Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to current bats-core #11

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 12 additions & 2 deletions script/install-bats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 10 additions & 4 deletions test/51-temp-10-temp_make.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions test/51-temp-11-temp_del.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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() <path>: \`BATSLIB_TEMP_PRESERVE_ON_FAILURE' does not work when called from \`setup'" {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/temp/temp_del-main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ load 'test_helper'

BATSLIB_TEMP_PRESERVE_ON_FAILURE=1
temp_del "$TEST_TEMP_DIR"

@test "void" {
}
3 changes: 3 additions & 0 deletions test/fixtures/temp/temp_make-main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
load 'test_helper'

TEST_TEMP_DIR="$(temp_make)"

@test "void" {
}
7 changes: 6 additions & 1 deletion test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down