Skip to content

Commit f65af8c

Browse files
committed
Fix breakage from Bats v1.0.0, bump to Bats v1.0.1
https://github.com/bats-core/bats-core/releases/tag/v1.0.0, while honoring the same interface as v0.4.0, introduced a few changes that required some cleanup of our Bats utilities: - bin/bats is no longer a symlink to libexec/bats, and the latter can no longer be invoked directly; hence _GO_BATS_PATH is now set to bin/bats. - TAP output for skipped tests changed in bats-core/bats-core#19. - run_bats_test_suite_in_isolation depended upon _GO_ROOTDIR and _GO_BATS_PATH, which led to bats not being able to find its libexec scripts. The bats path is now computed using `command -v bats`, which makes the library itself more portable. - Some assertion-test-helpers output didn't end with a newline. This prevented the `while` loop used to replace `sed` in bats-core/bats-core#88 from reading the final line of output from the test. While this was fixed in bats-core/bats-core#99, updating the code to always emit newlines was still the right thing to do. There was a bug in Bats v1.0.0 in setting `BATS_CWD` that broke the "assertion-test-helpers: failing assertion must disable shell options" test case. Specifically, stack trace paths that should've looked like: tests/assertion-test-helpers.bash instead looked like: go-script-bash/tests/assertion-test-helpers.bash This was fixed by bats-core/bats-core#98.
1 parent c583616 commit f65af8c

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

Diff for: lib/bats-main

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export _GO_BATS_COVERAGE_DIR="${_GO_BATS_COVERAGE_DIR:-$_GO_TEST_DIR/coverage}"
5050
export _GO_BATS_DIR="${_GO_BATS_DIR:-$_GO_TEST_DIR/bats}"
5151

5252
# Path to the main Bats executable
53-
export _GO_BATS_PATH="$_GO_BATS_DIR/libexec/bats"
53+
export _GO_BATS_PATH="$_GO_BATS_DIR/bin/bats"
5454

5555
# Version of Bats to fetch if `_GO_BATS_DIR` is missing
56-
export _GO_BATS_VERSION="${_GO_BATS_VERSION:-optimized-20170317}"
56+
export _GO_BATS_VERSION="${_GO_BATS_VERSION:-v1.0.1}"
5757

5858
# URL of the Bats git repository to clone to `_GO_BATS_DIR`
59-
export _GO_BATS_URL="${_GO_BATS_URL:-https://github.com/mbland/bats.git}"
59+
export _GO_BATS_URL="${_GO_BATS_URL:-https://github.com/bats-core/bats-core.git}"
6060

6161
# Set this to nonempty if you wish to collect coverage using kcov by default
6262
export _GO_COLLECT_BATS_COVERAGE="$_GO_COLLECT_BATS_COVERAGE"

Diff for: lib/bats/assertion-test-helpers

+4-3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ __expect_assertion_success() {
187187
"# \`failing_assertion' failed")
188188

189189
if ! __check_expected_output "$output" "${expected_output[@]}"; then
190-
printf "$ASSERTION_TEST_SCRIPT_FAILURE_MESSAGE" "${assertion%% *}" >&2
190+
printf "$ASSERTION_TEST_SCRIPT_FAILURE_MESSAGE\n" "${assertion%% *}" >&2
191191
return '1'
192192
fi
193193
}
@@ -230,7 +230,7 @@ __expect_assertion_failure() {
230230
"${@/#/# }")
231231

