From d9ee4168ed2a63e5599c9cb5547d970dc6bf8508 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 Sep 2017 10:55:51 -0400 Subject: [PATCH 1/6] Add .appveyor.yml This follows the example from https://www.appveyor.com/docs/lang/ruby/ except that it doesn't need `install` or `before_test` steps. --- .appveyor.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .appveyor.yml diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..fdaa0b8 --- /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 libexec/bats test From 5e752ee914e97d40c1593be225126ee5054e0814 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 Sep 2017 11:00:32 -0400 Subject: [PATCH 2/6] .appveyor.yml: Prefix test command with `time` This enables us to get an idea of the performance impact of a change. --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index fdaa0b8..bc83024 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,4 +12,4 @@ build: off test_script: - where bash - bash --version - - bash libexec/bats test + - bash -c 'time libexec/bats test' From bbac787615907ad06214ca2143464396d599ee5a Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 Sep 2017 11:14:48 -0400 Subject: [PATCH 3/6] .travis.yml: Prefix test command with `time` As with the update to .appveyor.yml in the previous commit, this enables us to get an idea of the performance impact of a change. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index db06d9d..76848d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: c -script: bin/bats --tap test +script: bash -c 'time bin/bats --tap test' notifications: email: on_success: never From d310b259110f51b14871072c252c829994b41432 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 Sep 2017 11:25:30 -0400 Subject: [PATCH 4/6] .travis.yml: Enable macOS builds Also sets the `language` to `bash`. --- .travis.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 76848d1..d7c534f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,11 @@ -language: c -script: bash -c 'time bin/bats --tap test' +language: bash +os: +- linux +- osx + +script: +- bash -c 'time bin/bats --tap test' + notifications: email: on_success: never From 918714dd4d7c4e537dc45f0292b16d559033bde9 Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Sat, 30 Sep 2017 14:51:45 -0400 Subject: [PATCH 5/6] test/bats: Add statements to debug Travis macOS The following build is demonstrating failures I can't reproduce on my own macOS system: https://travis-ci.org/bats-core/bats-core/jobs/281719290 --- test/bats.bats | 6 ++++++ 1 file changed, 6 insertions(+) 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)" ] } From 0f6dde530ee41c36dcb32341ca41af49fb00ad7d Mon Sep 17 00:00:00 2001 From: Mike Bland Date: Tue, 14 Feb 2017 23:06:59 -0500 Subject: [PATCH 6/6] exec-test: Work around Bash 3.2.57 ERR trap bug When running under Bash 3.2.57(1)-release on macOS, the following tests would fail because `BATS_ERROR_STACK_TRACE` would be empty, and hence no information about the actual error would get printed: - one failing test - failing test with significant status - failing test file outside of BATS_CWD This is because each of these cases use `FIXTURE_ROOT/failing.bats`, and the `ERR` trap would not fire for its `eval "( exit ${STATUS:-1} )"` line. Changing it to `exit ${STATUS:-1}` produced the same effect, and changing it to `return ${STATUS:-1}` would cause the output to point to the previous line, which executes `true`. However, the correct status would be reported to the `EXIT` trap, so now we call `bats_error_trap` at the very beginning of `bats_teardown_trap`. All the existing tests now pass under Bash 3.2.57(1)-release, Bash 4.2.25(1)-release (the version from the default Ubuntu 12.04.5/Precise image on Travis CI), and Bash 4.4.12(1)-release. --- libexec/bats-exec-test | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) 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="$?"