#!/usr/bin/env bats load test_helper fixtures junit-formatter FLOAT_REGEX='[0-9]+(\.[0-9]+)?' TIMESTAMP_REGEX='[0-9]+-[0-1][0-9]-[0-3][0-9]T[0-2][0-9]:[0-5][0-9]:[0-5][0-9]' TESTSUITES_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]}" == '' ]] [[ "${lines[1]}" =~ $TESTSUITES_REGEX ]] TESTSUITE_REGEX="" echo "TESTSUITE_REGEX='$TESTSUITE_REGEX'" [[ "${lines[2]}" =~ $TESTSUITE_REGEX ]] TESTCASE_REGEX="" [[ "${lines[3]}" =~ $TESTCASE_REGEX ]] [[ "${lines[4]}" == *""* ]] [[ "${lines[5]}" == *""* ]] TESTCASE_REGEX="" [[ "${lines[6]}" =~ $TESTCASE_REGEX ]] [[ "${lines[7]}" == *"a reason"* ]] [[ "${lines[8]}" == *""* ]] [[ "${lines[9]}" == *""* ]] [[ "${lines[10]}" == *""* ]] } @test "junit formatter: escapes xml special chars" { case $OSTYPE in linux* | darwin) # their CI can handle special chars on filename TEST_FILE_NAME="xml-escape-\"<>'&.bats" ESCAPED_TEST_FILE_NAME="xml-escape-"<>'&.bats" TEST_FILE_PATH="$BATS_TEST_TMPDIR/$TEST_FILE_NAME" cp "$FIXTURE_ROOT/xml-escape.bats" "$TEST_FILE_PATH" ;; *) # use the filename without special chars TEST_FILE_NAME="xml-escape.bats" ESCAPED_TEST_FILE_NAME="$TEST_FILE_NAME" TEST_FILE_PATH="$FIXTURE_ROOT/$TEST_FILE_NAME" ;; esac reentrant_run bats --formatter junit "$TEST_FILE_PATH" echo "$output" [[ "${lines[2]}" == "" ]] [[ "${lines[3]}" == " " ]] [[ "${lines[4]}" == " (in test file '*"$ESCAPED_TEST_FILE_NAME, line 6)" ]] [[ "${lines[6]}" == ' `echo "<>'&" && false' failed'* ]] [[ "${lines[9]}" == " " ]] [[ "${lines[10]}" == " "'<>&" ]] } @test "junit formatter: test suites" { reentrant_run bats --formatter junit "$FIXTURE_ROOT/suite/" echo "$output" [[ "${lines[0]}" == '' ]] [[ "${lines[1]}" == *""* ]] [[ "${lines[5]}" == *""* ]] [[ "${lines[8]}" == *""* ]] } @test "junit formatter: test suites relative path" { cd "$FIXTURE_ROOT" reentrant_run bats --formatter junit "suite/" echo "$output" [[ "${lines[0]}" == '' ]] [[ "${lines[1]}" == *""* ]] [[ "${lines[5]}" == *""* ]] [[ "${lines[8]}" == *""* ]] } @test "junit formatter: files with the same name are distinguishable" { reentrant_run bats --formatter junit -r "$FIXTURE_ROOT/duplicate/" echo "$output" [[ "${lines[2]}" == *"' ]] [[ "${lines[3]}" == ' ' ]] # only the outputs on FD3 should be visible on a successful test [[ "${lines[4]}" == ' setup FD3' ]] [[ "${lines[5]}" == 'hello Bilbo' ]] [[ "${lines[6]}" == 'teardown FD3' ]] [[ "${lines[7]}" == ' ' ]] [[ "${lines[8]}" == ' ' ]] # a failed test should show FD3 output first ... [[ "${lines[9]}" == ' setup FD3' ]] [[ "${lines[10]}" == 'hello Bilbo' ]] [[ "${lines[11]}" == 'teardown FD3' ]] [[ "${lines[12]}" == ' (in test file '*'test/fixtures/junit-formatter/issue_360.bats, line 21)' ]] [[ "${lines[13]}" == ' `false' failed' ]] # ... and then the stdout output [[ "${lines[14]}" == '# setup stdout' ]] [[ "${lines[15]}" == '# hello stdout' ]] [[ "${lines[16]}" == '# teardown stdout' ]] [[ "${lines[17]}" == ' ' ]] [[ "${lines[18]}" == '' ]] } @test "junit does not mark tests with FD 3 output in teardown_file as failed (issue #531)" { bats_require_minimum_version 1.5.0 reentrant_run -0 bats --formatter junit "$FIXTURE_ROOT/issue_531.bats" [[ "${lines[2]}" == '' ]] [[ "${lines[3]}" == ' ' ]] # only the outputs on FD3 should be visible on a successful test [[ "${lines[4]}" == ' test fd3' ]] [[ "${lines[5]}" == 'teardown_file fd3' ]] [[ "${lines[6]}" == ' ' ]] [[ "${lines[7]}" == '' ]] } @test "don't choke on setup_file errors" { bats_require_minimum_version 1.5.0 local stderr='' # silence shellcheck reentrant_run -1 --separate-stderr bats --formatter junit "$FIXTURE_ROOT/../file_setup_teardown/setup_file_failed.bats" [ "${stderr}" == "" ] }