🐙 Templated web page generator for your git repositories
git clone https://github.com/m-col/gitja
Files | Refs | Readme | License

Commit cbe90184d7b84718bd299e4f181a47f026400736
Parent: 7228d7efac9be1c4a26a6fbf8ff78ec59194c47c
Author: mcol <mcol@posteo.net>
Date: 2021-11-25 20:29:00 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-25 20:29:00 +0000

setup tests using expected files

test/test.sh Modified

@@ -15,40 +15,43 @@
 
 '
 
+set -u
+
 if [[ $(basename "$PWD") != gitserve ]]
 then
     echo "The test script should be run from the gitserve root project folder."
     exit 1
 fi
 
-rm -rf test/output
-stack run -- -c test/config.dhall
-
-let error=0
+let errors="0"
+EXPECTED="test/expected"
+RESULT="test/result"
 
-error() {
-    echo Failed: $1
-    echo Expected: $2
-    echo But got: $3
+declare -a TESTS
+TESTS=(
+    "gitserve/commit/0292014748caae952bbc8dd6225680d83c0a5135.html"
+    "gitserve/file/test.templates.style.css.html"
+)
 
-    let error+=1
-}
-
-commit_file="test/output/gitserve/commit/0292014748caae952bbc8dd6225680d83c0a5135.html"
-commit_result="$(cat $commit_file)"
-commit_expected="0292014748caae952bbc8dd6225680d83c0a5135"
+rm -rf "$RESULT"
+stack run -- -c test/config.dhall
 
-[[ "$commit_result" != "$commit_expected" ]] || {
-    error "$commit_file" "$commit_expected" "$commit_result"
-}
+for test in "${TESTS[@]}"
+do
+    diff --text --strip-trailing-cr --ignore-trailing-space \
+	"$EXPECTED/$test" "$RESULT/$test" || {
+	    let errors+=1
+	    echo "^ ERRORED ON: $test"
+	}
+done
 
-case "$error" in
+case "$errors" in
     0)
 	echo "All good!"
 	exit 0
 	;;
     *)
-	echo "Had this many errors: $error"
-	exit $error
+	echo "Had this many errors: $errors"
+	exit $errors
 	;;
 esac

test/expected/gitserve/file/test.templates.style.css.html Added

@@ -0,0 +1 @@
+test/templates/style.css
\ No newline at end of file

test/expected/gitserve/commit/0292014748caae952bbc8dd6225680d83c0a5135.html Added

@@ -0,0 +1 @@
+0292014748caae952bbc8dd6225680d83c0a5135

test/config.dhall Modified

@@ -1,7 +1,7 @@
 let config =
     { repoPaths = ["."]
     , templateDirectory = "./test/templates"
-    , outputDirectory = "./test/output"
+    , outputDirectory = "./test/result"
     , host = "https://github.com/m-col/gitserve"
     }
 

.gitignore Modified

@@ -1,5 +1,5 @@
 .stack-work/
 *~
 output
-test/output
+test/result
 dist-newstyle