Skip to content

Commit b08b59a

Browse files
author
bors-servo
authored
Auto merge of rust-lang#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 ... ~~~
2 parents d37fe13 + e7009e2 commit b08b59a

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ target/
44
bindgen-integration/Cargo.lock
55
tests/expectations/Cargo.lock
66
#*#
7+
8+
# Test script output
9+
ir.dot
10+
ir.png

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)