tree-sitter/script/test

104 lines
2.3 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
2016-01-15 11:35:35 -08:00
set -e
function usage {
cat <<-EOF
USAGE
$0 [-adDg] [-s SEED] [-l LANGUAGE] [-e EXAMPLE] [-t TRIAL]
OPTIONS
2019-01-25 12:05:21 -08:00
-h Print this message
-a Compile C code with the Clang static analyzer
2019-01-25 12:05:21 -08:00
-l Run only the corpus tests for the given language
2019-01-25 12:05:21 -08:00
-e Run only the corpus tests whose name contain the given string
2019-01-25 12:05:21 -08:00
-t Run only the given trial number of randomized test
2019-01-25 12:05:21 -08:00
-s Set the seed used to control random behavior
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
EOF
}
export RUST_BACKTRACE=full
2019-01-25 12:05:21 -08:00
mode=normal
test_flags="-p tree-sitter-cli"
2019-01-25 12:05:21 -08:00
while getopts "adDghl:e:s:t:" option; do
case ${option} in
h)
usage
exit
;;
a)
export RUSTFLAGS="-Z sanitizer=address"
# Specify a `--target` explicitly. For some reason, this is required for
# address sanitizer support.
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
test_flags="${test_flags} --target ${current_target}"
;;
l)
export TREE_SITTER_TEST_LANGUAGE_FILTER=${OPTARG}
;;
e)
export TREE_SITTER_TEST_EXAMPLE_FILTER=${OPTARG}
;;
2019-01-25 12:05:21 -08:00
t)
export TREE_SITTER_TEST_TRIAL_FILTER=${OPTARG}
;;
s)
2019-01-25 12:05:21 -08:00
export TREE_SITTER_TEST_SEED=${OPTARG}
;;
d)
2019-01-25 12:05:21 -08:00
export TREE_SITTER_TEST_ENABLE_LOG=1
;;
D)
2019-01-25 12:05:21 -08:00
export TREE_SITTER_TEST_ENABLE_LOG_GRAPHS=1
;;
g)
mode=debug
;;
esac
done
shift $(expr $OPTIND - 1)
2019-01-25 12:05:21 -08:00
top_level_filter=$1
if [[ \
-n $TREE_SITTER_TEST_LANGUAGE_FILTER || \
-n $TREE_SITTER_TEST_EXAMPLE_FILTER || \
-n $TREE_SITTER_TEST_TRIAL_FILTER \
]]; then
2020-09-02 09:17:48 -07:00
: ${top_level_filter:=corpus}
2016-11-18 13:47:31 -08:00
fi
2019-01-25 12:05:21 -08:00
if [[ "${mode}" == "debug" ]]; then
test_binary=$(
cargo test $test_flags --no-run --message-format=json 2> /dev/null |\
jq -rs 'map(select(.target.name == "tree-sitter-cli" and .executable))[0].executable'
)
2019-01-25 12:05:21 -08:00
lldb "${test_binary}" -- $top_level_filter
else
cargo test $test_flags --jobs 1 $top_level_filter -- --nocapture
2019-01-25 12:05:21 -08:00
fi