Skip to content

Commit 65484ad

Browse files
committed
tests/complete: Extract add_trailing_slashes
Part of #156. Very minor O(0.05s) benefit, but every little bit counts, especially on Windows. At this point, the timing for `./go test` under Bash 3.2.57(1)-release on my MacBook Pro with a 2.9GHz Intel Core i5 CPU and 8GB 1867MHz DDR3 RAM went from the following for the merge commit for #161: 784 tests, 0 failures, 2 skipped real 4m16.466s user 2m1.907s sys 2m2.015s to: real 3m2.408s user 1m31.395s sys 1m21.114s
1 parent 7e2db2b commit 65484ad

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

tests/complete/compgen.bats

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,23 @@ teardown() {
5858
assert_success "${expected[@]/%//}"
5959
}
6060

61-
@test "$SUITE: adds trailing slashes when called with -f" {
62-
mkdir -p "${TEST_GO_ROOTDIR}"/{foo,bar,baz}
63-
run "$TEST_GO_SCRIPT" -f -- ''
64-
65-
# Remember that `compgen` won't add trailing slashes by itself.
66-
local expected=($(cd "$TEST_GO_ROOTDIR"; compgen -f -- ''))
61+
add_trailing_slashes() {
6762
local i
6863
for ((i=0; i != "${#expected[@]}"; ++i)); do
6964
if [[ -d "$TEST_GO_ROOTDIR/${expected[$i]}" ]]; then
7065
expected[$i]+='/'
7166
fi
7267
done
68+
}
69+
70+
@test "$SUITE: adds trailing slashes when called with -f" {
71+
mkdir -p "${TEST_GO_ROOTDIR}"/{foo,bar,baz}
72+
run "$TEST_GO_SCRIPT" -f -- ''
73+
74+
set "$DISABLE_BATS_SHELL_OPTIONS"
75+
# Remember that `compgen` won't add trailing slashes by itself.
76+
local expected=($(cd "$TEST_GO_ROOTDIR"; compgen -f -- ''))
77+
add_trailing_slashes
78+
restore_bats_shell_options "$?"
7379
assert_success "${expected[@]}"
7480
}

0 commit comments

Comments
 (0)