232232
if ! __check_expected_output "$output" "${expected_output[@]}"; then
233-
printf "$ASSERTION_TEST_SCRIPT_FAILURE_MESSAGE" "${assertion%% *}" >&2
233+
printf "$ASSERTION_TEST_SCRIPT_FAILURE_MESSAGE\n" "${assertion%% *}" >&2
234234
return '1'
235235
fi
236236
}
@@ -271,7 +271,8 @@ __run_command_and_assertion_in_subshell() {
271271
__assertion_output="${__assertion_output%$'\n'}"
272272

273273
if [[ "$__assertion_output" =~ write\ error:\ Bad\ file\ descriptor$ ]]; then
274-
printf "'%s' tried to write to standard output instead of standard error" \
274+
printf \
275+
"'%s' tried to write to standard output instead of standard error\n" \
275276
"${assertion%% *}" >&2
276277
return 1
277278
elif [[ -z "$__assertion_status" ]]; then

Diff for: lib/bats/helpers

+2-1
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ run_bats_test_suite() {
508508
# Arguments:
509509
# $@: Passed directly through to `run_bats_test_suite`
510510
run_bats_test_suite_in_isolation() {
511-
create_forwarding_script --path "$_GO_ROOTDIR/${_GO_BATS_PATH%/*}" 'bash'
511+
local bats_bin="$(command -v bats)"
512+
create_forwarding_script --path "${bats_bin%/*}" 'bash'
512513
create_forwarding_script --path '' 'rm'
513514
run_bats_test_suite "$@"
514515
restore_programs_in_path 'bash' 'rm'

Diff for: tests/bats-background-process.bats

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ kill_background_test_script() {
6363
assert_success
6464
fail_if output_matches 'Did not skip'
6565

66-
local skip_msg='ok 1 # skip (pkill, sleep, tail not installed on the system)'
6766
local test_case_name='skip_if_missing_background_utilities'
68-
assert_lines_equal '1..1' "$skip_msg $test_case_name"
67+
local skip_msg='skip pkill, sleep, tail not installed on the system'
68+
assert_lines_equal '1..1' "ok 1 $test_case_name # $skip_msg"
6969
}
7070

7171
@test "$SUITE: run{,_test_script}_in_background launches background process" {

Diff for: tests/bats-helpers.bats

+8-8
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ __check_dirs_exist() {
167167
run "$BATS_TEST_ROOTDIR/test.bats"
168168
assert_success
169169
assert_lines_equal '1..1' \
170-
'ok 1 # skip (foo, bar, baz not installed on the system) skip if missing'
170+
'ok 1 skip if missing # skip foo, bar, baz not installed on the system'
171171
}
172172

173173
@test "$SUITE: skip_if_none_present_on_system" {
@@ -193,9 +193,9 @@ __check_dirs_exist() {
193193
'None of foo, bar, or baz are installed on the system')
194194
assert_lines_equal '1..4' \
195195
'ok 1 should not skip if at least one present' \
196-
"ok 2 # skip (${expected_messages[0]}) single program missing" \
197-
"ok 3 # skip (${expected_messages[1]}) two programs missing" \
198-
"ok 4 # skip (${expected_messages[2]}) three programs missing"
196+
"ok 2 single program missing # skip ${expected_messages[0]}" \
197+
"ok 3 two programs missing # skip ${expected_messages[1]}" \
198+
"ok 4 three programs missing # skip ${expected_messages[2]}"
199199
}
200200

201201
@test "$SUITE: test_join fails if result variable name is invalid" {
@@ -249,9 +249,9 @@ __check_dirs_exist() {
249249
TEST_FILTER='b[a-z]r' run bats "$test_file"
250250
assert_success
251251
assert_lines_equal '1..3' \
252-
'ok 1 # skip foo' \
252+
'ok 1 foo # skip' \
253253
'ok 2 bar' \
254-
'ok 3 # skip baz'
254+
'ok 3 baz # skip'
255255
}
256256

257257
@test "$SUITE: split_bats_output_into_lines" {
@@ -473,7 +473,7 @@ __check_dirs_exist() {
473473
' skip "just because"' \
474474
' [[ $((2 + 2)) -eq 5 ]] || return 1' \
475475
'}'
476-
assert_success '1..1' 'ok 1 # skip (just because) should skip'
476+
assert_success '1..1' 'ok 1 should skip # skip just because'
477477
}
478478

479479
@test "$SUITE: run_bats_test_suite runs a test suite with failures" {
@@ -494,7 +494,7 @@ __check_dirs_exist() {
494494
' skip_if_system_missing cp rm mkdir' \
495495
'}'
496496
assert_success '1..1' \
497-
'ok 1 # skip (cp, mkdir not installed on the system) should skip'
497+
'ok 1 should skip # skip cp, mkdir not installed on the system'
498498
}
499499

500500
@test "$SUITE: run_bats_test_suite_in_isolation can access forwarding scripts" {

0 commit comments

Comments
 (0)