tree-sitter/script/util/run_tests.sh

90 lines
1.4 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 {
local profile=
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
while getopts "df:ghpv" 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
;;
p)
profile=true
;;
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
if [[ -n $profile ]]; then
export CPUPROFILE=/tmp/${target}-$(date '+%s').prof
fi
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 lldb; then
2014-08-30 22:33:36 -07:00
lldb $cmd -- "${args[@]}"
elif which -s gdb; then
gdb $cmd -- "${args[@]}"
2014-08-30 22:33:36 -07:00
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
if [[ -n $profile ]]; then
pprof $cmd $CPUPROFILE
fi
}