diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..bc83024 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,15 @@ +version: 'v0.4.0.{build}' + +build: off + +# This presumes that Git bash is installed at `C:\Program Files\Git` and the +# bash we're using is `C:\Program Files\Git\bin\bash.exe`. +# +# If instead it finds the Windows Subsystem for Linux bash at +# `C:\Windows\System32\bash.exe`, it will fail with an error like: +# /mnt/c/.../bats-core/test/test_helper.bash: line 1: +# syntax error near unexpected token `$'{\r'' +test_script: + - where bash + - bash --version + - bash -c 'time libexec/bats test' diff --git a/.travis.yml b/.travis.yml index db06d9d..d7c534f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,11 @@ -language: c -script: bin/bats --tap test +language: bash +os: +- linux +- osx + +script: +- bash -c 'time bin/bats --tap test' + notifications: email: on_success: never diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test index 8f3bd51..bdce3c8 100755 --- a/libexec/bats-exec-test +++ b/libexec/bats-exec-test @@ -218,13 +218,22 @@ bats_debug_trap() { fi } +# When running under Bash 3.2.57(1)-release on macOS, the `ERR` trap may not +# always fire, but the `EXIT` trap will. For this reason we call it at the very +# beginning of `bats_teardown_trap` (the `DEBUG` trap for the call will move +# `BATS_CURRENT_STACK_TRACE` to `BATS_PREVIOUS_STACK_TRACE`) and check the value +# of `$?` before taking other actions. bats_error_trap() { - BATS_ERROR_STATUS="$?" - BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" ) - trap - debug + local status="$?" + if [[ "$status" -ne '0' ]]; then + BATS_ERROR_STATUS="$status" + BATS_ERROR_STACK_TRACE=( "${BATS_PREVIOUS_STACK_TRACE[@]}" ) + trap - debug + fi } bats_teardown_trap() { + bats_error_trap trap "bats_exit_trap" exit local status=0 teardown >>"$BATS_OUT" 2>&1 || status="$?" diff --git a/test/bats.bats b/test/bats.bats index f1aff29..9fca64a 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -67,6 +67,8 @@ fixtures bats @test "one failing test" { run bats "$FIXTURE_ROOT/failing.bats" [ $status -eq 1 ] + printf 'lines:\n' >&2 + printf '%s\n' "${lines[@]}" >&2 [ "${lines[0]}" = '1..1' ] [ "${lines[1]}" = 'not ok 1 a failing test' ] [ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ] @@ -86,6 +88,8 @@ fixtures bats @test "failing test with significant status" { STATUS=2 run bats "$FIXTURE_ROOT/failing.bats" [ $status -eq 1 ] + printf 'lines:\n' >&2 + printf '%s\n' "${lines[@]}" >&2 [ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ] } @@ -153,6 +157,8 @@ fixtures bats cd "$TMP" run bats "$FIXTURE_ROOT/failing.bats" [ $status -eq 1 ] + printf 'lines:\n' >&2 + printf '%s\n' "${lines[@]}" >&2 [ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ] }