summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/integration.sh94
-rw-r--r--tests/resources/expected/hello.html.0.txt4
-rw-r--r--tests/resources/expected/hello.html.1.txt1
-rw-r--r--tests/resources/expected/hello.htmlbody54
-rw-r--r--tests/resources/expected/hello.links2
-rw-r--r--tests/resources/expected/hello.snippets2
-rw-r--r--tests/resources/expected/src/content/en/blog/2024-01-15-launch.sortdata1
-rw-r--r--tests/resources/expected/src/content/en/blog/2025-03-20-feature.sortdata1
-rw-r--r--tests/resources/expected/src/content/en/news/2024-06-01-founding.sortdata1
-rw-r--r--tests/resources/expected/src/content/en/news/2025-06-01-anniversary.sortdata1
-rw-r--r--tests/resources/site/src/content/en/blog/2024/01/15/launch.adoc4
-rw-r--r--tests/resources/site/src/content/en/blog/2024/01/15/launch.conf2
-rw-r--r--tests/resources/site/src/content/en/blog/2025/03/20/feature.adoc4
-rw-r--r--tests/resources/site/src/content/en/blog/2025/03/20/feature.conf2
-rw-r--r--tests/resources/site/src/content/en/news/2024/06/01/founding.adoc4
-rw-r--r--tests/resources/site/src/content/en/news/2024/06/01/founding.conf2
-rw-r--r--tests/resources/site/src/content/en/news/2025/06/01/anniversary.adoc4
-rw-r--r--tests/resources/site/src/content/en/news/2025/06/01/anniversary.conf2
-rw-r--r--tests/resources/site/src/content/hello.adoc25
19 files changed, 210 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"
diff --git a/tests/resources/expected/hello.html.0.txt b/tests/resources/expected/hello.html.0.txt
new file mode 100644
index 0000000..3307d1d
--- /dev/null
+++ b/tests/resources/expected/hello.html.0.txt
@@ -0,0 +1,4 @@
+{
+ "key": "value",
+ "n": 42
+}
diff --git a/tests/resources/expected/hello.html.1.txt b/tests/resources/expected/hello.html.1.txt
new file mode 100644
index 0000000..3b18e51
--- /dev/null
+++ b/tests/resources/expected/hello.html.1.txt
@@ -0,0 +1 @@
+hello world
diff --git a/tests/resources/expected/hello.htmlbody b/tests/resources/expected/hello.htmlbody
new file mode 100644
index 0000000..34badfb
--- /dev/null
+++ b/tests/resources/expected/hello.htmlbody
@@ -0,0 +1,54 @@
+ <div id="preamble">
+ <div class="sectionbody">
+ <div class="paragraph">
+ <p>A minimal asciidoc page used by mkwb’s integration test.</p>
+ </div>
+ </div>
+ </div>
+ <div class="sect1">
+ <h2 id="section">Section<a class="anchor"
+ href="#section"></a></h2>
+ <div class="sectionbody">
+ <div class="ulist">
+ <ul>
+ <li>
+ <p>item one</p>
+ </li>
+ <li>
+ <p>item two</p>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </div>
+ <div class="sect1">
+ <h2 id="snippet">Snippet<a class="anchor"
+ href="#snippet"></a></h2>
+ <div class="sectionbody">
+ <div class="listingblock">
+ <div class="content">
+ <pre>{
+ "key": "value",
+ "n": 42
+}</pre>
+ </div>
+ </div>
+ <div class="paragraph plaintext">
+ <p><a href="hello.html.0.txt">plaintext</a></p>
+ </div>
+ </div>
+ </div>
+ <div class="sect1">
+ <h2 id="another-snippet">Another snippet<a class="anchor"
+ href="#another-snippet"></a></h2>
+ <div class="sectionbody">
+ <div class="listingblock">
+ <div class="content">
+ <pre>hello world</pre>
+ </div>
+ </div>
+ <div class="paragraph plaintext">
+ <p><a href="hello.html.1.txt">plaintext</a></p>
+ </div>
+ </div>
+ </div>
diff --git a/tests/resources/expected/hello.links b/tests/resources/expected/hello.links
new file mode 100644
index 0000000..222889b
--- /dev/null
+++ b/tests/resources/expected/hello.links
@@ -0,0 +1,2 @@
+https://example.com/docs
+https://www.rfc-editor.org/rfc/rfc7230
diff --git a/tests/resources/expected/hello.snippets b/tests/resources/expected/hello.snippets
new file mode 100644
index 0000000..87c2af9
--- /dev/null
+++ b/tests/resources/expected/hello.snippets
@@ -0,0 +1,2 @@
+hello.html.0.txt
+hello.html.1.txt
diff --git a/tests/resources/expected/src/content/en/blog/2024-01-15-launch.sortdata b/tests/resources/expected/src/content/en/blog/2024-01-15-launch.sortdata
new file mode 100644
index 0000000..39e52c0
--- /dev/null
+++ b/tests/resources/expected/src/content/en/blog/2024-01-15-launch.sortdata
@@ -0,0 +1 @@
+src/content/en/blog/2024/01/15/launch.sortdata
diff --git a/tests/resources/expected/src/content/en/blog/2025-03-20-feature.sortdata b/tests/resources/expected/src/content/en/blog/2025-03-20-feature.sortdata
new file mode 100644
index 0000000..e8a1011
--- /dev/null
+++ b/tests/resources/expected/src/content/en/blog/2025-03-20-feature.sortdata
@@ -0,0 +1 @@
+src/content/en/blog/2025/03/20/feature.sortdata
diff --git a/tests/resources/expected/src/content/en/news/2024-06-01-founding.sortdata b/tests/resources/expected/src/content/en/news/2024-06-01-founding.sortdata
new file mode 100644
index 0000000..72d71a6
--- /dev/null
+++ b/tests/resources/expected/src/content/en/news/2024-06-01-founding.sortdata
@@ -0,0 +1 @@
+src/content/en/news/2024/06/01/founding.sortdata
diff --git a/tests/resources/expected/src/content/en/news/2025-06-01-anniversary.sortdata b/tests/resources/expected/src/content/en/news/2025-06-01-anniversary.sortdata
new file mode 100644
index 0000000..185cf9b
--- /dev/null
+++ b/tests/resources/expected/src/content/en/news/2025-06-01-anniversary.sortdata
@@ -0,0 +1 @@
+src/content/en/news/2025/06/01/anniversary.sortdata
diff --git a/tests/resources/site/src/content/en/blog/2024/01/15/launch.adoc b/tests/resources/site/src/content/en/blog/2024/01/15/launch.adoc
new file mode 100644
index 0000000..9360a9d
--- /dev/null
+++ b/tests/resources/site/src/content/en/blog/2024/01/15/launch.adoc
@@ -0,0 +1,4 @@
+= Launch
+:updatedat: 2024-01-15
+
+We launched.
diff --git a/tests/resources/site/src/content/en/blog/2024/01/15/launch.conf b/tests/resources/site/src/content/en/blog/2024/01/15/launch.conf
new file mode 100644
index 0000000..70163d5
--- /dev/null
+++ b/tests/resources/site/src/content/en/blog/2024/01/15/launch.conf
@@ -0,0 +1,2 @@
+date_iso=2024-01-15
+sort=launch
diff --git a/tests/resources/site/src/content/en/blog/2025/03/20/feature.adoc b/tests/resources/site/src/content/en/blog/2025/03/20/feature.adoc
new file mode 100644
index 0000000..681656f
--- /dev/null
+++ b/tests/resources/site/src/content/en/blog/2025/03/20/feature.adoc
@@ -0,0 +1,4 @@
+= Feature
+:updatedat: 2025-03-20
+
+We shipped a feature.
diff --git a/tests/resources/site/src/content/en/blog/2025/03/20/feature.conf b/tests/resources/site/src/content/en/blog/2025/03/20/feature.conf
new file mode 100644
index 0000000..aead7c2
--- /dev/null
+++ b/tests/resources/site/src/content/en/blog/2025/03/20/feature.conf
@@ -0,0 +1,2 @@
+date_iso=2025-03-20
+sort=feature
diff --git a/tests/resources/site/src/content/en/news/2024/06/01/founding.adoc b/tests/resources/site/src/content/en/news/2024/06/01/founding.adoc
new file mode 100644
index 0000000..ab650b8
--- /dev/null
+++ b/tests/resources/site/src/content/en/news/2024/06/01/founding.adoc
@@ -0,0 +1,4 @@
+= Founding
+:updatedat: 2024-06-01
+
+Org founded.
diff --git a/tests/resources/site/src/content/en/news/2024/06/01/founding.conf b/tests/resources/site/src/content/en/news/2024/06/01/founding.conf
new file mode 100644
index 0000000..8504263
--- /dev/null
+++ b/tests/resources/site/src/content/en/news/2024/06/01/founding.conf
@@ -0,0 +1,2 @@
+date_iso=2024-06-01
+sort=founding
diff --git a/tests/resources/site/src/content/en/news/2025/06/01/anniversary.adoc b/tests/resources/site/src/content/en/news/2025/06/01/anniversary.adoc
new file mode 100644
index 0000000..de32ee0
--- /dev/null
+++ b/tests/resources/site/src/content/en/news/2025/06/01/anniversary.adoc
@@ -0,0 +1,4 @@
+= Anniversary
+:updatedat: 2025-06-01
+
+One year in.
diff --git a/tests/resources/site/src/content/en/news/2025/06/01/anniversary.conf b/tests/resources/site/src/content/en/news/2025/06/01/anniversary.conf
new file mode 100644
index 0000000..01e24d9
--- /dev/null
+++ b/tests/resources/site/src/content/en/news/2025/06/01/anniversary.conf
@@ -0,0 +1,2 @@
+date_iso=2025-06-01
+sort=anniversary
diff --git a/tests/resources/site/src/content/hello.adoc b/tests/resources/site/src/content/hello.adoc
new file mode 100644
index 0000000..ef6ac5b
--- /dev/null
+++ b/tests/resources/site/src/content/hello.adoc
@@ -0,0 +1,25 @@
+= Hello
+:upstream-docs: https://example.com/docs
+:rfc-link: https://www.rfc-editor.org/rfc/rfc7230
+
+A minimal asciidoc page used by mkwb's integration test.
+
+== Section
+
+* item one
+* item two
+
+== Snippet
+
+----
+{
+ "key": "value",
+ "n": 42
+}
+----
+
+== Another snippet
+
+----
+hello world
+----