From ea618c5e257a6aabded76e63567ec0e7b99ac6c4 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Mon, 24 Aug 2026 16:21:18 -1000 Subject: Renumber the test scripts into themed ranges t000x the ground the suite stands on: git version, html validity, the cache t01xx page content, one script per page t02xx features that cut across pages: filters, submodule links, dates, limits t03xx defence, the security regressions and the $HOME promise t04xx the helper tools under tools/ --- tests/t0002-html-validity.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 tests/t0002-html-validity.sh (limited to 'tests/t0002-html-validity.sh') diff --git a/tests/t0002-html-validity.sh b/tests/t0002-html-validity.sh new file mode 100755 index 0000000..842437c --- /dev/null +++ b/tests/t0002-html-validity.sh @@ -0,0 +1,61 @@ +#!/bin/sh + +# Runs the tidy checker over one page of each kind cgit renders, so that markup +# broken enough to confuse a browser is caught here rather than in the browser. +# Only the shape of the markup matters, since what the pages actually say is +# the business of the t01xx scripts. Tidy is optional and old versions of it +# predate the elements cgit uses, so the whole file steps aside when a usable +# one cannot be found. + +test_description='Validate html with tidy' +. ./setup.sh + +test_url() +{ + tidy_options="-eq" + test -z "$NO_TIDY_WARNINGS" || + tidy_options="$tidy_options --show-warnings no" + cgit_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" $tidy_options tidy-$test_count + status=$? + + # Tidy leaves with 1 for warnings and 2 for errors, and only an error is + # worth failing the test over. + if test $status = 2 + then + false + else + : + fi +} + +tidy=$(which tidy 2>/dev/null) +test -n "$tidy" || { + skip_all='Skipping html validation tests: tidy not found' + test_done + exit +} + +# 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' + test_done + exit +} + +test_expect_success 'index page' 'test_url ""' +test_expect_success 'foo' 'test_url "foo"' +test_expect_success 'foo/log' 'test_url "foo/log"' +test_expect_success 'foo/tree' 'test_url "foo/tree"' +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_done -- cgit v2.8.0