From 4a020a89540354dd97666138af2f95f7b8e6a980 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 14:52:27 +0200 Subject: [PATCH 01/12] script/install: Reformat for readability Add line breaks and split the long installation statement. --- script/install-bats.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/script/install-bats.sh b/script/install-bats.sh index 4c3161a..0c11c93 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,5 +2,12 @@ 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 +git clone \ + --depth 1 \ + https://github.com/sstephenson/bats + +(cd bats + ./install.sh "${HOME}/.local" +) + +rm -rf bats From b3fcca297d43e25f9244ff5e3c55be843fe94eee Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 14:54:52 +0200 Subject: [PATCH 02/12] script/install: Pin `bats` to a version Use a specific `bats` version instead of the moving `master` branch. Set the version to v0.4.0 which is the latest release. --- script/install-bats.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/script/install-bats.sh b/script/install-bats.sh index 0c11c93..3fe3a37 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,7 +2,10 @@ set -o errexit set -o xtrace +BATS_VERSION="${1:-0.4.0}" + git clone \ + --branch "v${BATS_VERSION}" \ --depth 1 \ https://github.com/sstephenson/bats From c6f5cecb39ac03fa3bc11734534dcf0a415e19ad Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 12:32:40 +0200 Subject: [PATCH 03/12] script/install: Migrate to `bats-core` Since the original `bats` isn't maintained anymore, switch to its successor `bats-core`. --- script/install-bats.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/install-bats.sh b/script/install-bats.sh index 3fe3a37..42869ff 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -7,7 +7,7 @@ BATS_VERSION="${1:-0.4.0}" git clone \ --branch "v${BATS_VERSION}" \ --depth 1 \ - https://github.com/sstephenson/bats + https://github.com/bats-core/bats-core bats (cd bats ./install.sh "${HOME}/.local" From 3d1a466ff866165156e456620d34b9b75d1b3d70 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 20:24:10 +0200 Subject: [PATCH 04/12] script/install: Enable cloning a `bats` branch Cloning was done using the `v*` pattern which works for tags only. In future, we will need to clone a branch, too. Extend the mechanism to branches by removing the leading `v`. --- script/install-bats.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/install-bats.sh b/script/install-bats.sh index 42869ff..9aa3666 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,10 +2,10 @@ set -o errexit set -o xtrace -BATS_VERSION="${1:-0.4.0}" +BATS_VERSION="${BATS_VERSION:-v0.4.0}" git clone \ - --branch "v${BATS_VERSION}" \ + --branch "${BATS_VERSION}" \ --depth 1 \ https://github.com/bats-core/bats-core bats From 77f8c6349171ecdc2ae0173d35daf3a31d5a3b18 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sun, 5 Apr 2020 01:12:00 +0200 Subject: [PATCH 05/12] travis: Add `bats` v0.4.0 to the build matrix In an upcoming commit, we will test with different `bats` versions in parallel, prepare for this by declaring a separate `v0.4.0` build environment. --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index e56169a..eb3c799 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,6 @@ language: bash +env: + - BATS_VERSION=v0.4.0 before_install: - ./script/install-bats.sh - git clone --depth 1 https://github.com/ztombol/bats-support ../bats-support From 90d587e466824b52449405d32d670488a172ca11 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 15:24:59 +0200 Subject: [PATCH 06/12] script/install: Update `bats-core` to v1.0.0 To make use of the newest `bats-core` features, update the version. Since a couple hurdles will occur, do it step-wise. With v1.0.0, all tests fail, so expect them to fail. This will be fixed in an upcoming commit. --- .travis.yml | 3 ++- script/install-bats.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index eb3c799..4659e34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: bash env: - BATS_VERSION=v0.4.0 + - BATS_VERSION=v1.0.0 before_install: - ./script/install-bats.sh - git clone --depth 1 https://github.com/ztombol/bats-support ../bats-support before_script: - export PATH="${HOME}/.local/bin:${PATH}" script: - - bats test + - if [ "${BATS_VERSION}" = "v1.0.0" ]; then ! bats test; else bats test; fi diff --git a/script/install-bats.sh b/script/install-bats.sh index 9aa3666..ed47deb 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,7 +2,7 @@ set -o errexit set -o xtrace -BATS_VERSION="${BATS_VERSION:-v0.4.0}" +BATS_VERSION="${BATS_VERSION:-v1.0.0}" git clone \ --branch "${BATS_VERSION}" \ From c2f95be38144bbd102c2cff4a08ddc04b30f7efa Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 00:53:21 +0200 Subject: [PATCH 07/12] test/test_helper.bash: Update for `bats` v1.0.0 In the `fixtures()` function, a `bats`-internal function is used, namely `bats_trim_filename()`. With the commit eaa151fb "exec-test: Use printf -v in bats_trim_filename" (bats-core/bats-core@eaa151f) introduced in `bats` v1.0.0, its interface was changed to take a variable name instead of printing to `stdout`, breaking the test code. Adapt to the incompatible change, retaining compatibility with v0.* versions. Expect all tests to pass now. --- .travis.yml | 2 +- test/test_helper.bash | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4659e34..1c153d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,4 +8,4 @@ before_install: before_script: - export PATH="${HOME}/.local/bin:${PATH}" script: - - if [ "${BATS_VERSION}" = "v1.0.0" ]; then ! bats test; else bats test; fi + - bats test 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() { From c0fcc1e459f2997408273038b7c7b751a958f65c Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 15:24:59 +0200 Subject: [PATCH 08/12] script/install: Update `bats-core` to v1.0.1 To make use of the newest `bats-core` features, update the version. Since a couple hurdles will occur, do it step-wise. --- .travis.yml | 1 + script/install-bats.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1c153d7..c8bdd03 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: bash env: - BATS_VERSION=v0.4.0 - BATS_VERSION=v1.0.0 + - BATS_VERSION=v1.0.1 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 ed47deb..3ca81c3 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,7 +2,7 @@ set -o errexit set -o xtrace -BATS_VERSION="${BATS_VERSION:-v1.0.0}" +BATS_VERSION="${BATS_VERSION:-v1.0.1}" git clone \ --branch "${BATS_VERSION}" \ From f98be58a37d031b9dec0be3cecfbfa733c1b560d Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 15:24:59 +0200 Subject: [PATCH 09/12] script/install: Update `bats-core` to v1.0.2 To make use of the newest `bats-core` features, update the version. Since a couple hurdles will occur, do it step-wise. --- .travis.yml | 1 + script/install-bats.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c8bdd03..c4bb063 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ env: - BATS_VERSION=v0.4.0 - BATS_VERSION=v1.0.0 - BATS_VERSION=v1.0.1 + - BATS_VERSION=v1.0.2 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 3ca81c3..fbd74b1 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,7 +2,7 @@ set -o errexit set -o xtrace -BATS_VERSION="${BATS_VERSION:-v1.0.1}" +BATS_VERSION="${BATS_VERSION:-v1.0.2}" git clone \ --branch "${BATS_VERSION}" \ From b39ae92d4c065da7d93493d8bbcfcbc838aa7e76 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 15:24:59 +0200 Subject: [PATCH 10/12] script/install: Update `bats-core` to v1.1.0 To make use of the newest `bats-core` features, update the version. Since a couple hurdles will occur, do it step-wise. --- .travis.yml | 1 + script/install-bats.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index c4bb063..e2f5412 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ env: - BATS_VERSION=v1.0.0 - BATS_VERSION=v1.0.1 - BATS_VERSION=v1.0.2 + - BATS_VERSION=v1.1.0 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 fbd74b1..3d01e2d 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,7 +2,7 @@ set -o errexit set -o xtrace -BATS_VERSION="${BATS_VERSION:-v1.0.2}" +BATS_VERSION="${BATS_VERSION:-v1.1.0}" git clone \ --branch "${BATS_VERSION}" \ From 8341e86debe55906820b1ce82b7572c59032018f Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sat, 4 Apr 2020 20:29:08 +0200 Subject: [PATCH 11/12] travis: Update `bats-core` to master To make use of the newest `bats-core` features, update the version, ultimately. Two tests fail, so expect them to. This will be fixed in an upcoming commit. --- .travis.yml | 1 + script/install-bats.sh | 2 +- test/51-temp-10-temp_make.bats | 5 +++++ test/51-temp-11-temp_del.bats | 5 +++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e2f5412..b10a418 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ env: - 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 3d01e2d..f7f73a9 100755 --- a/script/install-bats.sh +++ b/script/install-bats.sh @@ -2,7 +2,7 @@ set -o errexit set -o xtrace -BATS_VERSION="${BATS_VERSION:-v1.1.0}" +BATS_VERSION="${BATS_VERSION:-master}" git clone \ --branch "${BATS_VERSION}" \ diff --git a/test/51-temp-10-temp_make.bats b/test/51-temp-10-temp_make.bats index 30048c1..1613777 100755 --- a/test/51-temp-10-temp_make.bats +++ b/test/51-temp-10-temp_make.bats @@ -42,11 +42,16 @@ fixtures 'temp' @test "temp_make() : does not work when called from \`main'" { run bats "${TEST_FIXTURE_ROOT}/temp_make-main.bats" + if [[ "${BATS_VERSION}" =~ ^1\.2\.0 ]] + then + [ "$status" -ne 1 ] + else [ "$status" -eq 1 ] [ "${#lines[@]}" -eq 3 ] [ "${lines[0]}" == '-- ERROR: temp_make --' ] [ "${lines[1]}" == "Must be called from \`setup', \`@test' or \`teardown'" ] [ "${lines[2]}" == '--' ] + fi } # Options diff --git a/test/51-temp-11-temp_del.bats b/test/51-temp-11-temp_del.bats index 7349508..c12982d 100755 --- a/test/51-temp-11-temp_del.bats +++ b/test/51-temp-11-temp_del.bats @@ -96,11 +96,16 @@ fixtures 'temp' export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-main.bats" + if [[ "${BATS_VERSION}" =~ ^1\.2\.0 ]] + then + [ "$status" -ne 1 ] + else [ "$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]}" == '--' ] + fi } @test "temp_del() : \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup'" { From 5d536f00f273c019f61850165f778c938607e4a8 Mon Sep 17 00:00:00 2001 From: Alex Thiessen Date: Sun, 5 Apr 2020 03:45:11 +0200 Subject: [PATCH 12/12] test: Update for `bats` master Since commit 17e2cf35 "*: refactor to always use bats-exec-suite" (bats-core/bats-core@17e2cf35), `*.bats` files without a test aren't run at all. This leads to two checks not working properly. Add _void_ tests to the affected files and adapt the tests to take into account the extra line that is emitted. --- test/51-temp-10-temp_make.bats | 19 ++++++++++--------- test/51-temp-11-temp_del.bats | 19 ++++++++++--------- test/fixtures/temp/temp_del-main.bats | 3 +++ test/fixtures/temp/temp_make-main.bats | 3 +++ 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/test/51-temp-10-temp_make.bats b/test/51-temp-10-temp_make.bats index 1613777..6feea03 100755 --- a/test/51-temp-10-temp_make.bats +++ b/test/51-temp-10-temp_make.bats @@ -42,16 +42,17 @@ fixtures 'temp' @test "temp_make() : does not work when called from \`main'" { run bats "${TEST_FIXTURE_ROOT}/temp_make-main.bats" - if [[ "${BATS_VERSION}" =~ ^1\.2\.0 ]] - then - [ "$status" -ne 1 ] - else [ "$status" -eq 1 ] - [ "${#lines[@]}" -eq 3 ] - [ "${lines[0]}" == '-- ERROR: temp_make --' ] - [ "${lines[1]}" == "Must be called from \`setup', \`@test' or \`teardown'" ] - [ "${lines[2]}" == '--' ] - fi + [ "${#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 c12982d..ceb2991 100755 --- a/test/51-temp-11-temp_del.bats +++ b/test/51-temp-11-temp_del.bats @@ -96,16 +96,17 @@ fixtures 'temp' export TEST_TEMP_DIR run bats "${TEST_FIXTURE_ROOT}/temp_del-main.bats" - if [[ "${BATS_VERSION}" =~ ^1\.2\.0 ]] - then - [ "$status" -ne 1 ] - else [ "$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]}" == '--' ] - fi + [ "${#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" { +}