aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2025-11-14 19:06:36 +0100
committerMatěj Cepl <mcepl@cepl.eu>2025-12-02 21:31:14 +0100
commit05e1a22470ae63df9efa7c015355da61165b8004 (patch)
tree437545803dad3dbf55a26212f1e3d28a3ec49b70 /test
parent7c37ec643a2332a04b3c5be1e0ea300693f2d3c9 (diff)
downloadvis-05e1a22470ae63df9efa7c015355da61165b8004.tar.gz
vis-05e1a22470ae63df9efa7c015355da61165b8004.tar.xz
test: add gdb debugging support to lua tests
This commit refactors the lua test runner (`test.sh`) to support running a test inside `gdb` when the `-d` or `--debug` flag is passed.
Diffstat (limited to 'test')
-rwxr-xr-xtest/lua/test.sh44
1 files changed, 36 insertions, 8 deletions
diff --git a/test/lua/test.sh b/test/lua/test.sh
index db7fb1e..e867749 100755
--- a/test/lua/test.sh
+++ b/test/lua/test.sh
@@ -2,6 +2,21 @@
export VIS_PATH=.
[ -z "$VIS" ] && VIS="../../vis"
+
+# Function to run vis under gdb
+# This approach avoids the complex quoting issues of string variables in POSIX shell.
+debug_run() {
+ # $1 is $VIS, $2 is "$t.in"
+ gdb --batch -ex "run" -ex "bt" --args "$1" "$2"
+}
+
+# Flag to check if we are in debug mode
+DEBUG_MODE=0
+if [ "$1" = "-d" ] || [ "$1" = "--debug" ]; then
+ DEBUG_MODE=1
+ shift
+fi
+
$VIS -v
if ! $VIS -v | grep '+lua' >/dev/null 2>&1; then
@@ -15,6 +30,8 @@ TESTS_RUN=0
if [ $# -gt 0 ]; then
test_files=$*
else
+ # Use 'find ... -print' instead of command substitution in case of very long lists
+ # Although command substitution is generally POSIX, this avoids potential issues.
test_files="$(find . -type f -name '*.lua' -a ! -name visrc.lua)"
fi
@@ -22,19 +39,30 @@ for t in $test_files; do
TESTS_RUN=$((TESTS_RUN + 1))
t=${t%.lua}
t=${t#./}
- printf "%-30s" "$t"
- $VIS "$t.in" < /dev/null 2> /dev/null > "$t.out"
- if [ $? -ne 0 ]; then
- printf "FAIL\n"
- cat "$t.out"
+ if [ $DEBUG_MODE -eq 1 ]; then
+ printf "Debugging %s\n" "$t"
+ # Call the function instead of expanding a variable
+ debug_run "$VIS" "$t.in" 2> "$t.err"
else
- TESTS_OK=$((TESTS_OK + 1))
- printf "OK\n"
+ printf "% -30s" "$t"
+
+ if "$VIS" "$t.in" < /dev/null 2> "$t.err" > "$t.out"; then
+ TESTS_OK=$((TESTS_OK + 1))
+ printf "OK\n"
+ else
+ printf "FAIL\n"
+ cat "$t.out"
+ cat "$t.err"
+ fi
fi
done
-printf "Tests ok %d/%d\n" $TESTS_OK $TESTS_RUN
+if [ $DEBUG_MODE -eq 1 ]; then
+ exit 0
+fi
+
+printf "Tests ok %d/%d\n" "$TESTS_OK" "$TESTS_RUN"
# set exit status
[ $TESTS_OK -eq $TESTS_RUN ]