Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ The format is based on [Keep a Changelog][kac] and this project adheres to

* unset `output`, `stderr`, `lines`, `stderr_lines` at the start of `run` to avoid crosstalk
between successive invocations (#1105)
* junit: XML escape fully removes ANSI sequences, e.g. color codes, cursor movements (#1103)
* junit:
* XML escape fully removes ANSI sequences, e.g. color codes, cursor movements (#1103)
* fix retried tests being listed multiple times (#1150)
* remove deprecated windows runner (#1119)
* renamed `docker-compose.yml` to `compose.yaml` (#1128)

Expand Down
1 change: 1 addition & 0 deletions libexec/bats-core/bats-format-junit
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ flush_log() {
fi
_buffer_log=""
_system_out_log=""
test_result_state="" # Clean out result from last test. Retried tests will have multiple begin calls.
}

log_system_out() {
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/junit-formatter/issue_1149.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bats

# shellcheck disable=SC2034
BATS_TEST_RETRIES=1

@test "test fail" {
false
}

@test "test foobar" {
false
}
33 changes: 23 additions & 10 deletions test/junit-formatter.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"

@test "junit formatter with skipped test does not fail" {
reentrant_run bats --formatter junit "$FIXTURE_ROOT/skipped.bats"
echo "$output"

[[ $status -eq 0 ]]
[[ "${lines[0]}" == '<?xml version="1.0" encoding="UTF-8"?>' ]]

Expand Down Expand Up @@ -52,7 +52,6 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"
esac
reentrant_run bats --formatter junit "$TEST_FILE_PATH"

echo "$output"
[[ "${lines[2]}" == "<testsuite name=\"$ESCAPED_TEST_FILE_NAME\" tests=\"3\" failures=\"1\" errors=\"0\" skipped=\"1\" time=\""*"\" timestamp=\""*"\" hostname=\""*"\">" ]]
[[ "${lines[3]}" == " <testcase classname=\"$ESCAPED_TEST_FILE_NAME\" name=\"Successful test with escape characters: &quot;&#39;&lt;&gt;&amp; (0x1b)\" time=\""*"\" />" ]]
[[ "${lines[4]}" == " <testcase classname=\"$ESCAPED_TEST_FILE_NAME\" name=\"Failed test with escape characters: &quot;&#39;&lt;&gt;&amp; (0x1b)\" "* ]]
Expand All @@ -64,7 +63,6 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"

@test "junit formatter: test suites" {
reentrant_run bats --formatter junit "$FIXTURE_ROOT/suite/"
echo "$output"

[[ "${lines[0]}" == '<?xml version="1.0" encoding="UTF-8"?>' ]]
[[ "${lines[1]}" == *"<testsuites "* ]]
Expand All @@ -80,7 +78,6 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"
@test "junit formatter: test suites relative path" {
cd "$FIXTURE_ROOT"
reentrant_run bats --formatter junit "suite/"
echo "$output"

[[ "${lines[0]}" == '<?xml version="1.0" encoding="UTF-8"?>' ]]
[[ "${lines[1]}" == *"<testsuites "* ]]
Expand All @@ -95,28 +92,26 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"

@test "junit formatter: files with the same name are distinguishable" {
reentrant_run bats --formatter junit -r "$FIXTURE_ROOT/duplicate/"
echo "$output"


[[ "${lines[2]}" == *"<testsuite name=\"first/file1.bats\""* ]]
[[ "${lines[5]}" == *"<testsuite name=\"second/file1.bats\""* ]]
}

@test "junit formatter as report formatter creates report.xml" {
cd "$BATS_TEST_TMPDIR" # don't litter sources with output files
reentrant_run bats --report-formatter junit "$FIXTURE_ROOT/suite/"
echo "$output"
echo "$output" # duplicate for later comparison

[[ -e "report.xml" ]]
run cat "report.xml"
echo "$output"

[[ "${lines[2]}" == *"<testsuite name=\"file1.bats\" tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\""* ]]
[[ "${lines[5]}" == *"<testsuite name=\"file2.bats\" tests=\"1\" failures=\"0\" errors=\"0\" skipped=\"0\""* ]]
}

@test "junit does not mark tests with FD 3 output as failed (issue #360)" {
reentrant_run bats --formatter junit "$FIXTURE_ROOT/issue_360.bats"

echo "$output"

[[ "${lines[2]}" == '<testsuite name="issue_360.bats" '*'>' ]]
[[ "${lines[3]}" == ' <testcase classname="issue_360.bats" '*'>' ]]
# only the outputs on FD3 should be visible on a successful test
Expand Down Expand Up @@ -158,3 +153,21 @@ TESTSUITES_REGEX="<testsuites time=\"$FLOAT_REGEX\">"
reentrant_run -1 --separate-stderr bats --formatter junit "$FIXTURE_ROOT/../file_setup_teardown/setup_file_failed.bats"
[ "${stderr}" == "" ]
}

@test "junit outputs status of last completed test when a test is retried (issue #1149)" {
bats_require_minimum_version 1.8.0
reentrant_run bats --formatter junit "$FIXTURE_ROOT/issue_1149.bats"

[[ "${lines[2]}" == '<testsuite name="issue_1149.bats" '*'>' ]]
# The first failing (and retried) test has one entry, as expected
[[ "${lines[3]}" == ' <testcase classname="issue_1149.bats" name="test fail" '*'>' ]]
[[ "${lines[4]}" == " <failure type=\"failure\">(in test file $RELATIVE_FIXTURE_ROOT/issue_1149.bats, line 7)" ]]
[[ "${lines[5]}" == ' `false&#39; failed</failure>' ]]
[[ "${lines[6]}" == ' </testcase>' ]]
# Second failing test (also retried) should also only have one entry, and that includes the failure message
[[ "${lines[7]}" == ' <testcase classname="issue_1149.bats" name="test foobar" '*'>' ]]
[[ "${lines[8]}" == " <failure type=\"failure\">(in test file $RELATIVE_FIXTURE_ROOT/issue_1149.bats, line 11)" ]]
[[ "${lines[9]}" == ' `false&#39; failed</failure>' ]]
[[ "${lines[10]}" == ' </testcase>' ]]
[[ "${lines[11]}" == '</testsuite>' ]]
}