diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-06-19 09:15:54 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-19 09:15:54 -0700 |
commit | b08b59a7d03a5b9b408f19c18efc38134d6ff119 (patch) | |
tree | 8318fcd4e4522771da9ff7056eb544a4ff4e80d1 | |
parent | d37fe132be5350ed1477b4e578a5d1b70c583666 (diff) | |
parent | e7009e275155bb7989b0291625b7dd82edd7d80f (diff) |
Auto merge of #761 - tmfink:script-fix, r=fitzgen
Refactor test script
Check for correct arguments, quote variables, ensure exactly one test
file matches the pattern, and print usage information.
Here are some examples:
~~~
$ ./tests/test-one.sh
Usage: ./tests/test-one.sh <fuzzy-name>
~~~
~~~
$ ./tests/test-one.sh zzz
ERROR: no files found with pattern "zzz"
~~~
~~~
$ ./tests/test-one.sh union
ERROR: Expected exactly 1 result, got 15:
./tests/headers/struct_with_anon_unnamed_union.h
./tests/headers/union_dtor.hpp
./tests/headers/union_with_anon_union.h
./tests/headers/union_with_big_member.h
./tests/headers/anon_union.hpp
./tests/headers/union_fields.hpp
./tests/headers/union_with_anon_struct_bitfield.h
./tests/headers/struct_with_anon_union.h
./tests/headers/union-in-ns.hpp
./tests/headers/union_with_anon_unnamed_union.h
./tests/headers/union_with_anon_struct.h
./tests/headers/union_with_nesting.h
./tests/headers/union_template.hpp
./tests/headers/anon_struct_in_union.h
./tests/headers/union_with_anon_unnamed_struct.h
~~~
~~~
$ ./tests/test-one.sh keywords
...
~~~
-rw-r--r-- | .gitignore | 4 | ||||
-rwxr-xr-x | tests/test-one.sh | 27 |
2 files changed, 28 insertions, 3 deletions
@@ -4,3 +4,7 @@ target/ bindgen-integration/Cargo.lock tests/expectations/Cargo.lock #*# + +# Test script output +ir.dot +ir.png 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) |