From 4c428b0412c4c0334a2bae1a90e8f494c5d05ce6 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 08:32:12 -1000 Subject: Let a test run require the tools it must not skip Nothing could make a missing prerequisite fail. A host without pkg-config builds without Lua, and make test then passed with every Lua test skipped and the lua pass of t0201 never run. The whole-script skips become named prerequisites so the same list covers them, and the strace probe now traces the file class of calls the tests use, so an strace too old for it skips rather than fails. --- README.txt | 10 ++++++++++ tests/setup.sh | 7 +++++++ tests/t0002-html-validity.sh | 26 ++++++++++++++------------ tests/t0006-nolua.sh | 4 +++- tests/t0302-home-access.sh | 16 ++++++++-------- tests/t0401-serve.sh | 9 +++++++-- 6 files changed, 49 insertions(+), 23 deletions(-) diff --git a/README.txt b/README.txt index fa568f3..a2d8185 100644 --- a/README.txt +++ b/README.txt @@ -351,6 +351,16 @@ standalone Lua or LuaJIT for the unit checks of the filters, with lpeg, luaossl and luaposix for some of them, and dash, ksh and bash besides sh for the hooks. A few need an account other than root. +A run that has to cover everything, such as one before a release, names the +prerequisites it cannot go without in CGIT_TEST_REQUIRE, separated by spaces, +and a script that finds one missing then stops with an error rather than skip +the tests that need it. The names are CGIT_LUA for a cgit built with Lua, +CGIT_NOLUA for build/nolua, TIDY, STRACE and STRACE_DELAY, PYTHON, XMLLINT, +UNZIP, GZIP, BZIP2, LZIP, XZ, ZSTD, SANITY for an account other than root, and +the others the tests in a script name, such as CGIT_LUA_LPEG. + + $ make test CGIT_TEST_REQUIRE="CGIT_LUA TIDY STRACE SANITY" + Credits ------- diff --git a/tests/setup.sh b/tests/setup.sh index 68b7a5b..c61fa85 100644 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -145,6 +145,13 @@ then fi unset cgit_version cgit_flags +# A run that has to cover everything names the prerequisites it cannot go +# without in CGIT_TEST_REQUIRE, and the library then stops a script that finds +# one missing rather than skip the tests that need it. Lua is asked about at +# once, as a few scripts leave whole tests out when cgit has none. +GIT_TEST_REQUIRE_PREREQ="$GIT_TEST_REQUIRE_PREREQ $CGIT_TEST_REQUIRE" +test_have_prereq CGIT_LUA || : + # Creates a repository holding the given number of one file commits. A third # argument asks for a variant, either testplus for a file and a branch whose # names have to be escaped in a URL, or commit-graph for a written commit graph. diff --git a/tests/t0002-html-validity.sh b/tests/t0002-html-validity.sh index bdccaf2..a4a6725 100755 --- a/tests/t0002-html-validity.sh +++ b/tests/t0002-html-validity.sh @@ -17,22 +17,24 @@ test_url() { strip_headers tidy-$test_count || return # Tidy leaves with 1 for warnings and 2 for errors, and only an error is # worth failing the test over. - "$tidy" -eq tidy-$test_count + tidy -eq tidy-$test_count test $? != 2 } -tidy=$(command -v tidy) || { - skip_all='Skipping html validation tests: tidy not found' - test_done -} - # Releases of tidy that predate HTML5 reject the semantic elements cgit emits, -# header, nav, main and footer among them, reporting each as an error. Skip the -# validation unless tidy is new enough to understand them. -printf '\nt
x
\n' \ - | "$tidy" -q -e >/dev/null 2>&1 -test $? -ge 2 && { - skip_all='Skipping html validation tests: tidy is too old for HTML5' +# header, nav, main and footer among them, reporting each as an error, so only +# a tidy new enough to understand them will do. +test_lazy_prereq TIDY ' + cat >probe.html <<-\EOF && + + t
x
+ EOF + tidy -q -e probe.html >/dev/null 2>&1 + test $? -lt 2 +' + +test_have_prereq TIDY || { + skip_all='Skipping html validation tests: no tidy that knows HTML5' test_done } diff --git a/tests/t0006-nolua.sh b/tests/t0006-nolua.sh index cd35fca..f68e731 100755 --- a/tests/t0006-nolua.sh +++ b/tests/t0006-nolua.sh @@ -10,7 +10,9 @@ test_description='Check the build without Lua' . ./setup.sh nolua="$TEST_OUTPUT_DIRECTORY/../build/nolua/cgit" -test -x "$nolua" || { +test_lazy_prereq CGIT_NOLUA 'test -x "$nolua"' + +test_have_prereq CGIT_NOLUA || { skip_all='Skipping the Lua-less checks: build/nolua/cgit is missing, run make test' test_done } diff --git a/tests/t0302-home-access.sh b/tests/t0302-home-access.sh index 6447927..0c0fcd2 100755 --- a/tests/t0302-home-access.sh +++ b/tests/t0302-home-access.sh @@ -11,14 +11,14 @@ test_description='Ensure that git does not access $HOME' . ./setup.sh # strace needs ptrace, which a system can refuse even where the binary is -# installed, so a working run is checked as well as a present binary. -command -v strace >/dev/null 2>&1 || { - skip_all='Skipping access validation tests: strace not found' - test_done -} - -strace true 2>/dev/null || { - skip_all='Skipping access validation tests: strace not functional' +# installed, and a release that knows the file class of calls, so the probe +# traces that class. +test_lazy_prereq STRACE ' + strace -o /dev/null -e trace=%file true +' + +test_have_prereq STRACE || { + skip_all='Skipping access validation tests: no strace that can trace here' test_done } diff --git a/tests/t0401-serve.sh b/tests/t0401-serve.sh index 341bbb6..4a2d08b 100755 --- a/tests/t0401-serve.sh +++ b/tests/t0401-serve.sh @@ -9,8 +9,13 @@ test_description='Check the preview server splits CGI output correctly' CGIT_TEST_NO_CREATE_REPOS=YesPlease . ./setup.sh -command -v python3 >/dev/null 2>&1 || { - skip_all='Skipping preview server tests: python3 not found' +# serve.py uses syntax that came with Python 3.8. +test_lazy_prereq PYTHON ' + python3 -c "import sys; sys.exit(sys.version_info < (3, 8))" +' + +test_have_prereq PYTHON || { + skip_all='Skipping preview server tests: no python3 3.8 or later' test_done } -- cgit 2.12.1