From ed1b6d435183de0af3fadf84c6ea8234cf8768a3 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 08:41:15 -1000 Subject: Validate only pages that rendered in t0002 test_url failed only on tidy's own errors, so a 404 or a 500 page in place of the stats or the blame page validated as well as the real one, and an empty body drew no more than warnings. --- tests/t0002-html-validity.sh | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'tests/t0002-html-validity.sh') diff --git a/tests/t0002-html-validity.sh b/tests/t0002-html-validity.sh index a4a6725..08a0e99 100755 --- a/tests/t0002-html-validity.sh +++ b/tests/t0002-html-validity.sh @@ -8,19 +8,30 @@ test_description='Validate html with tidy' . ./setup.sh -test_url() { - # A second argument names a config of its own, for pages the shared - # config keeps turned off. - cgit_rc "${2:-cgitrc}" "url=$1" >tidy-$test_count.tmp || return - # Tidy reads what it is given as a whole document, so the response - # headers are dropped before it sees the page. - 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 reads what it is given as a whole document, so the response headers are +# dropped before it sees the page, and an empty page would only draw warnings. +# Tidy leaves with 1 for warnings and 2 for errors, and only an error is worth +# failing the test over. +tidy_page() { + strip_headers <"$1.out" >"$1" && + test -s "$1" || return 1 + tidy -eq "$1" test $? != 2 } +# Validates the page at the url given, which has to render whole, through a +# config named second for the pages the shared config keeps turned off. +test_url() { + tidy_file=tidy-$(printf '%s' "${1:-index}" | tr / -) && + if test -n "$2" + then + cgit_ok "$2" "url=$1" + else + cgit_ok_url "$1" + fi >"$tidy_file.out" && + tidy_page "$tidy_file" +} + # Releases of tidy that predate HTML5 reject the semantic elements cgit emits, # header, nav, main and footer among them, reporting each as an error, so only # a tidy new enough to understand them will do. @@ -46,7 +57,11 @@ test_expect_success 'foo/tree/file-1' 'test_url "foo/tree/file-1"' test_expect_success 'foo/commit' 'test_url "foo/commit"' test_expect_success 'foo/diff' 'test_url "foo/diff"' test_expect_success 'foo/refs' 'test_url "foo/refs"' -test_expect_success 'error page' 'test_url "no-such-repo"' +test_expect_success 'error page' ' + cgit_url "no-such-repo" >tidy-error.out && + grep "^Status: 404" tidy-error.out && + tidy_page tidy-error +' # Stats and blame stay off in the shared config, so their pages validate # through a config of their own. -- cgit 2.12.1