Add a test harness and make compile.sh copy source -> dest for now

This commit is contained in:
Sami Samhuri 2019-12-01 12:13:37 -08:00
parent 03d147b071
commit 03bdab61f2
9 changed files with 51 additions and 22 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
www www
tests/*/actual

View file

@ -1,2 +1,2 @@
exclude = "{$exclude,www,tweets,wayback}" exclude = "{$exclude,www,tweets,wayback,actual}"
include = "{$include,.gitignore}" include = "{$include,.gitignore}"

View file

@ -17,7 +17,7 @@ Execution, trying TDD for the first time:
- [ ] Replace harp with custom Swift code - [ ] 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 - [ ] Port _layout.ejs to Swift code

View file

@ -3,41 +3,42 @@
# bail on errors # bail on errors
set -e set -e
# export PATH="$HOME/.rbenv/shims:$PATH" THIS_DIR=$(dirname "$0")
SOURCE_DIR="$1"
DIR=$(dirname "$0") TARGET_DIR="$2"
# HARP="node_modules/harp/bin/harp"
BLOG_DIR="${1:-${DIR}/..}"
TARGET="${BLOG_DIR%/}/${2:-www}"
function main() { 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 # compile_feeds
# echo "* harp compile $BLOG_DIR $TARGET" # echo "* harp compile $SOURCE_DIR $TARGET_DIR"
# rm -rf "$TARGET/*" "$TARGET/.*" # rm -rf "$TARGET_DIR/*" "$TARGET_DIR/.*"
# "$HARP" compile "$BLOG_DIR" "$TARGET" # "$HARP" compile "$SOURCE_DIR" "$TARGET_DIR"
# clean up temporary feeds # clean up temporary feeds
# rm $BLOG_DIR/public/feed.xml # rm $SOURCE_DIR/public/feed.xml
# rm $BLOG_DIR/public/feed.json # 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 # munge_html
echo "* inline CSS" # echo "* inline CSS"
# ruby -w $DIR/inline-css.rb "$TARGET" # ruby -w $THIS_DIR/inline-css.rb "$TARGET_DIR"
echo "* minify js" # echo "* minify js"
# minify_js # minify_js
} }
function compile_feeds() { function compile_feeds() {
ruby -w $DIR/feeds.rb $BLOG_DIR/public ruby -w $THIS_DIR/feeds.rb $SOURCE_DIR/public
} }
function munge_html() { 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##*/}" FILENAME="${FILE##*/}"
case "$FILENAME" in case "$FILENAME" in
index.html) index.html)
@ -56,8 +57,8 @@ function munge_html() {
} }
# function minify_js() { # function minify_js() {
# for FILE in "$TARGET"/js/*.js; do # for FILE in "$TARGET_DIR"/js/*.js; do
# $DIR/minify-js.sh "$FILE" > /tmp/minified.js && mv /tmp/minified.js "$FILE" || echo "* failed to minify $FILE" # $THIS_DIR/minify-js.sh "$FILE" > /tmp/minified.js && mv /tmp/minified.js "$FILE" || echo "* failed to minify $FILE"
# done # done
# } # }

9
bin/test.sh Executable file
View file

@ -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

View file

@ -0,0 +1,3 @@
<!doctype html>
<html>
</html>

View file

@ -0,0 +1,6 @@
{
"title": "Valar Morghulis",
"author": "A man has no name",
"email": "jaqen@hotmail.com",
"url": "http://example.net"
}

View file

@ -0,0 +1,3 @@
<!doctype html>
<html>
</html>

View file

@ -0,0 +1,6 @@
{
"title": "Valar Morghulis",
"author": "A man has no name",
"email": "jaqen@hotmail.com",
"url": "http://example.net"
}