blob: f22b2b6227f9d897d935594267882156f7e00436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/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"
	# A second argument names a config of its own, for pages the shared
	# config keeps turned off.
	if test -n "$2"
	then
		CGIT_CONFIG="$PWD/$2" QUERY_STRING="url=$1" cgit >tidy-$test_count.tmp || return
	else
		cgit_url "$1" >tidy-$test_count.tmp || return
	fi
	# 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" $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=$(command -v 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 '<!DOCTYPE html>\n<html lang="en"><head><title>t</title></head><body><header>x</header></body></html>\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_expect_success 'foo/refs' 'test_url "foo/refs"'
test_expect_success 'error page' 'test_url "no-such-repo"'

# Stats and blame stay off in the shared config, so their pages validate
# through a config of their own.
test_expect_success 'set up a features config' '
	{
		echo "virtual-root=/" &&
		echo "cache-size=0" &&
		echo "max-stats=year" &&
		echo "enable-blame=1" &&
		echo "repo.url=feat" &&
		echo "repo.path=$PWD/repos/foo/.git"
	} >featrc
'

test_expect_success 'stats page' 'test_url "feat/stats/" featrc'
test_expect_success 'blame page' 'test_url "feat/blame/file-1" featrc'

test_done