From 5a17d0898d72bc8574601f57f26af8d3e0da2288 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Sat, 19 Nov 2016 22:01:58 +0100
Subject: [PATCH] Rename generated meta files, test for them.

---
 processor/{author.do => author.meta.do} |  0
 processor/default.html.do               |  5 +++--
 processor/feed.xml.do                   | 28 ++++++++++++++-----------
 processor/index.html.do                 |  5 +++--
 processor/{title.do => title.meta.do}   |  0
 processor/{url.do => url.meta.do}       |  0
 processor/{uuid.do => uuid.meta.do}     |  0
 test.sh                                 | 15 +++++++++++++
 test/test_files/author.meta             |  1 +
 test/test_files/title.meta              |  1 +
 test/test_files/url.meta                |  1 +
 test/test_files/uuid.meta               |  1 +
 12 files changed, 41 insertions(+), 16 deletions(-)
 rename processor/{author.do => author.meta.do} (100%)
 rename processor/{title.do => title.meta.do} (100%)
 rename processor/{url.do => url.meta.do} (100%)
 rename processor/{uuid.do => uuid.meta.do} (100%)
 create mode 100644 test/test_files/author.meta
 create mode 100644 test/test_files/title.meta
 create mode 100644 test/test_files/url.meta
 create mode 100644 test/test_files/uuid.meta

diff --git a/processor/author.do b/processor/author.meta.do
similarity index 100%
rename from processor/author.do
rename to processor/author.meta.do
diff --git a/processor/default.html.do b/processor/default.html.do
index 3ff4132..2a457a5 100644
--- a/processor/default.html.do
+++ b/processor/default.html.do
@@ -3,11 +3,12 @@
 # Pull in global dependencies.
 . ./helpers.sh
 intermediate_file="${1%.html}.intermediate"
-redo-ifchange title
+title_file=title.meta
+redo-ifchange "$title_file" 
 redo-ifchange "$intermediate_file"
 
 # Build entry data.
-blog_title=`read_and_escape_file title | head -1`
+blog_title=`read_and_escape_file "$title_file" | head -1`
 title_html=`cat "$intermediate_file" | head -1`
 title_plaintext=`echo "$title_html" | html2text`
 title_plaintext_escaped=`escape_html "$title_plaintext"`
diff --git a/processor/feed.xml.do b/processor/feed.xml.do
index 2cdb7b2..14ead59 100644
--- a/processor/feed.xml.do
+++ b/processor/feed.xml.do
@@ -2,21 +2,25 @@
 
 # Pull in global dependencies.
 . ./helpers.sh
-redo-ifchange url
-redo-ifchange author
-redo-ifchange uuid
-redo-ifchange title 
+url_file=url.meta
+author_file=author.meta
+uuid_file=uuid.meta
+title_file=title.meta
+redo-ifchange "$url_file"
+redo-ifchange "$author_file"
+redo-ifchange "$uuid_file"
+redo-ifchange "$title_file"
 
 # Build some variables. XML-escape even file contents that should not contain
 # dangerous characters, just to avoid any XML trouble.
-base_url=`cat url | head -1`
+base_url=`cat "$url_file" | head -1`
 url_protocol=`echo $base_url | cut -d ':' -f 1`
 url_basepath=`echo $base_url | cut -d '/' -f 3-`
 url_basepath_escaped=`escape_url "$url_basepath"`
 basepath="$url_protocol""://""$url_basepath_escaped"
-title=`read_and_escape_file title | head -1`
-author=`read_and_escape_file author | head -1`
-uuid=`read_and_escape_file uuid | head -1`
+title=`read_and_escape_file "$title_file" | head -1`
+author=`read_and_escape_file "$author_file" | head -1`
+uuid=`read_and_escape_file "$uuid_file" | head -1`
 
 # Write majority of feed head.
 cat << EOF
@@ -47,13 +51,13 @@ for file in $files; do
   # Build some variables and dependencies.
   intermediate_file="${file%.*}.intermediate"
   htmlfile=`escape_url "${file%.*}.html"`
