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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
test_description='Check the markup hooks a theme relies on'
CGIT_TEST_NO_CREATE_REPOS=YesPlease
. ./setup.sh
site=Example
test_expect_success 'set up a repository with a file that has an extension' '
mkrepo repos/hooks 2 &&
(
cd repos/hooks &&
mkdir dir &&
echo "int x;" >dir/hello.c &&
git add dir &&
git commit -m sources
) &&
old=$(git -C repos/hooks rev-parse HEAD~1 | cut -c1-10) &&
cgitrc_repo hooksrc hooks enable-blame=1 max-stats=year readme=:file-1 \
"root-title=$site"
'
test_expect_success 'the root names the page and the repository' '
cgit_rc hooksrc "url=" >tmp &&
grep "<div id=.cgit. data-page=.repolist.>" tmp &&
cgit_rc hooksrc "url=hooks/log/" >tmp &&
grep "<div id=.cgit. data-page=.log. data-repo=.hooks.>" tmp
'
test_expect_success 'the landmarks and the search form are in place' '
cgit_ok hooksrc "url=hooks/log/" >tmp &&
grep "<header id=.header.>" tmp &&
grep "<nav class=.tabs. aria-label=.Pages.>" tmp &&
grep "<form class=.search. role=.search." tmp &&
grep "<main class=.content.>" tmp &&
grep "<footer class=.footer.>" tmp
'
test_expect_success 'the pages name the versions only when asked to' '
cgit_rc hooksrc "url=hooks/" >footer &&
grep "<meta name=.generator. content=.cgit.>" footer &&
grep "<footer class=.footer.>generated by <a href=[^>]*>cgit</a></footer>" footer &&
{
echo "enable-version-info=1" &&
cat hooksrc
} >versionrc &&
cgit_rc versionrc "url=hooks/" >footer &&
grep "<meta name=.generator. content=.cgit v[0-9][^>]*>" footer &&
grep "<footer class=.footer.>generated by <a href=[^>]*>cgit v[0-9][^<]*</a> (<a href=[^>]*>git [0-9][^<]*</a>)</footer>" footer &&
echo "<footer>our own</footer>" >footer.html &&
{
echo "enable-version-info=1" &&
echo "footer=$PWD/footer.html" &&
cat hooksrc
} >versionrc &&
cgit_rc versionrc "url=hooks/" >footer &&
grep "<footer>our own</footer>" footer &&
! grep "git-scm" footer
'
test_expect_success 'the listings name themselves, their sections and their rows' '
cgit_ok hooksrc "url=hooks/log/" >tmp &&
grep "<table class=.list log. aria-label=.Commits.>" tmp &&
grep "<tbody class=.log.>" tmp &&
grep "<tr class=.commit.>" tmp &&
grep "class=.active. aria-current=.page." tmp &&
grep "<th class=.left. scope=.col.>" tmp &&
cgit_rc hooksrc "url=" >tmp &&
grep "<table class=.list repolist. aria-label=.Repositories.>" tmp &&
grep "<tbody class=.repos.>" tmp &&
grep "<tr class=.repo.>" tmp &&
cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<table class=.list summary. aria-label=.Summary.>" tmp &&
grep "<tbody class=.branches.>" tmp &&
grep "<tr class=.branch.>" tmp &&
cgit_rc hooksrc "url=hooks/tree/" >tmp &&
grep "<table class=.list tree. aria-label=.Files.>" tmp &&
grep "<tr class=.dir.>" tmp &&
grep "<tr class=.blob.>" tmp &&
cgit_rc hooksrc "url=hooks/tree/dir/" >tmp &&
grep "class=.ls-blob ext-c." tmp
'
test_expect_success 'the diff pages wrap each file and label their controls' '
cgit_rc hooksrc "url=hooks/commit/" >tmp &&
grep "<table class=.commit-info.>" tmp &&
grep "<th scope=.row.>author</th>" tmp &&
grep "<div class=.file. data-path=.dir/hello.c.>" tmp &&
grep "<label for=.diff-context.>context</label>" tmp &&
grep "<select id=.diff-context. name=.context.>" tmp &&
grep "<form method=.get. aria-label=.Diff options.>" tmp &&
cgit_rc hooksrc "url=hooks/diff/&ss=1" >tmp &&
grep "<tbody class=.file. data-path=.dir/hello.c.>" tmp &&
cgit_rc hooksrc "url=hooks/stats/" >tmp &&
grep "<label for=.stats-authors.>authors</label>" tmp
'
test_expect_success 'the blob, blame and about pages open with their own containers' '
cgit_rc hooksrc "url=hooks/tree/dir/hello.c" >tmp &&
grep "<div class=.blob-header.>" tmp &&
grep "<a id=.n1." tmp &&
cgit_rc hooksrc "url=hooks/blame/dir/hello.c" >tmp &&
grep "<div class=.blob-header.>" tmp &&
cgit_rc hooksrc "url=hooks/about/" >tmp &&
grep "<div id=.about.>" tmp
'
test_expect_success 'each page names itself, then the repository and the site' '
cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<title>hooks - $site</title>" tmp &&
for page in about log refs tree stats
do
cgit_rc hooksrc "url=hooks/$page/" >tmp &&
grep "<title>$page - hooks - $site</title>" tmp || return 1
done &&
cgit_rc hooksrc "url=hooks/tree/dir/hello.c" >tmp &&
grep "<title>hello.c < dir - hooks - $site</title>" tmp &&
cgit_rc hooksrc "url=hooks/blame/dir/hello.c" >tmp &&
grep "<title>blame - hello.c < dir - hooks - $site</title>" tmp
'
test_expect_success 'a pinned page names its commit before the repository' '
cgit_rc hooksrc "url=hooks/tree/&id=$old" >tmp &&
grep "<title>tree @ $old - hooks - $site</title>" tmp &&
cgit_rc hooksrc "url=hooks/commit/&id=$old" >tmp &&
grep "<title>commit 2 @ $old - hooks - $site</title>" tmp &&
cgit_rc hooksrc "url=hooks/&id=$old" >tmp &&
grep "<title>hooks @ $old - $site</title>" tmp
'
test_expect_success 'the index is named after the site alone' '
cgit_ok hooksrc "url=" >tmp &&
test_grep "<title>$site</title>" tmp
'
test_expect_success 'a repository shows its name and keeps its url in data-repo' '
{
cat hooksrc &&
echo "repo.name=hook scripts"
} >namedrc &&
cgit_ok namedrc "url=" >tmp &&
test_grep "<td class=.col-name toplevel-repo.><a href=./hooks/.>hook scripts</a></td>" tmp &&
cgit_ok namedrc "url=hooks/log/" >tmp &&
test_grep "<div id=.cgit. data-page=.log. data-repo=.hooks.>" tmp &&
test_grep "<title>log - hook scripts - $site</title>" tmp &&
test_grep " : <a href=./hooks/.>hook scripts</a></h1>" tmp &&
cgit_ok namedrc "url=hooks/tree/&id=$old" >tmp &&
test_grep "<title>tree @ $old - hook scripts - $site</title>" tmp &&
cgit_rc namedrc "url=hooks/tree/missing" >tmp &&
test_grep "^Status: 404" tmp &&
test_grep "<title>Not Found - hook scripts - $site</title>" tmp
'
test_expect_success 'the logo is named after the site wherever it links' '
cgit_ok hooksrc "url=hooks/" >tmp &&
test_grep "<a class=.logo. href=./.><img src=./cgit.png. alt=.$site.></a>" tmp &&
{
echo "logo-link=https://example.org/" &&
cat hooksrc
} >logorc &&
cgit_ok logorc "url=hooks/" >tmp &&
test_grep "<a class=.logo. href=.https://example.org/.><img src=./cgit.png. alt=.$site.></a>" tmp
'
test_expect_success 'a repository logo stands in on its own pages' '
{
cat hooksrc &&
echo "repo.logo=/hooks.png"
} >logorc &&
cgit_ok logorc "url=hooks/" >tmp &&
test_grep "<a class=.logo. href=./.><img src=./hooks.png. alt=.$site.></a>" tmp &&
cgit_ok logorc "url=" >tmp &&
test_grep "<a class=.logo. href=./.><img src=./cgit.png. alt=.$site.></a>" tmp
'
test_expect_success 'an empty logo leaves the header without one' '
{
echo "logo=" &&
cat hooksrc
} >logorc &&
cgit_ok logorc "url=hooks/" >tmp &&
test_grep "<header id=.header.>" tmp &&
test_grep ! "class=.logo." tmp &&
test_grep ! "<img" tmp
'
test_expect_success 'an error page names the error where a page names itself' '
cgit_rc hooksrc "url=hooks/tree/missing" >tmp &&
grep "^Status: 404" tmp &&
grep "<title>Not Found - hooks - $site</title>" tmp &&
cgit_rc hooksrc "url=hooks/nonsense/" >tmp &&
grep "<title>Not Found - hooks - $site</title>" tmp &&
cgitrc_repo brokenrc broken "root-title=$site" "repo.path=$PWD/nowhere" &&
cgit_rc brokenrc "url=broken/" >tmp &&
grep "Failed to open broken" tmp &&
grep "<title>Not Found - $site</title>" tmp
'
test_expect_success 'the pages ask robots what the robots setting says' '
cgit_ok hooksrc "url=hooks/" >tmp &&
test_grep "<meta name=.robots. content=.index, nofollow.>" tmp &&
{
echo "robots=noindex, noarchive" &&
cat hooksrc
} >robotsrc &&
cgit_ok robotsrc "url=hooks/" >tmp &&
test_grep "<meta name=.robots. content=.noindex, noarchive.>" tmp &&
{
echo "robots=" &&
cat hooksrc
} >robotsrc &&
cgit_ok robotsrc "url=hooks/" >tmp &&
test_grep "<meta name=.generator." tmp &&
test_grep ! "<meta name=.robots." tmp
'
test_expect_success 'every monospace element takes the theme font' '
sed -n "/^div#cgit code,$/,/^}/p" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" >rule &&
grep "^div#cgit pre,$" rule &&
grep "^ font-family: var(--font-mono);$" rule
'
test_expect_success 'the stylesheet and the script name only the current hooks' '
test_grep ! -E "_dark|#summary|ul\.pager|td:empty" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" &&
test_grep "window.cgit.updateAges" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" &&
test_grep "window.cgit.highlightLines" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js"
'
test_expect_success 'the page background is the same everywhere it is set' '
css="$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" &&
sed -n "s/^ --bg: *light-dark(\(#[0-9a-f]*\), \(#[0-9a-f]*\));\$/\1 \2/p" "$css" >expect &&
test_line_count = 1 expect &&
sed -n "/^html.cgit-standalone {\$/,/^}/s/^ background: light-dark(\(#[0-9a-f]*\), \(#[0-9a-f]*\));\$/\1 \2/p" "$css" >actual &&
test_cmp expect actual &&
cgit_rc hooksrc "url=hooks/" >tmp &&
light=$(sed -n "s/.*theme-color. media=.(prefers-color-scheme: light). content=.\(#[0-9a-f]*\).*/\1/p" tmp) &&
dark=$(sed -n "s/.*theme-color. media=.(prefers-color-scheme: dark). content=.\(#[0-9a-f]*\).*/\1/p" tmp) &&
echo "$light $dark" >actual &&
test_cmp expect actual
'
test_expect_success 'the script waits for the page instead of holding it up' '
cgit_rc hooksrc "url=hooks/" >tmp &&
grep "<script src=./cgit.js. defer></script>" tmp
'
test_expect_success 'the script walks the ages from a list that holds still' '
test_grep "window.cgit.updateAges" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js" &&
test_grep ! "getElementsByClassName" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js"
'
test_expect_success 'a line range scrolls where a single line does' '
grep "^ scroll-margin-top: calc(50vh - 1em);$" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.css" &&
grep "first.scrollIntoView();" "$TEST_OUTPUT_DIRECTORY/../assets/cgit.js"
'
test_expect_success 'set up the remaining kinds of entry' '
(
cd repos/hooks &&
git tag -a -m "first release" v1 &&
test_ln_s_add file-1 link &&
git update-index --add --cacheinfo "160000,$(git rev-parse HEAD),sub" &&
git commit -m "more kinds of entry" -m "Fixes: $(git rev-parse --short HEAD)"
) &&
git init -q --bare repos/empty.git &&
{
echo "virtual-root=/" &&
echo "cache-size=0" &&
echo "enable-commit-trailers=1" &&
echo "max-repo-count=1" &&
echo "clone-url=https://example.com/clone.git" &&
echo "repo.url=hooks" &&
echo "repo.path=$PWD/repos/hooks/.git" &&
echo "repo.url=again" &&
echo "repo.path=$PWD/repos/hooks/.git" &&
echo "repo.url=empty" &&
echo "repo.path=$PWD/repos/empty.git"
} >morerc
'
test_expect_success 'the refs, summary and tree name every section and row' '
cgit_rc morerc "url=hooks/refs/" >tmp &&
grep "<table class=.list refs. aria-label=.Branches and tags.>" tmp &&
grep "<tbody class=.tags.>" tmp &&
grep "<tr class=.tag.>" tmp &&
cgit_rc morerc "url=hooks/" >tmp &&
grep "<tbody class=.clone.>" tmp &&
cgit_rc morerc "url=hooks/tree/" >tmp &&
grep "<tbody class=.tree.>" tmp &&
grep "<tr class=.link.>" tmp &&
grep "<tr class=.mod.>" tmp
'
test_expect_success 'the commit page has its trailer table and diffstat' '
cgit_rc morerc "url=hooks/commit/" >tmp &&
grep "<table class=.commit-trailers.>" tmp &&
grep "<table class=.diffstat.>" tmp
'
test_expect_success 'the breadcrumb, the pager and the ages carry their hooks' '
cgit_rc morerc "url=hooks/tree/dir/" >tmp &&
grep "<nav class=.path. aria-label=.breadcrumb.>" tmp &&
cgit_rc morerc "url=" >tmp &&
grep "<nav class=.pager. aria-label=.Pager.>" tmp &&
grep "class=.current. aria-current=.page." tmp &&
grep "<time class=.age-[a-z]*. datetime=.[^ ]* data-ut=.[0-9]*." tmp
'
test_expect_success 'a date shown in full is a plain time element' '
{
echo "enable-relative-dates=0" &&
cat morerc
} >fullrc &&
cgit_rc fullrc "url=" >tmp &&
grep "<time datetime=" tmp &&
! grep "data-ut=" tmp
'
test_expect_success 'an empty repository lists its clone urls as a clone table' '
cgit_rc morerc "url=empty/" >tmp &&
grep "<table class=.list clone. aria-label=.Clone urls.>" tmp &&
grep "<tbody class=.clone.>" tmp
'
test_expect_success 'embedded mode marks the root' '
{
echo "embedded=1" &&
cat hooksrc
} >embeddedrc &&
cgit_rc embeddedrc "url=hooks/" >tmp &&
grep "<div id=.cgit. class=.cgit-embedded. data-page=.summary." tmp
'
test_done
|