diff --git a/.travis.yml b/.travis.yml index e56169a..b10a418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,11 @@ language: bash +env: + - BATS_VERSION=v0.4.0 + - BATS_VERSION=v1.0.0 + - BATS_VERSION=v1.0.1 + - BATS_VERSION=v1.0.2 + - BATS_VERSION=v1.1.0 + - BATS_VERSION=master before_install: - ./script/install-bats.sh - git clone --depth 1 https://github.com/ztombol/bats-support ../bats-support diff --git a/script/install-bats.sh b/script/install-bats.sh index 4c3161a..f7f73a9 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,5 +2,15 @@ set -o errexit set -o xtrace -git clone --depth 1 https://github.com/sstephenson/bats -cd bats && ./install.sh "${HOME}/.local" && cd .. && rm -rf bats +BATS_VERSION="${BATS_VERSION:-master}" + +git clone \ + --branch "${BATS_VERSION}" \ + --depth 1 \ + https://github.com/bats-core/bats-core bats + +(cd bats + ./install.sh "${HOME}/.local" +) + +rm -rf bats diff --git a/test/51-temp-10-temp_make.bats b/test/51-temp-10-temp_make.bats index 30048c1..6feea03 100755 --- a/test/51-temp-10-temp_make.bats +++ b/test/51-temp-10-temp_make.bats @@ -43,10 +43,16 @@ fixtures 'temp' run bats "${TEST_FIXTURE_ROOT}/temp_make-main.bats" [ "$status" -eq 1 ] - [ "${#lines[@]}" -eq 3 ] - [ "${lines[0]}" == '-- ERROR: temp_make --' ] - [ "${lines[1]}" == "Must be called from \`setup', \`@test' or \`teardown'" ] - [ "${lines[2]}" == '--' ] + [ "${#lines[@]}" -ge 3 ] + + # Starting with `bats` commit 17e2cf35 "*: refactor to always use + # bats-exec-suite" (bats-core/bats-core@17e2cf35), an empty test is needed + # which emits an empty line as a side-effect, account for it. + declare -i i_line=$(( ${#lines[@]} - 3 )) + + [ "${lines[$(( i_line++ ))]}" == '-- ERROR: temp_make --' ] + [ "${lines[$(( i_line++ ))]}" == "Must be called from \`setup', \`@test' or \`teardown'" ] + [ "${lines[$(( i_line++ ))]}" == '--' ] } # Options diff --git a/test/51-temp-11-temp_del.bats b/test/51-temp-11-temp_del.bats index 7349508..ceb2991 100755 --- a/test/51-temp-11-temp_del.bats +++ b/test/51-temp-11-temp_del.bats @@ -97,10 +97,16 @@ fixtures 'temp' run bats "${TEST_FIXTURE_ROOT}/temp_del-main.bats" [ "$status" -eq 1 ] - [ "${#lines[@]}" -eq 3 ] - [ "${lines[0]}" == '-- ERROR: temp_del --' ] - [ "${lines[1]}" == "Must be called from \`teardown' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'" ] - [ "${lines[2]}" == '--' ] + [ "${#lines[@]}" -ge 3 ] + + # Starting with `bats` commit 17e2cf35 "*: refactor to always use + # bats-exec-suite" (bats-core/bats-core@17e2cf35), an empty test is needed + # which emits an empty line as a side-effect, account for it. + declare -i i_line=$(( ${#lines[@]} - 3 )) + + [ "${lines[$(( i_line++ ))]}" == '-- ERROR: temp_del --' ] + [ "${lines[$(( i_line++ ))]}" == "Must be called from \`teardown' when using \`BATSLIB_TEMP_PRESERVE_ON_FAILURE'" ] + [ "${lines[$(( i_line++ ))]}" == '--' ] } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup'" { diff --git a/test/fixtures/temp/temp_del-main.bats b/test/fixtures/temp/temp_del-main.bats index e2576d9..eaf5978 100644 --- a/test/fixtures/temp/temp_del-main.bats +++ b/test/fixtures/temp/temp_del-main.bats @@ -4,3 +4,6 @@ load 'test_helper' BATSLIB_TEMP_PRESERVE_ON_FAILURE=1 temp_del "$TEST_TEMP_DIR" + +@test "void" { +} diff --git a/test/fixtures/temp/temp_make-main.bats b/test/fixtures/temp/temp_make-main.bats index e0226a0..bd7d524 100644 --- a/test/fixtures/temp/temp_make-main.bats +++ b/test/fixtures/temp/temp_make-main.bats @@ -3,3 +3,6 @@ load 'test_helper' TEST_TEMP_DIR="$(temp_make)" + +@test "void" { +} diff --git a/test/test_helper.bash b/test/test_helper.bash index 3ae57b0..4116a2a 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -10,7 +10,12 @@ # none fixtures() { TEST_FIXTURE_ROOT="${BATS_TEST_DIRNAME}/fixtures/$1" - TEST_RELATIVE_FIXTURE_ROOT="$(bats_trim_filename "${TEST_FIXTURE_ROOT}")" + if bats_trim_filename "${TEST_FIXTURE_ROOT}" &>/dev/null + then + TEST_RELATIVE_FIXTURE_ROOT="$(bats_trim_filename "${TEST_FIXTURE_ROOT}")" + else + bats_trim_filename "${TEST_FIXTURE_ROOT}" TEST_RELATIVE_FIXTURE_ROOT + fi } setup() {