From 6b9dac473def1e6ed0daedb9eb35664fbbfffb8c Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Mon, 24 Aug 2026 16:51:55 -1000 Subject: Prefer POSIX forms throughout the test scripts --- tests/Makefile | 3 +++ tests/filters/dump.sh | 6 +++++- tests/setup.sh | 8 +++++--- tests/t0001-git-version.sh | 3 ++- tests/t0002-html-validity.sh | 3 +-- tests/t0201-filters.sh | 3 ++- tests/t0204-limits.sh | 7 ++++--- tests/t0302-home-access.sh | 2 +- tests/valgrind/bin/cgit | 7 +++++-- 9 files changed, 28 insertions(+), 14 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 1047de5..7a8beb1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -4,6 +4,9 @@ # to pass extra options along. The top-level Makefile reaches this through its # test target, once cgit and the Git tree it links against have been built. +.DEFAULT_GOAL := all +.SUFFIXES: + # SHELL_PATH comes from Git's platform detection, and cgit.conf may override it, # so both are read before anything below uses it. include ../vendor/git/config.mak.uname diff --git a/tests/filters/dump.sh b/tests/filters/dump.sh index da6f7a1..a4c1571 100755 --- a/tests/filters/dump.sh +++ b/tests/filters/dump.sh @@ -1,4 +1,8 @@ #!/bin/sh -[ "$#" -gt 0 ] && printf "%s " "$*" +# Test fixture for the cgit exec filter API, exercised by t0201-filters.sh. +# It echoes the arguments it was invoked with and upper-cases the body, which +# lets the test confirm that both flow through the exec: filter path. + +test "$#" -gt 0 && printf "%s " "$*" tr '[:lower:]' '[:upper:]' diff --git a/tests/setup.sh b/tests/setup.sh index 93a663a..aac498c 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -56,7 +56,8 @@ FILTER_DIRECTORY=$(cd ../filters && pwd) # Lua filters only work when cgit was compiled with Lua, so the tests that use # them have to ask the binary rather than assume. -if cgit --version | grep -F -q "[+] Lua scripting"; then +if cgit --version | grep -F -q "[+] Lua scripting" +then export CGIT_HAS_LUA=1 else export CGIT_HAS_LUA=0 @@ -78,7 +79,7 @@ mkrepo() { echo $n >file-$n git add file-$n git commit -m "commit $n" - n=$(expr $n + 1) + n=$((n + 1)) done case "$variant" in testplus) @@ -146,7 +147,8 @@ repo.source-filter=exec:$FILTER_DIRECTORY/dump.sh repo.readme=master:a+b EOF - if [ $CGIT_HAS_LUA -eq 1 ]; then + if test "$CGIT_HAS_LUA" -eq 1 + then cat >>cgitrc </dev/null) -test -n "$tidy" || { +tidy=$(command -v tidy) || { skip_all='Skipping html validation tests: tidy not found' test_done exit diff --git a/tests/t0201-filters.sh b/tests/t0201-filters.sh index 88533f4..971ec36 100755 --- a/tests/t0201-filters.sh +++ b/tests/t0201-filters.sh @@ -10,7 +10,8 @@ test_description='Check filtered content' . ./setup.sh prefixes="exec" -if [ $CGIT_HAS_LUA -eq 1 ]; then +if test "$CGIT_HAS_LUA" -eq 1 +then prefixes="$prefixes lua" fi diff --git a/tests/t0204-limits.sh b/tests/t0204-limits.sh index f09c290..d35dc69 100755 --- a/tests/t0204-limits.sh +++ b/tests/t0204-limits.sh @@ -12,7 +12,8 @@ test_description='Check the ref listing and diff size limits' . ./setup.sh -if [ $CGIT_HAS_LUA -eq 1 ]; then +if test "$CGIT_HAS_LUA" -eq 1 +then test_set_prereq LUA fi @@ -24,11 +25,11 @@ test_expect_success 'set up limit fixtures' ' mkrepo repos/limits 1 && ( cd repos/limits && - seq 1 60 >big.c && + test_seq 1 60 >big.c && printf "int x;\n" >small.c && git add -A && git commit -m sources && - seq 301 360 >big.c && + test_seq 301 360 >big.c && printf "int y;\n" >small.c && git commit -am change && for i in 1 2 3; do git branch branch-$i || exit 1; done && diff --git a/tests/t0302-home-access.sh b/tests/t0302-home-access.sh index 7078596..89aa00f 100755 --- a/tests/t0302-home-access.sh +++ b/tests/t0302-home-access.sh @@ -12,7 +12,7 @@ test_description='Ensure that git does not access $HOME' # strace needs ptrace, which containers and hardened kernels refuse even # where the binary is installed, so a working run is checked as well as a # present binary. -test -n "$(which strace 2>/dev/null)" || { +command -v strace >/dev/null 2>&1 || { skip_all='Skipping access validation tests: strace not found' test_done exit diff --git a/tests/valgrind/bin/cgit b/tests/valgrind/bin/cgit index 56ca807..e35e220 100755 --- a/tests/valgrind/bin/cgit +++ b/tests/valgrind/bin/cgit @@ -1,7 +1,10 @@ #!/bin/sh -# Note that we currently use Git's suppression file and there are variables -# $GIT_VALGRIND and $CGIT_VALGRIND which point to different places. +# Stands in for the cgit binary when the suite runs with --valgrind, which is +# when setup.sh puts this directory ahead of the build on PATH. Git's own +# suppression file is reused rather than kept in a copy here, so GIT_VALGRIND +# points into the bundled Git tree while CGIT_VALGRIND points back at this +# wrapper's home. exec valgrind -q --error-exitcode=126 \ --suppressions="$GIT_VALGRIND/default.supp" \ --gen-suppressions=all \ -- cgit v2.8.0