diff options
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" |
