2016-01-15 11:19:24 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
2016-01-15 11:35:35 -08:00
|
|
|
set -e
|
|
|
|
|
|
2016-01-15 11:19:24 -08:00
|
|
|
function usage {
|
|
|
|
|
cat <<-EOF
|
|
|
|
|
USAGE
|
|
|
|
|
|
2023-07-16 19:50:13 +03:00
|
|
|
$0 [-adDg] [-s SEED] [-l LANGUAGE] [-e EXAMPLE]
|
2016-01-15 11:19:24 -08:00
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
|
|
2019-01-25 12:05:21 -08:00
|
|
|
-h Print this message
|
2016-01-15 11:19:24 -08:00
|
|
|
|
2024-03-15 14:40:01 -07:00
|
|
|
-a Compile C code with the Clang address sanitizer
|
2017-06-14 13:28:03 -04:00
|
|
|
|
2019-01-25 12:05:21 -08:00
|
|
|
-e Run only the corpus tests whose name contain the given string
|
2016-01-15 11:19:24 -08:00
|
|
|
|
2022-06-24 12:23:13 -07:00
|
|
|
-i Run the given number of iterations of randomized tests (default 10)
|
2016-08-29 11:51:47 -07:00
|
|
|
|
2019-01-25 12:05:21 -08:00
|
|
|
-s Set the seed used to control random behavior
|
2019-01-14 17:19:46 -08:00
|
|
|
|
2019-01-25 12:05:21 -08:00
|
|
|
-d Print parsing log to stderr
|
|
|
|
|
|
|
|
|
|
-D Generate an SVG graph of parsing logs
|
|
|
|
|
|
|
|
|
|
-g Run the tests with a debugger
|
2017-06-14 13:28:03 -04:00
|
|
|
|
2016-01-15 11:19:24 -08:00
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-14 17:19:46 -08:00
|
|
|
export RUST_BACKTRACE=full
|
2017-06-27 15:44:58 -07:00
|
|
|
|
2019-01-25 12:05:21 -08:00
|
|
|
mode=normal
|
2022-03-02 16:45:54 -08:00
|
|
|
test_flags=""
|
2019-01-25 12:05:21 -08:00
|
|
|
|
2022-06-24 12:23:13 -07:00
|
|
|
while getopts "adDghl:e:s:i:" option; do
|
2016-01-15 11:19:24 -08:00
|
|
|
case ${option} in
|
|
|
|
|
h)
|
|
|
|
|
usage
|
|
|
|
|
exit
|
|
|
|
|
;;
|
2020-05-18 10:48:47 -07:00
|
|
|
a)
|
2024-03-15 14:40:01 -07:00
|
|
|
export CFLAGS="-fsanitize=undefined,address"
|
|
|
|
|
|
|
|
|
|
# When the Tree-sitter C library is compiled with the address sanitizer, the address sanitizer
|
|
|
|
|
# runtime library needs to be linked into the final test executable. When using Xcode clang,
|
|
|
|
|
# the Rust linker doesn't know where to find that library, so we need to specify linker flags directly.
|
|
|
|
|
runtime_dir=$(cc -print-runtime-dir)
|
|
|
|
|
if [[ $runtime_dir == */Xcode.app/* ]]; then
|
|
|
|
|
export RUSTFLAGS="-C link-arg=-L${runtime_dir} -C link-arg=-lclang_rt.asan_osx_dynamic -C link-arg=-Wl,-rpath,${runtime_dir}"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Specify a `--target` explicitly. This is required for address sanitizer support.
|
2020-12-02 15:35:28 -08:00
|
|
|
toolchain=$(rustup show active-toolchain)
|
|
|
|
|
toolchain_regex='(stable|beta|nightly)-([_a-z0-9-]+).*'
|
|
|
|
|
if [[ $toolchain =~ $toolchain_regex ]]; then
|
|
|
|
|
release=${BASH_REMATCH[1]}
|
|
|
|
|
current_target=${BASH_REMATCH[2]}
|
|
|
|
|
else
|
|
|
|
|
echo "Failed to parse toolchain '${toolchain}'"
|
|
|
|
|
fi
|
2024-03-15 14:40:01 -07:00
|
|
|
|
|
|
|
|
test_flags+=" --target ${current_target}"
|
2020-05-18 10:48:47 -07:00
|
|
|
;;
|
2019-01-14 17:19:46 -08:00
|
|
|
e)
|
2022-03-02 16:45:54 -08:00
|
|
|
export TREE_SITTER_EXAMPLE=${OPTARG}
|
2019-01-25 12:05:21 -08:00
|
|
|
;;
|
2016-01-15 11:19:24 -08:00
|
|
|
s)
|
2022-03-02 16:45:54 -08:00
|
|
|
export TREE_SITTER_SEED=${OPTARG}
|
2016-01-15 11:19:24 -08:00
|
|
|
;;
|
2022-06-24 12:23:13 -07:00
|
|
|
i)
|
|
|
|
|
export TREE_SITTER_ITERATIONS=${OPTARG}
|
|
|
|
|
;;
|
2019-01-14 17:19:46 -08:00
|
|
|
d)
|
2022-03-02 16:45:54 -08:00
|
|
|
export TREE_SITTER_LOG=1
|
2016-08-29 11:51:47 -07:00
|
|
|
;;
|
2019-01-14 17:19:46 -08:00
|
|
|
D)
|
2022-03-02 16:45:54 -08:00
|
|
|
export TREE_SITTER_LOG_GRAPHS=1
|
2019-01-25 12:05:21 -08:00
|
|
|
;;
|
|
|
|
|
g)
|
|
|
|
|
mode=debug
|
2017-06-14 13:28:03 -04:00
|
|
|
;;
|
2016-01-15 11:19:24 -08:00
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2019-03-21 11:23:30 -07:00
|
|
|
shift $(expr $OPTIND - 1)
|
2019-01-25 12:05:21 -08:00
|
|
|
|
|
|
|
|
if [[ "${mode}" == "debug" ]]; then
|
2019-03-21 11:23:30 -07:00
|
|
|
test_binary=$(
|
2020-12-02 15:35:28 -08:00
|
|
|
cargo test $test_flags --no-run --message-format=json 2> /dev/null |\
|
2019-03-21 11:23:30 -07:00
|
|
|
jq -rs 'map(select(.target.name == "tree-sitter-cli" and .executable))[0].executable'
|
|
|
|
|
)
|
2022-03-02 16:45:54 -08:00
|
|
|
lldb "${test_binary}" -- $1
|
2019-01-25 12:05:21 -08:00
|
|
|
else
|
2022-03-02 16:45:54 -08:00
|
|
|
cargo test $test_flags $1 -- --nocapture
|
2019-01-25 12:05:21 -08:00
|
|
|
fi
|