Diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
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.
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/t0002-html-validity.sh | 37 |
1 file changed, 26 insertions, 11 deletions
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.tmp >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. |
