Skip to content

Commit b422e65

Browse files
committed
Refactor test script
Check for correct arguments, quote variables, ensure exactly one test file matches the pattern, and print usage information.
1 parent d37fe13 commit b422e65

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

tests/test-one.sh

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,34 @@
1010

1111
set -eu
1212

13-
cd $(dirname $0)
13+
if [ $# -ne 1 ]; then
14+
echo "Usage: $0 <fuzzy-name>"
15+
exit 1
16+
fi
17+
18+
cd "$(dirname "$0")"
1419
cd ..
1520

1621
export RUST_BACKTRACE=1
1722

18-
# Grab the first match
19-
TEST=$(find ./tests/headers -type f -iname "*$1*" | head -n 1)
23+
unique_fuzzy_file() {
24+
local pattern="$1"
25+
local results="$(find ./tests/headers -type f -iname "*$pattern*")"
26+
local num_results=$(echo "$results" | wc -l)
27+
28+
if [[ -z "$results" ]]; then
29+
>&2 echo "ERROR: no files found with pattern \"$pattern\""
30+
exit 1
31+
elif [[ "$num_results" -ne 1 ]]; then
32+
>&2 echo "ERROR: Expected exactly 1 result, got $num_results:"
33+
>&2 echo "$results"
34+
exit 1
35+
fi
36+
37+
echo "$results"
38+
}
39+
40+
TEST="$(unique_fuzzy_file "$1")"
2041

2142
BINDINGS=$(mktemp -t bindings.rs.XXXXXX)
2243
TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX)

0 commit comments

Comments
 (0)