Skip to content

Commit f530a60

Browse files
committed
bats/helpers: Create script before setting PATH
The following test case from `tests/new.bats` was failing on Windows (using the MSYS2 Bash 4.3.46(2)-release from Git for Windows): ✗ new: error if setting permissions fails (from function `stub_program_in_path' in file lib/bats/helpers, line 320, in test file tests/new.bats, line 268) `stub_program_in_path 'chmod' 'printf "ARG: %s\n" "$@"' 'exit 1'' failed ARG: 700 ARG: /tmp/test rootdir/bin/chmod ARG: -R ARG: u+rwx ARG: /tmp/test rootdir Apparently on this platform, `chmod` wasn't already `hash`-ed, and using `stub_program_in_path` to stub out `chmod` was causing `create_bats_test_script` to look up `chmod` in `PATH` andinvoke the stub script itself. The fix: call `create_bats_test_script` before setting `PATH`. The existing `stub_program_in_path for testing external program` test case from `tests/bats-helpers.bats` now uses `chmod` for its example program instead of `git`, which reproduced the original failure and verifies its fix.
1 parent 5abb59b commit f530a60

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

lib/bats/helpers

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ stub_program_in_path() {
313313
in_process='true'
314314
shift
315315
fi
316+
create_bats_test_script "${BATS_TEST_BINDIR#$BATS_TEST_ROOTDIR/}/$1" "${@:2}"
316317

317318
if [[ ! "$PATH" =~ $bindir_pattern ]]; then
318319
export PATH="$BATS_TEST_BINDIR:$PATH"
319320
fi
320-
create_bats_test_script "${BATS_TEST_BINDIR#$BATS_TEST_ROOTDIR/}/$1" "${@:2}"
321321

322322
if [[ -n "$in_process" ]]; then
323323
hash "$1"

tests/bats-helpers.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ __check_dirs_exist() {
240240
local bats_bindir_pattern="^${BATS_TEST_BINDIR}:"
241241
fail_if matches "$bats_bindir_pattern" "$PATH"
242242

243-
stub_program_in_path 'git' 'echo "$@"'
243+
stub_program_in_path 'chmod' 'echo "$@"'
244244
assert_matches "$bats_bindir_pattern" "$PATH"
245245

246-
run git Hello, World!
247-
assert_success 'Hello, World!'
246+
run chmod ugo+rwx foo.txt
247+
assert_success 'ugo+rwx foo.txt'
248248
}
249249

250250
@test "$SUITE: {stub,restore}_program_in_path for testing in-process function" {

0 commit comments

Comments
 (0)