summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Finkenauer <tmfinken@gmail.com>2017-06-17 14:59:13 -0700
committerTravis Finkenauer <tmfinken@gmail.com>2017-06-17 15:10:42 -0700
commitb422e6566f6f83f3b0a66ea4c482fdfcb8620147 (patch)
treedaf61a092723b9fd8b9b766a1fe15953196917db
parentd37fe132be5350ed1477b4e578a5d1b70c583666 (diff)
Refactor test script
Check for correct arguments, quote variables, ensure exactly one test file matches the pattern, and print usage information.
-rwxr-xr-xtests/test-one.sh27
1 files changed, 24 insertions, 3 deletions
diff --git a/tests/test-one.sh b/tests/test-one.sh
index ac466164..d274a53f 100755
--- a/tests/test-one.sh
+++ b/tests/test-one.sh
@@ -10,13 +10,34 @@
set -eu
-cd $(dirname $0)
+if [ $# -ne 1 ]; then
+ echo "Usage: $0 <fuzzy-name>"
+ exit 1
+fi
+
+cd "$(dirname "$0")"
cd ..
export RUST_BACKTRACE=1
-# Grab the first match
-TEST=$(find ./tests/headers -type f -iname "*$1*" | head -n 1)
+unique_fuzzy_file() {
+ local pattern="$1"
+ local results="$(find ./tests/headers -type f -iname "*$pattern*")"
+ local num_results=$(echo "$results" | wc -l)
+
+ if [[ -z "$results" ]]; then
+ >&2 echo "ERROR: no files found with pattern \"$pattern\""
+ exit 1
+ elif [[ "$num_results" -ne 1 ]]; then
+ >&2 echo "ERROR: Expected exactly 1 result, got $num_results:"
+ >&2 echo "$results"
+ exit 1
+ fi
+
+ echo "$results"
+}
+
+TEST="$(unique_fuzzy_file "$1")"
BINDINGS=$(mktemp -t bindings.rs.XXXXXX)
TEST_BINDINGS_BINARY=$(mktemp -t bindings.XXXXXX)