Skip to content

Commit 6822c15

Browse files
committed
.build/run-unittest*: accept extra args for the test runner
1 parent 8fb6755 commit 6822c15

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

.build/run-unittest

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,57 @@
11
#!/bin/sh -ef
22

3-
if [ "$#" -eq 0 ]; then
4-
use_valgrind=
5-
elif [ "$#" -eq 1 ] && [ "$1" = '--valgrind' ]; then
6-
use_valgrind=1
7-
else
8-
echo "Usage: $0 [--valgrind]" >&2
3+
usage()
4+
{
5+
echo "Usage: $0 [-h | --help] [--valgrind] [-- <gtest_args>...]"
6+
echo
7+
echo 'Options:'
8+
echo ' -h, --help Show this help message and exit.'
9+
echo ' --valgrind Run tests under Valgrind.'
10+
echo ' -- Pass remaining arguments to the test runner.'
11+
echo
12+
echo 'Examples:'
13+
echo ' * Basic usage:'
14+
echo " $0"
15+
echo
16+
echo " * Run all tests (including disabled tests) under Valgrind:"
17+
echo " $0 --valgrind -- --gtest_also_run_disabled_tests"
18+
echo
19+
}
20+
21+
die()
22+
{
23+
printf '%s\n' "$1" >&2
24+
printf '\n%s\n' "$(usage)" >&2
925
exit 1
10-
fi
26+
}
27+
28+
use_valgrind=
29+
30+
while [ "$#" -gt 0 ]; do
31+
case $1 in
32+
-h|--help)
33+
usage
34+
exit
35+
;;
36+
--valgrind)
37+
use_valgrind=1
38+
;;
39+
--)
40+
shift
41+
break
42+
;;
43+
*)
44+
die "Error: unexpected argument '$1'"
45+
;;
46+
esac
47+
shift
48+
done
1149

1250
cd "$(dirname "$0")"/..
1351

1452
cd build/tests
1553
if [ -n "$use_valgrind" ]; then
16-
valgrind -s --leak-check=full --show-leak-kinds=all ./unittest
54+
valgrind -s --leak-check=full --show-leak-kinds=all ./unittest ${@:+"$@"}
1755
else
18-
./unittest
56+
./unittest ${@:+"$@"}
1957
fi

.build/run-unittest.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ try {
1919
#ctest -C Debug --output-on-failure
2020

2121
# Run gtest-generated binary directly, produces more detailed output
22-
./tests/Debug/unittest.exe
22+
#
23+
# NOTE: `$args` is a built-in PowerShell variable that contains all command-line arguments
24+
# passed to the script (see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.5#args).
25+
# We use [splatting](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.5)
26+
# to pass all received arguments to the test runner.
27+
./tests/Debug/unittest.exe @args
2328
} finally {
2429
Pop-Location
2530
}

0 commit comments

Comments
 (0)