diff options
| author | EuAndreh <eu@euandre.org> | 2026-05-26 09:43:44 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2026-05-26 09:43:44 -0300 |
| commit | 94bef68330c09ffb052c7bd881e5d9cd7ba04d32 (patch) | |
| tree | 828f718271de83bc6d4fbafe9806ef56c204c924 /tests/integration.sh | |
| parent | meta.capim: Add with :dependencies key (diff) | |
| download | mkwb-94bef68330c09ffb052c7bd881e5d9cd7ba04d32.tar.gz mkwb-94bef68330c09ffb052c7bd881e5d9cd7ba04d32.tar.xz | |
Extract canonical site rules into share/mkwb/site.mk
Sites used to copy-paste ~340 lines of suffix rules, derived-asset
lists, and recipes (global.conf assembly, sitemap, security.txt,
gpg-derived fingerprint/expiry, check-unit-*) into every Makefile.
Move all of it into share/mkwb/site.mk, shipped at install time.
Add src/rules.in -> `mkwb rules`: prints the absolute path of the
shipped site.mk so a site's mkdeps.sh can append it as the last
`include` line of deps.mk. The site's own Makefile then needs
only an `all:` anchor (to keep it as the default target ahead of
deps.mk's first rule) and `include deps.mk`.
Also adds tests/resources/{site,expected}/ and tests/integration.sh
exercising mkwb htmlbody / links / snippets / sortdata against
golden files, with sortdata covering >1 collection and >1 entry
per collection to verify per-collection chronological ordering.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'tests/integration.sh')
| -rwxr-xr-x | tests/integration.sh | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/integration.sh b/tests/integration.sh new file mode 100755 index 0000000..b8b7c1f --- /dev/null +++ b/tests/integration.sh @@ -0,0 +1,94 @@ +#!/bin/sh +# Integration test: drives mkwb against a slim fixture site and +# diffs every output against committed golden files under +# tests/resources/expected/. Run in an isolated tmpdir so the +# snapshot fixture (tests/resources/site/) stays clean. +# +# Required tools on PATH: mkwb (with all libexec scripts) and adoc. +set -eu + +HERE="$(dirname "$(readlink -f "$0")")" +RESOURCES="$HERE/resources" +SITE="$RESOURCES/site" +EXPECTED="$RESOURCES/expected" + +WORK="$(mktemp -d -t mkwb-integration.XXXXXX)" +trap 'rm -rf "$WORK"' EXIT INT TERM + +cp -r "$SITE/." "$WORK/" + +CONTENT="$WORK/src/content" +ACTUAL="$WORK/actual" +mkdir -p "$ACTUAL" + +# --- single-page subcommands ------------------------------------- +# htmlbody: .adoc -> HTML body fragment +mkwb htmlbody "$CONTENT/hello.adoc" > "$ACTUAL/hello.htmlbody" + +# links: extract :attr: link values from the .adoc +mkwb links "$CONTENT/hello.adoc" > "$ACTUAL/hello.links" + +# snippets: emits one .txt per "----" block next to the .adoc, and +# prints the list of filenames to stdout. Run from $CONTENT so the +# filenames are relative. +( cd "$CONTENT" && mkwb snippets hello.adoc ) > "$ACTUAL/hello.snippets" +cp "$CONTENT/hello.html.0.txt" "$ACTUAL/hello.html.0.txt" +cp "$CONTENT/hello.html.1.txt" "$ACTUAL/hello.html.1.txt" + +# --- sortdata: per-collection chronological sort ----------------- +# Each <collection>/YYYY/MM/DD/X.conf gets a sibling sentinel three +# levels up at <collection>/${date_iso}-${sort}.sortdata pointing +# back to the original .sortdata. Sorting these sentinel filenames +# alphabetically yields the chronological order per collection. +for conf in \ + "$CONTENT/en/blog/2024/01/15/launch.conf" \ + "$CONTENT/en/blog/2025/03/20/feature.conf" \ + "$CONTENT/en/news/2024/06/01/founding.conf" \ + "$CONTENT/en/news/2025/06/01/anniversary.conf" \ + ; do + ( cd "$WORK" && mkwb sortdata "${conf#$WORK/}" ) > /dev/null +done + +# --- diff every captured output against goldens ------------------ +fail=0 +diff_one() { + if diff -u "$EXPECTED/$1" "$2"; then + echo "PASS: $1" + else + echo "FAIL: $1 differs from expected" >&2 + fail=1 + fi +} + +for f in hello.htmlbody hello.links hello.snippets \ + hello.html.0.txt hello.html.1.txt; do + diff_one "$f" "$ACTUAL/$f" +done + +# Diff each sentinel file content (points back to .sortdata). +for f in src/content/en/blog/2024-01-15-launch.sortdata \ + src/content/en/blog/2025-03-20-feature.sortdata \ + src/content/en/news/2024-06-01-founding.sortdata \ + src/content/en/news/2025-06-01-anniversary.sortdata; do + diff_one "$f" "$WORK/$f" +done + +# Verify the FILENAME order per collection encodes chronological +# order -- sort all *.sortdata under each collection and check the +# listing matches expected. +for col in blog news; do + want="$(cd "$EXPECTED/src/content/en/$col" && \ + ls *.sortdata 2>/dev/null | sort)" + got="$(cd "$WORK/src/content/en/$col" && \ + ls *.sortdata 2>/dev/null | sort)" + if [ "$want" = "$got" ]; then + echo "PASS: sortdata order in collection '$col'" + else + echo "FAIL: sortdata order in collection '$col'" >&2 + echo " expected:"; echo "$want" | sed 's/^/ /' + echo " actual: "; echo "$got" | sed 's/^/ /' + fail=1 + fi +done + +exit "$fail" |