+  uuid_file="${file%.*}.uuid"
   redo-ifchange "$intermediate_file"
-  redo-ifchange "$uuidfile"
+  redo-ifchange "$uuid_file"
   title=`read_and_escape_file "$intermediate_file" | head -1`
-  uuidfile="${file%.*}.uuid"
-  uuid=`read_and_escape_file "$uuidfile" | head -1`
+  uuid=`read_and_escape_file "$uuid_file" | head -1`
   body=`read_and_escape_file "$intermediate_file" | sed 1d`
-  published=`stat -c%y "$uuidfile"`
+  published=`stat -c%y "$uuid_file"`
   published_rfc3339=`date -u "+%Y-%m-%dT%TZ" -d "$published"`
 
   # Write entry.
diff --git a/processor/index.html.do b/processor/index.html.do
index 8bf6751..2b71ffb 100644
--- a/processor/index.html.do
+++ b/processor/index.html.do
@@ -2,7 +2,8 @@
 
 # Pull in global dependencies.
 . ./helpers.sh
-redo-ifchange title
+title_file=title.meta
+redo-ifchange "$title_file"
 
 # Write index head.
 cat << EOF
@@ -10,7 +11,7 @@ cat << EOF
 <html>
 <head>
 EOF
-blog_title=`read_and_escape_file title | head -1`
+blog_title=`read_and_escape_file "$title_file" | head -1`
 printf "<title>%s</title>\n</head>\n<body>\n" "$blog_title"
 printf "<h1>%s</h1>\n<ul>\n" "$blog_title"
 
diff --git a/processor/title.do b/processor/title.meta.do
similarity index 100%
rename from processor/title.do
rename to processor/title.meta.do
diff --git a/processor/url.do b/processor/url.meta.do
similarity index 100%
rename from processor/url.do
rename to processor/url.meta.do
diff --git a/processor/uuid.do b/processor/uuid.meta.do
similarity index 100%
rename from processor/uuid.do
rename to processor/uuid.meta.do
diff --git a/test.sh b/test.sh
index 97d0fbf..4daff6b 100755
--- a/test.sh
+++ b/test.sh
@@ -18,3 +18,18 @@ for file in test/test_files/*.html; do
     echo "== test FAILURE =="
   fi
 done
+for file in test/test_files/*meta; do
+  if [ "$file" = "test/test_files/uuid.meta" ]; then
+    true
+    # TODO: validate UUID
+  else
+    cmp_file=`echo "$file" | sed 's/test_files/test_dir/'`
+    printf "== %s diff test ==\n" "$cmp_file"
+    diff "$file" "$cmp_file"
+    if [ "$?" = "0" ]; then
+      echo "== test SUCCESS =="
+    else
+      echo "== test FAILURE =="
+    fi
+  fi
+done
diff --git a/test/test_files/author.meta b/test/test_files/author.meta
new file mode 100644
index 0000000..5f36248
--- /dev/null
+++ b/test/test_files/author.meta
@@ -0,0 +1 @@
+Joe Sixpack
\ No newline at end of file
diff --git a/test/test_files/title.meta b/test/test_files/title.meta
new file mode 100644
index 0000000..4d35b7e
--- /dev/null
+++ b/test/test_files/title.meta
@@ -0,0 +1 @@
+Yet another blog
\ No newline at end of file
diff --git a/test/test_files/url.meta b/test/test_files/url.meta
new file mode 100644
index 0000000..673d303
--- /dev/null
+++ b/test/test_files/url.meta
@@ -0,0 +1 @@
+http://example.org/
\ No newline at end of file
diff --git a/test/test_files/uuid.meta b/test/test_files/uuid.meta
new file mode 100644
index 0000000..09e4abd
--- /dev/null
+++ b/test/test_files/uuid.meta
@@ -0,0 +1 @@
+438b364d-e7e9-4225-952e-1e9ae312026f
-- 
2.30.2