Blob


1 #!/bin/ksh -e
3 ok_count=0
4 ok_expected=29
6 plan() {
7 echo "$ok_expected..$ok_count"
8 test "$ok_expected" -eq "$ok_count" || { echo 'failed' && exit 1; }
9 echo 'passed' && exit 0
10 }
12 bench() {
13 i="$1" && shift
14 exec 3>&1
15 {
16 time (
17 n=1 && printf . >&3
18 while [ "$n" -le "$i" ]; do
19 "$@" >/dev/null 2>&1 && n=$((n + 1))
20 printf . >&3
21 done
22 printf '\n' >&3
23 )
24 } 2>&1 | grep 'real' | cut -f2 | cut -d' ' -f5
25 exec 3>&-
26 }
28 ok() { echo "ok: $*" && ok_count=$((ok_count + 1)); }
29 not_ok() { echo "not ok: $*" && plan; }
31 t_match_n() {
32 fifo=$(mktemp -u) || exit 1
33 mkfifo "$fifo" || exit 1
34 (printf "%s" "$2" >"$fifo") &
35 printf "\n%s\n" "$(cat)" | diff - "$fifo" || not_ok "$1"
36 rm -f "$fifo"
37 }
39 t_match() {
40 fifo=$(mktemp -u) || exit 1
41 mkfifo "$fifo" || exit 1
42 (echo "$2" >"$fifo") &
43 diff - "$fifo" || not_ok "$1"
44 rm -f "$fifo"
45 }
47 t_find() {
48 find "$1" -type f | sort | sed "s,$1/,," | t_match_n "$2" "$3"
49 }
51 base=$(dirname "$0")
52 cmd="$base/ssg.sh"
53 test -x "$cmd" || { echo "$cmd not found" >&2 && exit 1; }
55 basic_case() {
56 dir=$(mktemp -d)
57 src="$dir/src" && dst="$dir/dst"
58 mkdir "$src" "$src/.git"
59 echo '# h1' >"$src/markdown.md"
60 echo '<h1>h1</h1>' >"$src/html1.html"
61 echo '<html>' >"$src/html2.html"
62 echo '<title>{{title}}:{{site}}</title>{{content}}' >"$src/.ssg.template"
63 echo '.git/' >"$src/.ssg.ignore"
64 echo >"$src/.git/index"
65 echo >"$src/main.css"
66 echo >"$src/logo.png"
67 # shellcheck disable=2016
68 echo '
69 if test -z "$1"; then echo "x.txt" && exit; fi
70 echo . >"$2/x.txt" && echo "x.txt"
71 ' >"$src/.ssg.sh"
72 "$cmd" "$src" "$dst" | t_match_n "basic_case" '
73 ignore .ssg.ignore
74 sh .ssg.sh > x.txt
75 sh .ssg.sh > x.txt.gz
76 template .ssg.template
77 html html1.html, .ssg.template > html1.html
78 html html1.html, .ssg.template > html1.html.gz
79 html html2.html
80 html html2.html > html2.html.gz
81 copy logo.png
82 copy gz main.css
83 copy gz main.css > main.css.gz
84 md markdown.md, .ssg.template > markdown.html
85 md markdown.md, .ssg.template > markdown.html.gz
86 sitemap sitemap.xml
87 sitemap sitemap.xml.gz
88 sitemap robots.txt
89 sitemap robots.txt.gz
90 e601a42390b8c734a818abc9b7406ea6a52a12c912a37b7464eb17df27d6d0e0
91 '
92 rm -rf "$dir"
93 }
95 t() {
96 dir=$(mktemp -d) && src="$dir/src" && dst="$dir/dst"
97 case "$1" in
99 fail_no_args)
100 if "$cmd" "$src" 2>/dev/null; then
101 exit_code="$?" && test "$exit_code" -eq 1 ||
102 not_ok "$1: expected: exit code 1, actual: exit code $exit_code"
103 fi
104 test -d "$dst" && not_ok "$1"
105 ;;
107 fail_no_src)
108 if "$cmd" "$src" "$dst" 2>/dev/null; then
109 exit_code="$?" && test "$exit_code" -eq 1 ||
110 not_ok "$1: expected: exit code 1, actual: exit code $exit_code"
111 fi
112 test -d "$dst" && not_ok "$1"
113 ;;
115 select_src_files_empty_src)
116 mkdir "$src" "$dst" && "$cmd" "$src" "$dst" 2>&1 | t_match_n "$1" '
117 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
119 t_find "$dst" "$1: dst not empty" '
120 .ssg.dst
121 .ssg.src
123 ;;
125 select_src_files_ssg_ignore)
126 mkdir "$src" "$src/a" "$src/a/b" "$src/a/c"
127 echo '1.txt' >"$src/.ssg.ignore"
128 echo '2.txt
129 c/' >"$src/a/.ssg.ignore"
130 echo '3.txt' >"$src/a/b/.ssg.ignore"
131 echo >"$src/1.txt"
132 echo >"$src/a/2.txt"
133 echo >"$src/a/b/3.txt"
134 echo >"$src/a/c/4.txt"
135 echo >"$src/a/c/5.txt"
136 "$cmd" "$src" "$dst" | t_match_n "$1" '
137 ignore .ssg.ignore
138 ignore a/.ssg.ignore
139 ignore a/b/.ssg.ignore
140 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
142 t_find "$dst" "$1" '
143 .ssg.dst
144 .ssg.src
146 ;;
148 select_src_files_trailing_slash)
149 mkdir "$src" && echo >"$src/t.png"
150 "$cmd" "$src"/ "$dst"/ | t_match_n "$1" '
151 copy t.png
152 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
154 t_find "$dst" "$1: dst has t.png" '
155 .ssg.dst
156 .ssg.src
157 t.png
159 cat "$dst/.ssg.dst" | t_match_n "$1: .ssg.dst" '
160 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b t.png
162 ;;
164 select_src_files_no_dst)
165 mkdir "$src" && echo >"$src/t.png"
166 "$cmd" "$src" "$dst" | t_match_n "$1" '
167 copy t.png
168 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
170 t_find "$dst" "$1: dst has t.png" '
171 .ssg.dst
172 .ssg.src
173 t.png
175 ;;
177 select_src_files_no_ssg_dst_ssg_src)
178 mkdir "$src" "$dst" && echo >"$src/t.png"
179 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
180 copy t.png
181 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
183 rm "$dst/.ssg.src"
184 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
185 copy t.png
186 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
188 rm "$dst/.ssg.dst"
189 "$cmd" "$src" "$dst" | t_match_n "$1: third run" '
190 copy t.png
191 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
193 ;;
195 select_src_files_no_dst_ssg_dst_match)
196 mkdir "$src" "$dst" && echo >"$src/t.png"
197 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
198 copy t.png
199 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
201 echo x >>"$dst/.ssg.dst"
202 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
203 copy t.png
204 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
206 ;;
208 select_src_files_no_src_diff)
209 mkdir "$src" "$dst" && echo >"$src/t.png"
210 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
211 copy t.png
212 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
214 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
215 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
217 ;;
219 select_src_files_clean_dst)
220 mkdir "$src" && echo >"$src/t.png"
221 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
222 copy t.png
223 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
225 echo >"$dst/trash_file"
226 mkdir "$dst/trash_dir"
227 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
228 copy t.png
229 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
231 t_find "$dst" "$1" '
232 .ssg.dst
233 .ssg.src
234 t.png
236 ;;
238 select_src_files_clean_dst_dir)
239 mkdir "$src" "$src/dir"
240 echo >"$src/a.png"
241 echo >"$src/dir/b.png"
242 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
243 copy a.png
244 copy dir/b.png
245 6e0b941542f81e1b299a21444d0efe2fa224a4220e67df9c37cc34a2c6f01b13
247 rm "$src/dir/b.png"
248 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
249 rm dir/b.png
250 rmdir dir/
251 e86615a87eeeae97fb6302dd5013109f0ccfb7336f164a39457e684c30bae90e
253 t_find "$dst" "$1" '
254 .ssg.dst
255 .ssg.src
256 a.png
258 ;;
260 select_updated)
261 mkdir "$src" "$dst"
262 echo '<title></title>' >"$src/.ssg.template"
263 echo '<h1>h1</h1>' >"$src/html1.html"
264 echo '<html>' >"$src/html2.html"
265 echo '# h1' >"$src/markdown.md"
266 echo >"$src/t.png"
267 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
268 template .ssg.template
269 html html1.html, .ssg.template > html1.html
270 html html1.html, .ssg.template > html1.html.gz
271 html html2.html
272 html html2.html > html2.html.gz
273 md markdown.md, .ssg.template > markdown.html
274 md markdown.md, .ssg.template > markdown.html.gz
275 copy t.png
276 sitemap sitemap.xml
277 sitemap sitemap.xml.gz
278 sitemap robots.txt
279 sitemap robots.txt.gz
280 b11930bb5dc6fe0f6e863ec12cfb80a4ee46a292f7021e8619967a0514dc98f9
283 expected_dst='
284 .ssg.dst
285 .ssg.src
286 html1.html
287 html1.html.gz
288 html2.html
289 html2.html.gz
290 markdown.html
291 markdown.html.gz
292 robots.txt
293 robots.txt.gz
294 sitemap.xml
295 sitemap.xml.gz
296 t.png
298 t_find "$dst" "$1" "$expected_dst"
300 echo 'x' >"$src/.ssg.template"
301 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
302 template .ssg.template
303 html html1.html, .ssg.template > html1.html
304 html html1.html, .ssg.template > html1.html.gz
305 md markdown.md, .ssg.template > markdown.html
306 md markdown.md, .ssg.template > markdown.html.gz
307 094260284ae96faf91d950a6c1121fb9940e909c14e34710517b63e01d57a6f9
309 t_find "$dst" "$1" "$expected_dst"
310 ;;
312 generate_copy)
313 mkdir "$src" "$dst" && echo 'png' >"$src/t.png"
314 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
315 copy t.png
316 5265fde36fa46d08d2bc48d0f413d41c166ee966a4f94b5fd7ad0c23e1bb92d4
318 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
319 5265fde36fa46d08d2bc48d0f413d41c166ee966a4f94b5fd7ad0c23e1bb92d4
321 t_find "$dst" "$1" '
322 .ssg.dst
323 .ssg.src
324 t.png
326 cat "$dst/t.png" | t_match "$1" 'png'
327 ;;
329 generate_copy_gz)
330 mkdir "$src" "$dst"
331 echo 'txt' >"$src/t.txt"
332 echo 'pdf' >"$src/p.pdf"
333 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
334 copy p.pdf
335 copy gz t.txt
336 copy gz t.txt > t.txt.gz
337 2a962ce37f2d10996c3a66c9c1bd2e687a796f255b90b062de8ec813d987b12b
339 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
340 2a962ce37f2d10996c3a66c9c1bd2e687a796f255b90b062de8ec813d987b12b
342 t_find "$dst" "$1" '
343 .ssg.dst
344 .ssg.src
345 p.pdf
346 t.txt
347 t.txt.gz
349 cat "$dst/t.txt" | t_match "$1" 'txt'
350 hexdump -C "$dst/t.txt.gz" | t_match_n "$1" '
351 00000000 1f 8b 08 00 00 00 00 00 02 03 2b a9 28 e1 02 00 |..........+.(...|
352 00000010 d3 84 7d 34 04 00 00 00 |..}4....|
353 00000018
355 ;;
357 generate_html)
358 mkdir "$src" "$dst" && echo '<html>' >"$src/h.html"
359 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
360 html h.html
361 html h.html > h.html.gz
362 sitemap sitemap.xml
363 sitemap sitemap.xml.gz
364 sitemap robots.txt
365 sitemap robots.txt.gz
366 8612441a4737f34fcdcc133846c3b98c48f030ce640953f6219b4ca34a378b3f
368 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
369 8612441a4737f34fcdcc133846c3b98c48f030ce640953f6219b4ca34a378b3f
371 t_find "$dst" "$1" '
372 .ssg.dst
373 .ssg.src
374 h.html
375 h.html.gz
376 robots.txt
377 robots.txt.gz
378 sitemap.xml
379 sitemap.xml.gz
381 cat "$dst/h.html" | t_match "$1" '<html>'
382 hexdump -C "$dst/h.html.gz" | t_match_n "$1" '
383 00000000 1f 8b 08 00 00 00 00 00 02 03 b3 c9 28 c9 cd b1 |............(...|
384 00000010 e3 02 00 99 34 cb 33 07 00 00 00 |....4.3....|
385 0000001b
387 ;;
389 generate_sitemap)
390 mkdir "$src" "$dst" && echo '<html>' >"$src/h.html"
391 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
392 html h.html
393 html h.html > h.html.gz
394 sitemap sitemap.xml
395 sitemap sitemap.xml.gz
396 sitemap robots.txt
397 sitemap robots.txt.gz
398 8612441a4737f34fcdcc133846c3b98c48f030ce640953f6219b4ca34a378b3f
400 cat "$dst/sitemap.xml" | t_match_n "$1" '
401 <?xml version="1.0" encoding="UTF-8"?>
402 <urlset
403 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
404 xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
405 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"
406 xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
407 <url><loc>https://src/h.html</loc></url>
408 </urlset>
410 rm "$src/h.html"
412 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
413 rm h.html
414 rm h.html.gz
415 rm robots.txt
416 rm robots.txt.gz
417 rm sitemap.xml
418 rm sitemap.xml.gz
419 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
422 t_find "$dst" "$1" '
423 .ssg.dst
424 .ssg.src
426 ;;
428 generate_sitemap_xml_found_in_src)
429 mkdir "$src" "$dst"
430 echo '<html>' >"$src/h.html"
431 echo >"$src/sitemap.xml"
432 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
433 html h.html
434 html h.html > h.html.gz
435 copy gz sitemap.xml
436 copy gz sitemap.xml > sitemap.xml.gz
437 8ff598b31385c53268c54ff343e33ff60bbf0605d5efcd4f7c5f84a395eaaaa4
439 cat "$dst/sitemap.xml" | t_match "$1" ''
440 ;;
442 generate_sitemap_robots_txt_found_in_src)
443 mkdir "$src" "$dst"
444 echo '<html>' >"$src/h.html"
445 echo >"$src/robots.txt"
446 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
447 html h.html
448 html h.html > h.html.gz
449 copy gz robots.txt
450 copy gz robots.txt > robots.txt.gz
451 sitemap sitemap.xml
452 sitemap sitemap.xml.gz
453 8708dbc61a4641eaec9e0279774ea7a449ac4e00502fbfd388b29b75a2d0b42f
455 cat "$dst/robots.txt" | t_match "$1" ''
456 ;;
458 generate_html_with_template_title)
459 mkdir "$src" "$dst"
460 echo '<h>b<h1 id="h1" >'\''&rarr;<a href=""></a>
461 nl</h1>a
462 <p>a</p></h>' >"$src/h.html"
463 echo '<title>{{title}}</title>' >"$src/.ssg.template"
465 "$cmd" "$src" "$dst" >/dev/null
466 cat "$dst/h.html" | t_match "$1: h.html" "<title>'&rarr; nl</title>"
467 ;;
469 generate_html_with_template)
470 mkdir "$src" "$dst"
471 echo '<h1>x</h1>' >"$src/h.html"
472 echo '<title>{{title}}~{{site}}</title>{{content}}' >"$src/.ssg.template"
474 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
475 template .ssg.template
476 html h.html, .ssg.template > h.html
477 html h.html, .ssg.template > h.html.gz
478 sitemap sitemap.xml
479 sitemap sitemap.xml.gz
480 sitemap robots.txt
481 sitemap robots.txt.gz
482 65db88eacf905753ae5fdc810a53d358eed5bb03fada03ede6da8b19830a35e9
484 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
485 65db88eacf905753ae5fdc810a53d358eed5bb03fada03ede6da8b19830a35e9
487 t_find "$dst" "$1" '
488 .ssg.dst
489 .ssg.src
490 h.html
491 h.html.gz
492 robots.txt
493 robots.txt.gz
494 sitemap.xml
495 sitemap.xml.gz
498 cat "$dst/h.html" | t_match "$1" '<title>x~src</title><h1>x</h1>'
499 hexdump -C "$dst/h.html.gz" | t_match_n "$1" '
500 00000000 1f 8b 08 00 00 00 00 00 02 03 b3 29 c9 2c c9 49 |...........).,.I|
501 00000010 b5 ab a8 2b 2e 4a b6 d1 87 70 6c 32 0c ed 2a 6c |...+.J...pl2..*l|
502 00000020 f4 81 24 17 00 14 10 05 9e 1f 00 00 00 |..$..........|
503 0000002d
505 ;;
507 generate_html_with_template_no_title)
508 mkdir "$src" "$dst"
509 echo '<h1>h1</h1>' >"$src/h.html"
510 echo 'p' >"$src/p.html"
511 echo '<title>{{#title}}{{title}}: {{/title}}{{site}}</title>{{content}}' >"$src/.ssg.template"
513 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
514 template .ssg.template
515 html h.html, .ssg.template > h.html
516 html h.html, .ssg.template > h.html.gz
517 html p.html, .ssg.template > p.html
518 html p.html, .ssg.template > p.html.gz
519 sitemap sitemap.xml
520 sitemap sitemap.xml.gz
521 sitemap robots.txt
522 sitemap robots.txt.gz
523 8b493eed8f65cb60f9b9ebfe2b2414cb646078b3281759a0725246139b2f74da
525 t_find "$dst" "$1" '
526 .ssg.dst
527 .ssg.src
528 h.html
529 h.html.gz
530 p.html
531 p.html.gz
532 robots.txt
533 robots.txt.gz
534 sitemap.xml
535 sitemap.xml.gz
538 cat "$dst/h.html" | t_match "$1" '<title>h1: src</title><h1>h1</h1>'
539 cat "$dst/p.html" | t_match "$1" '<title>src</title>p'
540 ;;
542 generate_html_with_template_in_dir)
543 mkdir "$src" "$src/dir"
544 echo >"$src/h1.html"
545 echo >"$src/dir/h2.html"
546 echo '/' >"$src/.ssg.template"
547 echo '/dir' >"$src/dir/.ssg.template"
549 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
550 template .ssg.template
551 template dir/.ssg.template
552 html dir/h2.html, dir/.ssg.template > dir/h2.html
553 html dir/h2.html, dir/.ssg.template > dir/h2.html.gz
554 html h1.html, .ssg.template > h1.html
555 html h1.html, .ssg.template > h1.html.gz
556 sitemap sitemap.xml
557 sitemap sitemap.xml.gz
558 sitemap robots.txt
559 sitemap robots.txt.gz
560 febf860d03f4581be373e01ca5bfd8d06796170480602d7189b995f17eab45b3
562 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
563 febf860d03f4581be373e01ca5bfd8d06796170480602d7189b995f17eab45b3
565 t_find "$dst" "$1" '
566 .ssg.dst
567 .ssg.src
568 dir/h2.html
569 dir/h2.html.gz
570 h1.html
571 h1.html.gz
572 robots.txt
573 robots.txt.gz
574 sitemap.xml
575 sitemap.xml.gz
578 cat "$dst/h1.html" | t_match "$1" '/'
579 cat "$dst/dir/h2.html" | t_match "$1" '/dir'
580 ;;
582 generate_html_template_not_found)
583 mkdir "$src" "$dst"
584 echo '<h1>h1</h1>' >"$src/h.html"
586 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
587 html h.html
588 html h.html > h.html.gz
589 sitemap sitemap.xml
590 sitemap sitemap.xml.gz
591 sitemap robots.txt
592 sitemap robots.txt.gz
593 b3a4594de39ed2763ffe81abff08c1e39344a38135a19d79919fea4ffd4a4ce9
595 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
596 b3a4594de39ed2763ffe81abff08c1e39344a38135a19d79919fea4ffd4a4ce9
598 t_find "$dst" "$1" '
599 .ssg.dst
600 .ssg.src
601 h.html
602 h.html.gz
603 robots.txt
604 robots.txt.gz
605 sitemap.xml
606 sitemap.xml.gz
609 cat "$dst/h.html" | t_match "$1" '<h1>h1</h1>'
610 hexdump -C "$dst/h.html.gz" | t_match_n "$1" '
611 00000000 1f 8b 08 00 00 00 00 00 02 03 b3 c9 30 b4 cb 30 |............0..0|
612 00000010 b4 d1 07 52 5c 00 12 f0 3b a6 0c 00 00 00 |...R\...;.....|
613 0000001e
615 ;;
617 generate_md_with_collision)
618 mkdir "$src" "$dst"
619 echo >"$src/h.md"
620 echo >"$src/h.html"
622 "$cmd" "$src" "$dst" 2>&1| t_match_n "$1: first run" '
623 html h.html
624 html h.html > h.html.gz
625 fail: h.md collides with h.html
627 ;;
629 generate_md_with_template)
630 mkdir "$src" "$dst"
631 echo '# h1' >"$src/h.md"
632 echo '<title>{{title}}~{{site}}</title>{{content}}' >"$src/.ssg.template"
634 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
635 template .ssg.template
636 md h.md, .ssg.template > h.html
637 md h.md, .ssg.template > h.html.gz
638 sitemap sitemap.xml
639 sitemap sitemap.xml.gz
640 sitemap robots.txt
641 sitemap robots.txt.gz
642 488486c68f55da2c1c922455bae85e5413d17892f74f1d98f798b9709720bbc1
644 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
645 488486c68f55da2c1c922455bae85e5413d17892f74f1d98f798b9709720bbc1
647 t_find "$dst" "$1" '
648 .ssg.dst
649 .ssg.src
650 h.html
651 h.html.gz
652 robots.txt
653 robots.txt.gz
654 sitemap.xml
655 sitemap.xml.gz
658 cat "$dst/h.html" |
659 t_match "$1" '<title>h1~src</title><h1 id="h1">h1</h1>'
660 hexdump -C "$dst/h.html.gz" | t_match_n "$1" '
661 00000000 1f 8b 08 00 00 00 00 00 02 03 b3 29 c9 2c c9 49 |...........).,.I|
662 00000010 b5 cb 30 ac 2b 2e 4a b6 d1 87 f0 6c 32 0c 15 32 |..0.+.J....l2..2|
663 00000020 53 6c 95 32 0c 95 80 32 36 fa 19 86 76 5c 00 0b |Sl.2...26...v\..|
664 00000030 26 40 c1 29 00 00 00 |&@.)...|
665 00000037
667 ;;
669 generate_md_template_not_found)
670 mkdir "$src" "$dst"
671 echo '# h1' >"$src/h.md"
673 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
674 md h.md > h.html
675 md h.md > h.html.gz
676 sitemap sitemap.xml
677 sitemap sitemap.xml.gz
678 sitemap robots.txt
679 sitemap robots.txt.gz
680 6600b89bcccccecb0778b428cd94d0fd544898f64030dab95181e3a173f71d94
682 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
683 6600b89bcccccecb0778b428cd94d0fd544898f64030dab95181e3a173f71d94
685 t_find "$dst" "$1" '
686 .ssg.dst
687 .ssg.src
688 h.html
689 h.html.gz
690 robots.txt
691 robots.txt.gz
692 sitemap.xml
693 sitemap.xml.gz
696 cat "$dst/h.html" | t_match "$1" '<h1 id="h1">h1</h1>'
697 hexdump -C "$dst/h.html.gz" | t_match_n "$1" '
698 00000000 1f 8b 08 00 00 00 00 00 02 03 b3 c9 30 54 c8 4c |............0T.L|
699 00000010 b1 55 ca 30 54 b2 cb 30 b4 d1 cf 30 b4 e3 02 00 |.U.0T..0...0....|
700 00000020 0e 5d 6f 38 14 00 00 00 |.]o8....|
701 00000028
703 ;;
705 generate_sh)
706 mkdir "$src"
707 # shellcheck disable=2016
708 echo '
709 if test -z "$1"; then echo "x.txt" && exit; fi
710 echo . >"$2/x.txt" && echo "x.txt"
711 ' >"$src/.ssg.sh"
713 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
714 sh .ssg.sh > x.txt
715 sh .ssg.sh > x.txt.gz
716 99c418b0dcd6c6c2124e87b4857b415bcf0a12ba7c7540d8ac53fe73c2046a29
718 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
719 99c418b0dcd6c6c2124e87b4857b415bcf0a12ba7c7540d8ac53fe73c2046a29
721 t_find "$dst" "$1" '
722 .ssg.dst
723 .ssg.src
724 x.txt
725 x.txt.gz
728 cat "$dst/x.txt" | t_match "$1" '.'
729 hexdump -C "$dst/x.txt.gz" | t_match_n "$1" '
730 00000000 1f 8b 08 00 00 00 00 00 02 03 d3 e3 02 00 cd f2 |................|
731 00000010 0b aa 02 00 00 00 |......|
732 00000016
734 ;;
736 generate_sh_with_collision)
737 mkdir "$src"
738 echo >"$src/x.txt"
739 # shellcheck disable=2016
740 echo '
741 if test -z "$1"; then echo "x.txt" && exit; fi
742 echo . >"$2/x.txt" && echo "x.txt"
743 ' >"$src/.ssg.sh"
745 "$cmd" "$src" "$dst" 2>&1 | t_match_n "$1: first run" '
746 fail: .ssg.sh collides with x.txt
748 ;;
750 write_hashes)
751 mkdir "$src"
752 echo >"$src/x.txt"
753 # shellcheck disable=2016
754 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
755 copy gz x.txt
756 copy gz x.txt > x.txt.gz
757 a12d7b67f235edb37cfcf1bdd5a50a2e0486e1612eda28210b816eaff424a100
759 cat "$dst/.ssg.src" | t_match_n "$1" '
760 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b x.txt
762 cat "$dst/.ssg.dst" | t_match_n "$1" '
763 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b x.txt
764 34d5848c995803cfd00c2f7f02d807e2069b51ffca60a40f05d2d7229ef13b69 x.txt.gz
766 ;;
768 *) not_ok "$1: not such test" ;;
770 esac
772 ok "$1" && rm -rf "$dir"
775 # tests
777 t fail_no_args
778 t fail_no_src
779 t select_src_files_empty_src
780 t select_src_files_ssg_ignore
781 t select_src_files_trailing_slash
782 t select_src_files_no_dst
783 t select_src_files_no_ssg_dst_ssg_src
784 t select_src_files_no_dst_ssg_dst_match
785 t select_src_files_no_src_diff
786 t select_src_files_clean_dst
787 t select_src_files_clean_dst_dir
788 t select_updated
789 t generate_copy
790 t generate_copy_gz
791 t generate_html
792 t generate_html_with_template
793 t generate_html_with_template_title
794 t generate_html_with_template_no_title
795 t generate_html_with_template_in_dir
796 t generate_html_template_not_found
797 t generate_md_with_collision
798 t generate_md_with_template
799 t generate_md_template_not_found
800 t generate_sh
801 t generate_sh_with_collision
802 t generate_sitemap
803 t generate_sitemap_xml_found_in_src
804 t generate_sitemap_robots_txt_found_in_src
805 t write_hashes
807 basic_case && bench 4 basic_case
809 plan