7 echo "$ok_expected..$ok_count"
8 test "$ok_expected" -eq "$ok_count" || { echo 'failed' && exit 1; }
9 echo 'passed' && exit 0
18 while [ "$n" -le "$i" ]; do
19 "$@" >/dev/null 2>&1 && n=$((n + 1))
24 } 2>&1 | grep 'real' | cut -f2 | cut -d' ' -f5
28 ok() { echo "ok: $*" && ok_count=$((ok_count + 1)); }
29 not_ok() { echo "not ok: $*" && plan; }
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"
40 fifo=$(mktemp -u) || exit 1
41 mkfifo "$fifo" || exit 1
42 (echo "$2" >"$fifo") &
43 diff - "$fifo" || not_ok "$1"
48 find "$1" -type f | sort | sed "s,$1/,," | t_match_n "$2" "$3"
53 test -x "$cmd" || { echo "$cmd not found" >&2 && exit 1; }
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"
67 # shellcheck disable=2016
69 if test -z "$1"; then echo "x.txt" && exit; fi
70 echo . >"$2/x.txt" && echo "x.txt"
72 "$cmd" "$src" "$dst" | t_match_n "basic_case" '
76 template .ssg.template
77 html html1.html, .ssg.template > html1.html
78 html html1.html, .ssg.template > html1.html.gz
80 html html2.html > html2.html.gz
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
87 sitemap sitemap.xml.gz
90 e601a42390b8c734a818abc9b7406ea6a52a12c912a37b7464eb17df27d6d0e0
96 dir=$(mktemp -d) && src="$dir/src" && dst="$dir/dst"
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"
104 test -d "$dst" && not_ok "$1"
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"
112 test -d "$dst" && not_ok "$1"
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" '
125 select_src_files_ssg_ignore)
126 mkdir "$src" "$src/a" "$src/a/b" "$src/a/c"
127 echo '1.txt' >"$src/.ssg.ignore"
129 c/' >"$src/a/.ssg.ignore"
130 echo '3.txt' >"$src/a/b/.ssg.ignore"
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" '
139 ignore a/b/.ssg.ignore
140 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
148 select_src_files_trailing_slash)
149 mkdir "$src" && echo >"$src/t.png"
150 "$cmd" "$src"/ "$dst"/ | t_match_n "$1" '
152 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
154 t_find "$dst" "$1: dst has t.png" '
159 cat "$dst/.ssg.dst" | t_match_n "$1: .ssg.dst" '
160 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b t.png
164 select_src_files_no_dst)
165 mkdir "$src" && echo >"$src/t.png"
166 "$cmd" "$src" "$dst" | t_match_n "$1" '
168 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
170 t_find "$dst" "$1: dst has t.png" '
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" '
181 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
184 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
186 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
189 "$cmd" "$src" "$dst" | t_match_n "$1: third run" '
191 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
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" '
199 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
201 echo x >>"$dst/.ssg.dst"
202 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
204 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
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" '
212 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
214 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
215 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
219 select_src_files_clean_dst)
220 mkdir "$src" && echo >"$src/t.png"
221 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
223 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
225 echo >"$dst/trash_file"
226 mkdir "$dst/trash_dir"
227 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
229 9db7b136bc6fdd9c51009ce2f88c69ff64060c3f3ff540a9199f37d2aa404eaa
238 select_src_files_clean_dst_dir)
239 mkdir "$src" "$src/dir"
241 echo >"$src/dir/b.png"
242 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
245 6e0b941542f81e1b299a21444d0efe2fa224a4220e67df9c37cc34a2c6f01b13
248 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
251 e86615a87eeeae97fb6302dd5013109f0ccfb7336f164a39457e684c30bae90e
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"
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
272 html html2.html > html2.html.gz
273 md markdown.md, .ssg.template > markdown.html
274 md markdown.md, .ssg.template > markdown.html.gz
277 sitemap sitemap.xml.gz
279 sitemap robots.txt.gz
280 b11930bb5dc6fe0f6e863ec12cfb80a4ee46a292f7021e8619967a0514dc98f9
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"
313 mkdir "$src" "$dst" && echo 'png' >"$src/t.png"
314 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
316 5265fde36fa46d08d2bc48d0f413d41c166ee966a4f94b5fd7ad0c23e1bb92d4
318 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
319 5265fde36fa46d08d2bc48d0f413d41c166ee966a4f94b5fd7ad0c23e1bb92d4
326 cat "$dst/t.png" | t_match "$1" 'png'
331 echo 'txt' >"$src/t.txt"
332 echo 'pdf' >"$src/p.pdf"
333 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
336 copy gz t.txt > t.txt.gz
337 2a962ce37f2d10996c3a66c9c1bd2e687a796f255b90b062de8ec813d987b12b
339 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
340 2a962ce37f2d10996c3a66c9c1bd2e687a796f255b90b062de8ec813d987b12b
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....|
358 mkdir "$src" "$dst" && echo '<html>' >"$src/h.html"
359 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
361 html h.html > h.html.gz
363 sitemap sitemap.xml.gz
365 sitemap robots.txt.gz
366 8612441a4737f34fcdcc133846c3b98c48f030ce640953f6219b4ca34a378b3f
368 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
369 8612441a4737f34fcdcc133846c3b98c48f030ce640953f6219b4ca34a378b3f
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....|
390 mkdir "$src" "$dst" && echo '<html>' >"$src/h.html"
391 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
393 html h.html > h.html.gz
395 sitemap sitemap.xml.gz
397 sitemap robots.txt.gz
398 8612441a4737f34fcdcc133846c3b98c48f030ce640953f6219b4ca34a378b3f
400 cat "$dst/sitemap.xml" | t_match_n "$1" '
401 <?xml version="1.0" encoding="UTF-8"?>
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>
412 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
419 01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b
428 generate_sitemap_xml_found_in_src)
430 echo '<html>' >"$src/h.html"
431 echo >"$src/sitemap.xml"
432 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
434 html h.html > h.html.gz
436 copy gz sitemap.xml > sitemap.xml.gz
437 8ff598b31385c53268c54ff343e33ff60bbf0605d5efcd4f7c5f84a395eaaaa4
439 cat "$dst/sitemap.xml" | t_match "$1" ''
442 generate_sitemap_robots_txt_found_in_src)
444 echo '<html>' >"$src/h.html"
445 echo >"$src/robots.txt"
446 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
448 html h.html > h.html.gz
450 copy gz robots.txt > robots.txt.gz
452 sitemap sitemap.xml.gz
453 8708dbc61a4641eaec9e0279774ea7a449ac4e00502fbfd388b29b75a2d0b42f
455 cat "$dst/robots.txt" | t_match "$1" ''
458 generate_html_with_template_title)
460 echo '<h>b<h1 id="h1" >'\''→<a href=""></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>'→ nl</title>"
469 generate_html_with_template)
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
479 sitemap sitemap.xml.gz
481 sitemap robots.txt.gz
482 65db88eacf905753ae5fdc810a53d358eed5bb03fada03ede6da8b19830a35e9
484 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
485 65db88eacf905753ae5fdc810a53d358eed5bb03fada03ede6da8b19830a35e9
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 |..$..........|
507 generate_html_with_template_no_title)
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
520 sitemap sitemap.xml.gz
522 sitemap robots.txt.gz
523 8b493eed8f65cb60f9b9ebfe2b2414cb646078b3281759a0725246139b2f74da
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'
542 generate_html_with_template_in_dir)
543 mkdir "$src" "$src/dir"
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
557 sitemap sitemap.xml.gz
559 sitemap robots.txt.gz
560 febf860d03f4581be373e01ca5bfd8d06796170480602d7189b995f17eab45b3
562 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
563 febf860d03f4581be373e01ca5bfd8d06796170480602d7189b995f17eab45b3
578 cat "$dst/h1.html" | t_match "$1" '/'
579 cat "$dst/dir/h2.html" | t_match "$1" '/dir'
582 generate_html_template_not_found)
584 echo '<h1>h1</h1>' >"$src/h.html"
586 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
588 html h.html > h.html.gz
590 sitemap sitemap.xml.gz
592 sitemap robots.txt.gz
593 b3a4594de39ed2763ffe81abff08c1e39344a38135a19d79919fea4ffd4a4ce9
595 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
596 b3a4594de39ed2763ffe81abff08c1e39344a38135a19d79919fea4ffd4a4ce9
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\...;.....|
617 generate_md_with_collision)
622 "$cmd" "$src" "$dst" 2>&1| t_match_n "$1: first run" '
624 html h.html > h.html.gz
625 fail: h.md collides with h.html
629 generate_md_with_template)
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
639 sitemap sitemap.xml.gz
641 sitemap robots.txt.gz
642 488486c68f55da2c1c922455bae85e5413d17892f74f1d98f798b9709720bbc1
644 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
645 488486c68f55da2c1c922455bae85e5413d17892f74f1d98f798b9709720bbc1
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 |&@.)...|
669 generate_md_template_not_found)
671 echo '# h1' >"$src/h.md"
673 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
677 sitemap sitemap.xml.gz
679 sitemap robots.txt.gz
680 6600b89bcccccecb0778b428cd94d0fd544898f64030dab95181e3a173f71d94
682 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
683 6600b89bcccccecb0778b428cd94d0fd544898f64030dab95181e3a173f71d94
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....|
707 # shellcheck disable=2016
709 if test -z "$1"; then echo "x.txt" && exit; fi
710 echo . >"$2/x.txt" && echo "x.txt"
713 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
715 sh .ssg.sh > x.txt.gz
716 99c418b0dcd6c6c2124e87b4857b415bcf0a12ba7c7540d8ac53fe73c2046a29
718 "$cmd" "$src" "$dst" | t_match_n "$1: second run" '
719 99c418b0dcd6c6c2124e87b4857b415bcf0a12ba7c7540d8ac53fe73c2046a29
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 |......|
736 generate_sh_with_collision)
739 # shellcheck disable=2016
741 if test -z "$1"; then echo "x.txt" && exit; fi
742 echo . >"$2/x.txt" && echo "x.txt"
745 "$cmd" "$src" "$dst" 2>&1 | t_match_n "$1: first run" '
746 fail: .ssg.sh collides with x.txt
753 # shellcheck disable=2016
754 "$cmd" "$src" "$dst" | t_match_n "$1: first run" '
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
768 *) not_ok "$1: not such test" ;;
772 ok "$1" && rm -rf "$dir"
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
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
801 t generate_sh_with_collision
803 t generate_sitemap_xml_found_in_src
804 t generate_sitemap_robots_txt_found_in_src
807 basic_case && bench 4 basic_case