From b4a8dba3d6447306a747ffc80e4cd375c4d1d04a Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 08:09:49 -1000 Subject: Add a request helper that checks the answer cgit exits 0 whatever goes wrong, and a die after the headers leaves a page cut short behind a 200 status, so cgit_rc and its siblings pass any page that does not crash. Only 71 of the 337 tests that request a page checked a status line. cgit_ok also wants an empty stderr and, for HTML, the closing tag. cgit_ok_url renders afresh with the page cache off, since the shared config caches a page under its request alone. --- tests/setup.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests') diff --git a/tests/setup.sh b/tests/setup.sh index 563412e..a083f75 100755 --- a/tests/setup.sh +++ b/tests/setup.sh @@ -259,6 +259,53 @@ cgit_url() { cgit_rc cgitrc "url=$1" } +# Asks for a page as cgit_rc does but fails unless the request really worked, +# with a 200 status, nothing logged and, for an HTML page, the closing tag. +# cgit exits 0 whatever goes wrong, and a death halfway through a page leaves +# it cut short behind a 200 status, so the exit status alone proves little. +# The page still goes to stdout and the log to stderr. Under -x a shell +# without BASH_XTRACEFD would trace cgit_rc into the log kept here, so the +# trace stops for that one call. +cgit_ok() { + cgit_ok_flags=$- + set +x + cgit_rc "$@" >cgit-ok.out 2>cgit-ok.err + cgit_ok_status=$? + case $cgit_ok_flags in + *x*) + set -x + ;; + esac + cat cgit-ok.out + cat cgit-ok.err >&2 + if test "$cgit_ok_status" != 0 + then + echo "cgit exited with status $cgit_ok_status" >&2 + return 1 + elif test -s cgit-ok.err + then + echo "cgit logged an error" >&2 + return 1 + elif ! sed -n 1p cgit-ok.out | grep "^Status: 200" >/dev/null + then + echo "cgit answered $(sed -n 1p cgit-ok.out)" >&2 + return 1 + elif sed "/^$/q" cgit-ok.out | grep -i "^Content-Type: text/html" >/dev/null && + ! grep "" cgit-ok.out >/dev/null + then + echo "the page stops short of " >&2 + return 1 + fi +} + +# The same against the shared repositories, through a copy of the shared +# config with the page cache off, so the page is rendered afresh rather than +# replayed from a slot an earlier test filled. +cgit_ok_url() { + sed "s/^cache-size=.*/cache-size=0/" cgitrc >cgitrc-ok && + cgit_ok cgitrc-ok "url=$1" +} + # The response headers run down to the first empty line, and a test comparing # two pages wants to see the bodies alone. strip_headers() { -- cgit 2.12.1