Skip to content

Commit

Permalink
Add quotation marks around values in tmt-report-result output
Browse files Browse the repository at this point in the history
  • Loading branch information
seberm committed Sep 22, 2024
1 parent c5d7fb2 commit 3fcb607
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
26 changes: 26 additions & 0 deletions tests/execute/result/special.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
. /usr/share/beakerlib/beakerlib.sh || exit 1

rlJournalStart
rlPhaseStartSetup
rlRun "run=\$(mktemp -d)" 0 "Create run directory"
rlRun "pushd special"
rlPhaseEnd

rlPhaseStartTest "Check characters are correctly escaped in tmt-report-result output"
rlRun -s "tmt run -v -i $run" 0

RESULT_FILE="$run/special-chars/execute/data/guest/default-0/special-characters-in-the-name-1/data/tmt-report-results.yaml"
rlRun "yq -ye '.' $RESULT_FILE" 0 "Check the YAML is valid"

rlAssertGrep "name: \"/special: characters: \*\$\@|&>< in: the: name\"" "$RESULT_FILE"
rlAssertGrep "result: \"pass\"" "$RESULT_FILE"
rlAssertGrep "end-time: \".*\"" "$RESULT_FILE"
rlAssertGrep "data-path: \"/.*\"" "$RESULT_FILE"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "popd"
rlRun "rm -r ${run}" 0 "Remove run directory"
rlPhaseEnd
rlJournalEnd
1 change: 1 addition & 0 deletions tests/execute/result/special/.fmf/version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1
9 changes: 9 additions & 0 deletions tests/execute/result/special/special-chars.fmf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
execute:
how: tmt
discover:
how: shell
tests:
- name: 'special: characters: *$@|&>< in: the: name'
test: "tmt-report-result 'special: characters: *$@|&>< in: the: name' PASS"
provision:
how: container
8 changes: 4 additions & 4 deletions tmt/steps/execute/scripts/tmt-report-result
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ die() { echo "$*" >&2; exit 2; } # complain to STDERR and exit with error
needs_arg() { if [ -z "$OPTARG" ]; then die "No arg for --$OPT option"; fi; }

write_report_file () {
echo " - name: ${TESTNAME}" >> "$REPORT_RESULT_OUTPUTFILE"
echo " result: ${TESTRESULT}" >> "$REPORT_RESULT_OUTPUTFILE"
echo " - name: \"${TESTNAME}\"" >> "$REPORT_RESULT_OUTPUTFILE"
echo " result: \"${TESTRESULT}\"" >> "$REPORT_RESULT_OUTPUTFILE"
if [ -n "${outputFile}" ]; then
echo " log:" >> "$REPORT_RESULT_OUTPUTFILE"
echo " - ${outputFile}" >> "$REPORT_RESULT_OUTPUTFILE"
echo " - \"${outputFile}\"" >> "$REPORT_RESULT_OUTPUTFILE"
fi
echo " end-time: \"$(date --utc +%FT%T.%6N%:z)\"" >> "$REPORT_RESULT_OUTPUTFILE"
echo " data-path: ${TMT_TEST_DATA/$TMT_TEST_EXE}" >> "$REPORT_RESULT_OUTPUTFILE"
echo " data-path: \"${TMT_TEST_DATA/$TMT_TEST_EXE}\"" >> "$REPORT_RESULT_OUTPUTFILE"
}

copy_outputfile_to_data_dir () {
Expand Down

0 comments on commit 3fcb607

Please sign in to comment.