home · contact · privacy
Refactor test script.
authorChristian Heller <c.heller@plomlompom.de>
Sat, 19 Nov 2016 22:28:23 +0000 (23:28 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Sat, 19 Nov 2016 22:28:23 +0000 (23:28 +0100)
test.sh

diff --git a/test.sh b/test.sh
index 26d4f33782712436b488a9546b313998c8ae2bbf..f7d05e8532c517765c7167f205092489744f3458 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -24,27 +24,38 @@ diff_test()
   fi
 }
 
   fi
 }
 
-rm -rf test/test_dir
-./add_dir.sh test/test_dir
-cp test/test_files/test.md test/test_dir/
-cp test/test_files/foo.rst test/test_dir/
-cp test/test_files/bar\ baz.md test/test_dir/
-cd test/test_dir
+# Set up test directory. 
+expected_files_dir="test/test_files"
+expected_files_dir_escaped="test\\/test_files"
+generated_files_dir="test/test_dir"
+generated_files_dir_escaped="test\\/test_dir"
+rm -rf "$generated_files_dir" 
+./add_dir.sh "$generated_files_dir" 
+working_dir=$(pwd)
+cp "$expected_files_dir"/test.md "$generated_files_dir"/
+cp "$expected_files_dir"/foo.rst "$generated_files_dir"/
+cp "$expected_files_dir"/bar\ baz.md "$generated_files_dir"/
+cd "$generated_files_dir"
 redo
 redo
-cd ../..
+cd "$working_dir" 
+
+# Simple file comparison tests.
 uuid_regex="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
 uuid_regex="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
-for file in test/test_files/*.html test/test_files/*.meta; do
-  cmp_file=`echo "$file" | sed 's/test_files/test_dir/'`
-  if [ ! "$file" = "test/test_files/index.html" ] && \
+uuid_test "$generated_files_dir""/uuid.meta"
+for file in "$expected_files_dir"/*.html "$expected_files_dir"/*.meta; do
+  sed_expression='s/'"$expected_files_dir_escaped"'/'"$generated_files_dir_escaped"'/'
+  cmp_file=`echo "$file" | sed "$sed_expression"`
+  if [ ! "$file" = "$expected_files_dir""/index.html" ] && \
       echo "$file" | grep -q "\.html$"; then
     uuid_test "${cmp_file%.html}.uuid"
   fi
   diff_test "$file" "$cmp_file"
 done
       echo "$file" | grep -q "\.html$"; then
     uuid_test "${cmp_file%.html}.uuid"
   fi
   diff_test "$file" "$cmp_file"
 done
-uuid_test "test/test_dir/uuid.meta"
-original_file="test/test_dir/feed.xml"
+
+# To compare feed.xml, ignore all variable date and uuid strings.
+original_file="$generated_files_dir""/feed.xml"
 generated_file="$original_file".ignoring
 generated_file="$original_file".ignoring
-expected_file="test/test_files/feed.xml.ignoring"
+expected_file="$expected_files_dir""/feed.xml.ignoring"
 cat "$original_file" | \
   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
   sed 's/>urn:uuid:[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}</>urn:uuid:IGNORE</' \
 cat "$original_file" | \
   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
   sed 's/>urn:uuid:[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}</>urn:uuid:IGNORE</' \