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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
test_description='Check the configuration documents'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
ROOT="$TEST_OUTPUT_DIRECTORY/.."
test_expect_success 'extract the key lists' '
sed -n "/^Global settings$/,/^Repository-specific cgitrc file$/p" "$ROOT/MANUAL.txt" |
sed -n "s/^\([a-z][a-zA-Z0-9.<>-]*\)::$/\1/p" |
sort >manual-keys &&
sed -n -e "s/^#\{0,1\}\(mimetype\)\..*=.*/\1.<ext>/p" \
-e "s/^#\{0,1\}\(repo\.module-link\)\..*=.*/\1.<path>/p" \
-e "s/^#\{0,1\}\([a-z][a-zA-Z0-9.<>-]*\)=.*/\1/p" "$ROOT/custom/cgitrc" |
sort -u >example-keys &&
test -s manual-keys && test -s example-keys
'
test_expect_success 'the reference config sets every documented key' '
comm -23 manual-keys example-keys >missing &&
test_must_be_empty missing
'
test_expect_success 'every key the reference config sets is documented' '
comm -13 manual-keys example-keys >undocumented &&
test_must_be_empty undocumented
'
test_expect_success 'cgit accepts every key the manual documents' '
{
grep -v "^repo\." manual-keys |
sed -e "s/^mimetype\.<ext>$/mimetype.txt/" -e "s/$/=/" &&
echo "no-such-key=" &&
echo "repo.url=docs" &&
grep "^repo\." manual-keys | grep -v "^repo\.url$" |
sed -e "s/^repo\.module-link\.<path>$/repo.module-link.sub/" -e "s/$/=/" &&
echo "repo.no-such-key="
} >keysrc &&
cgit_rc keysrc "url=" >keys.out 2>keys.err &&
grep "Unknown" keys.err >unknown &&
test_write_lines "[cgit] Unknown config key: no-such-key" \
"[cgit] Unknown repo config key: no-such-key" >expect &&
test_cmp expect unknown
'
test_expect_success 'the manual documents every key cgit accepts' '
sed -n "/^static void apply_config(/,/^}/p" "$ROOT/source/cgit.c" |
sed -n "s/.*strcmp(name, \"\([^\"]*\)\").*/\1/p" >accepted &&
sed -n "/^void cgit_repo_config(/,/^}/p" "$ROOT/source/cgit.c" |
sed -n "s/.*strcmp(name, \"\([^\"]*\)\").*/repo.\1/p" >>accepted &&
echo mimetype.\<ext\> >>accepted &&
echo repo.module-link.\<path\> >>accepted &&
test_line_count -gt 100 accepted &&
sort -u -o accepted accepted &&
comm -23 accepted manual-keys >undocumented &&
test_must_be_empty undocumented
'
test_expect_success 'the reference config changes nothing as it ships' '
mkrepo repos/sample 1 >/dev/null &&
{
echo "repo.url=sample" &&
echo "repo.path=$PWD/repos/sample/.git"
} >alonerc &&
cat "$ROOT/custom/cgitrc" alonerc >samplerc &&
for url in "" sample/ sample/log/
do
cgit_ok alonerc "url=$url" >alone.out &&
cgit_ok samplerc "url=$url" >sample.out &&
strip_headers <alone.out >expect &&
strip_headers <sample.out >actual &&
test_grep "data-page=" actual &&
test_cmp expect actual || return 1
done
'
test_expect_success 'the reference config scans after every global setting' '
sed -n "/^#\{0,1\}scan-path=/,\$p" "$ROOT/custom/cgitrc" |
sed -n "s/^#\{0,1\}\([a-z][a-zA-Z0-9.<>-]*\)=.*/\1/p" |
grep -v "^repo\." >after-scan-path &&
echo scan-path >expect &&
test_cmp expect after-scan-path
'
test_expect_success 'strict-export and cache-size reach the scan only above it' '
mkrepo scanned/exported 1 >/dev/null &&
mkrepo scanned/plain 1 >/dev/null &&
touch scanned/exported/.git/export-ok &&
mkdir above below &&
{
echo "virtual-root=/" &&
echo "cache-root=$PWD/above" &&
echo "strict-export=export-ok" &&
echo "cache-size=64" &&
echo "scan-path=$PWD/scanned"
} >aboverc &&
{
echo "virtual-root=/" &&
echo "cache-root=$PWD/below" &&
echo "scan-path=$PWD/scanned" &&
echo "strict-export=export-ok" &&
echo "cache-size=64"
} >belowrc &&
cgit_ok aboverc "url=" >tmp &&
test_grep ">exported</a>" tmp &&
test_grep ! ">plain</a>" tmp &&
ls above/rc-* &&
cgit_ok belowrc "url=" >tmp &&
test_grep ">plain</a>" tmp &&
ls below >slots &&
test_line_count = 1 slots &&
test_grep ! "^rc-" slots
'
test_expect_success 'the manual lists its global settings in order' '
sed -n "/^Global settings$/,/^Repository settings$/p" "$ROOT/MANUAL.txt" |
sed -n "s/^\([a-z][a-zA-Z0-9.<>-]*\)::$/\1/p" >global-order &&
sort -c global-order
'
test_expect_success 'the manual lists its repository settings in order' '
sed -n "/^Repository settings$/,/^Repository-specific cgitrc file$/p" "$ROOT/MANUAL.txt" |
sed -n "s/^\(repo\.[a-zA-Z0-9.<>-]*\)::$/\1/p" >repo-order &&
sort -c repo-order
'
test_expect_success 'the contents of the manual name its sections in order' '
sed -n "/^Contents$/,/^[^-]/s/^- //p" "$ROOT/MANUAL.txt" >contents &&
test -s contents &&
sed -n "\$!N;/\n--*\$/P;D" "$ROOT/MANUAL.txt" |
grep -v "^Contents$" >sections &&
test_cmp sections contents
'
test_done
|