-
Notifications
You must be signed in to change notification settings - Fork 455
JUnit formatter reported last skipped test as failure if teardown_suite logs to fd3 #1181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
55993f0
6787d2f
03f7f7d
31a4593
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,8 +74,13 @@ print_test_case() { | |
| if [[ -n "$_system_out_log" ]]; then | ||
| printf " <system-out>%s</system-out>\n" "$(xml_escape "${_system_out_log}")" | ||
| fi | ||
| if [[ -n "$_buffer_log" || "$test_result_state" == not_ok ]]; then | ||
| if [[ "$test_result_state" == not_ok ]]; then # Failed tests need a <failure> element. | ||
| # If we have system err output, we use that as the failure text. | ||
| printf " <failure type=\"failure\">%s</failure>\n" "$(xml_escape "${_buffer_log}")" | ||
| else | ||
| if [[ -n "$_buffer_log" ]]; then | ||
| printf " <system-err>%s</system-err>\n" "$(xml_escape "${_buffer_log}")" | ||
| fi | ||
| fi | ||
| if [[ "$test_result_state" == skipped ]]; then | ||
| printf " <skipped>%s</skipped>\n" "$(xml_escape "$test_skip_message")" | ||
|
|
@@ -127,7 +132,7 @@ flush() { | |
| _buffer="" | ||
| } | ||
|
|
||
| log() { | ||
| log_system_err() { | ||
| if [[ -n "$_buffer_log" ]]; then | ||
| _buffer_log="${_buffer_log} | ||
| $1" | ||
|
|
@@ -157,7 +162,7 @@ $1" | |
| finish_file() { | ||
| if [[ "${class}" != JUNIT_FORMATTER_NO_FILE_ENCOUNTERED ]]; then | ||
| file_header | ||
| printf "%s\n" "${_buffer}" | ||
| printf "%s" "${_buffer}" | ||
| file_footer | ||
| class='' | ||
| name='' | ||
|
|
@@ -226,7 +231,7 @@ bats_tap_stream_comment() { # <comment text without leading '# '> <scope> | |
| ;; | ||
| *) | ||
| # everything else is considered error output | ||
| log "$1" | ||
| log_system_err "$1" | ||
| ;; | ||
| esac | ||
| } | ||
|
|
@@ -239,7 +244,8 @@ bats_tap_stream_suite() { # <file name> | |
| } | ||
|
|
||
| bats_tap_stream_unknown() { # <full line> | ||
| : | ||
| local line="$1" scope="$2" | ||
| log_system_out "$line" | ||
|
Comment on lines
+247
to
+248
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure of the wisdom of these two lines. |
||
| } | ||
|
|
||
| main() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #!/usr/bin/env bats | ||
| # shellcheck shell=bash | ||
|
|
||
| function setup_file() { | ||
| skip | ||
| } | ||
|
|
||
| function teardown_file() { | ||
| echo "normal teardown_file stdout" | ||
| echo "# Hash teardown_file stdout" | ||
| echo "normal teardown_file stderr" >&2 | ||
| echo "# Hash teardown_file stderr" >&2 | ||
| echo "normal teardown_file fd3" >&3 | ||
| echo "# Hash teardown_file fd3" >&3 | ||
| } | ||
|
|
||
| @test "skipped-and-junit-agrees" { | ||
| echo "unexpected stdout as this should be skipped" | ||
| echo "unexpected stderr as this should be skipped" >&2 | ||
| echo "unexpected fd3 as this should be skipped" >&3 | ||
| } | ||
|
|
||
| @test "skipped-but-junit-reports-failure" { | ||
| echo "unexpected stdout as this should be skipped" | ||
| echo "unexpected stderr as this should be skipped" >&2 | ||
| echo "unexpected fd3 as this should be skipped" >&3 | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # shellcheck shell=bash | ||
|
|
||
| function setup_suite() { | ||
| true | ||
| } | ||
|
|
||
| teardown_suite() { | ||
| echo "normal teardown_suite stdout" | ||
| echo "# Hash teardown_suite stdout" | ||
| echo "normal teardown_suite stderr" >&2 | ||
| echo "# Hash teardown_suite stderr" >&2 | ||
| echo "normal teardown_suite fd3" >&3 | ||
| echo "# Hash teardown_suite fd3" >&3 | ||
|
Comment on lines
+12
to
+13
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this PR, this output causes the last test in the suite to be falsely-flagged as a failure by the JUnit formatter. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,6 +149,15 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">" | |
| [[ "${lines[7]}" == '</testsuite>' ]] | ||
| } | ||
|
|
||
| @test "junit does not mark tests with FD 3 output in teardown_suite as failed (issue #1180)" { | ||
| bats_require_minimum_version 1.5.0 | ||
| local stderr='' # silence shellcheck | ||
| name=non-empty reentrant_run -0 --separate-stderr bats --formatter junit "$FIXTURE_ROOT/issue1180" | ||
| [ "${stderr}" == "" ] || { echo "stderr should be empty but was: ${stderr}" >&3; return 1; } | ||
| [[ "${output}" != *'<failure '* ]] | ||
| [[ "${output}" == *'teardown_suite fd3'* ]] | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the "tightest" of tests, but it seems to do the job. |
||
| } | ||
|
|
||
| @test "don't choke on setup_file errors" { | ||
| bats_require_minimum_version 1.5.0 | ||
| local stderr='' # silence shellcheck | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core of my thinking here: only "not_ok" tests should report a
<failure... element.Everything else should say it's ok while recording as much of the test's output as system-out / system-err as possible.