tree-sitter/script/util/run_tests.sh

78 lines
1.2 KiB
Bash
Raw Normal View History

2014-08-30 19:57:15 -07:00
function usage {
cat <<-EOF
USAGE
$0 [-dghv] [-f focus-string]
OPTIONS
-h print this message
-d run tests in a debugger (either lldb or gdb)
-g run tests with valgrind
-v run tests with verbose output
2014-08-30 22:33:36 -07:00
-f run only tests whose description contain the given string
2014-08-30 19:57:15 -07:00
EOF
}
function run_tests {
2014-08-30 22:33:36 -07:00
local mode=normal
local args=()
2014-08-30 19:57:15 -07:00
local target=$1
local cmd="out/Debug/${target}"
shift
2014-08-30 22:33:36 -07:00
while getopts "df:ghv" option; do
case ${option} in
2014-08-30 19:57:15 -07:00
h)
usage
exit
;;
d)
2014-08-30 22:33:36 -07:00
mode=debug
;;
g)
mode=valgrind
;;
f)
2014-08-30 22:33:36 -07:00
args+=("--only=${OPTARG}")
;;
v)
2014-08-30 22:33:36 -07:00
args+=("--reporter=spec")
;;
esac
done
BUILDTYPE=Debug make $target
2014-08-30 22:33:36 -07:00
args=${args:-""}
2014-08-30 19:57:15 -07:00
2014-08-30 22:33:36 -07:00
case ${mode} in
valgrind)
valgrind \
--suppressions=./script/util/valgrind.supp \
2014-08-30 22:33:36 -07:00
--dsymutil=yes \
$cmd "${args[@]}" 2>&1 | \
grep --color -E '\w+_specs?.cc:\d+|$'
;;
2014-08-30 19:57:15 -07:00
2014-08-30 22:33:36 -07:00
debug)
if which -s gdb; then
gdb $cmd -- "${args[@]}"
elif which -s lldb; then
lldb $cmd -- "${args[@]}"
else
echo "No debugger found"
exit 1
fi
;;
2014-08-30 19:57:15 -07:00
2014-08-30 22:33:36 -07:00
normal)
time $cmd "${args[@]}"
;;
esac
}