diff --git a/.gitignore b/.gitignore index f8d728c..720b0f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ www +tests/*/actual diff --git a/.tm_properties b/.tm_properties index b958751..30bb3fd 100644 --- a/.tm_properties +++ b/.tm_properties @@ -1,2 +1,2 @@ -exclude = "{$exclude,www,tweets,wayback}" +exclude = "{$exclude,www,tweets,wayback,actual}" include = "{$include,.gitignore}" diff --git a/Readme.md b/Readme.md index 6c24180..9a8c106 100644 --- a/Readme.md +++ b/Readme.md @@ -17,7 +17,7 @@ Execution, trying TDD for the first time: - [ ] Replace harp with custom Swift code - - [ ] Write a test harness that renders a site and then checks the output with `diff -r` + - [x] Write a test harness that renders a site and then checks the output with `diff -r` - [ ] Port _layout.ejs to Swift code diff --git a/bin/compile.sh b/bin/compile.sh index cc02182..98e110d 100755 --- a/bin/compile.sh +++ b/bin/compile.sh @@ -3,41 +3,42 @@ # bail on errors set -e -# export PATH="$HOME/.rbenv/shims:$PATH" - -DIR=$(dirname "$0") -# HARP="node_modules/harp/bin/harp" -BLOG_DIR="${1:-${DIR}/..}" -TARGET="${BLOG_DIR%/}/${2:-www}" +THIS_DIR=$(dirname "$0") +SOURCE_DIR="$1" +TARGET_DIR="$2" function main() { - echo "* compile rss feed" + echo "* copy files from $SOURCE_DIR to $TARGET_DIR" + mkdir -p "$TARGET_DIR" + cp -rp "$SOURCE_DIR"/* "$TARGET_DIR" + + # echo "* compile rss feed" # compile_feeds - # echo "* harp compile $BLOG_DIR $TARGET" - # rm -rf "$TARGET/*" "$TARGET/.*" - # "$HARP" compile "$BLOG_DIR" "$TARGET" + # echo "* harp compile $SOURCE_DIR $TARGET_DIR" + # rm -rf "$TARGET_DIR/*" "$TARGET_DIR/.*" + # "$HARP" compile "$SOURCE_DIR" "$TARGET_DIR" # clean up temporary feeds - # rm $BLOG_DIR/public/feed.xml - # rm $BLOG_DIR/public/feed.json + # rm $SOURCE_DIR/public/feed.xml + # rm $SOURCE_DIR/public/feed.json - echo "* munge html files to make them available without an extension" + # echo "* munge html files to make them available without an extension" # munge_html - echo "* inline CSS" - # ruby -w $DIR/inline-css.rb "$TARGET" + # echo "* inline CSS" + # ruby -w $THIS_DIR/inline-css.rb "$TARGET_DIR" - echo "* minify js" + # echo "* minify js" # minify_js } function compile_feeds() { - ruby -w $DIR/feeds.rb $BLOG_DIR/public + ruby -w $THIS_DIR/feeds.rb $SOURCE_DIR/public } function munge_html() { - for FILE in "$TARGET"/*.html "$TARGET"/posts/*/*/*.html "$TARGET"/posts/drafts/*.html "$TARGET"/projects/*.html; do + for FILE in "$TARGET_DIR"/*.html "$TARGET_DIR"/posts/*/*/*.html "$TARGET_DIR"/posts/drafts/*.html "$TARGET_DIR"/projects/*.html; do FILENAME="${FILE##*/}" case "$FILENAME" in index.html) @@ -56,8 +57,8 @@ function munge_html() { } # function minify_js() { -# for FILE in "$TARGET"/js/*.js; do -# $DIR/minify-js.sh "$FILE" > /tmp/minified.js && mv /tmp/minified.js "$FILE" || echo "* failed to minify $FILE" +# for FILE in "$TARGET_DIR"/js/*.js; do +# $THIS_DIR/minify-js.sh "$FILE" > /tmp/minified.js && mv /tmp/minified.js "$FILE" || echo "* failed to minify $FILE" # done # } diff --git a/bin/test.sh b/bin/test.sh new file mode 100755 index 0000000..e06af7c --- /dev/null +++ b/bin/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +for site in Tests/test-*; do + bin/compile.sh "$site/in" "$site/actual" >/dev/null + diff -r "$site/expected" "$site/actual" + rm -r "$site/actual" +done diff --git a/tests/test-index/expected/index.html b/tests/test-index/expected/index.html new file mode 100644 index 0000000..825c61e --- /dev/null +++ b/tests/test-index/expected/index.html @@ -0,0 +1,3 @@ + + + diff --git a/tests/test-index/expected/site.json b/tests/test-index/expected/site.json new file mode 100644 index 0000000..473e83e --- /dev/null +++ b/tests/test-index/expected/site.json @@ -0,0 +1,6 @@ +{ + "title": "Valar Morghulis", + "author": "A man has no name", + "email": "jaqen@hotmail.com", + "url": "http://example.net" +} diff --git a/tests/test-index/in/index.html b/tests/test-index/in/index.html new file mode 100644 index 0000000..825c61e --- /dev/null +++ b/tests/test-index/in/index.html @@ -0,0 +1,3 @@ + + + diff --git a/tests/test-index/in/site.json b/tests/test-index/in/site.json new file mode 100644 index 0000000..473e83e --- /dev/null +++ b/tests/test-index/in/site.json @@ -0,0 +1,6 @@ +{ + "title": "Valar Morghulis", + "author": "A man has no name", + "email": "jaqen@hotmail.com", + "url": "http://example.net" +}