From: Christian Heller Date: Sat, 19 Nov 2016 22:28:23 +0000 (+0100) Subject: Refactor test script. X-Git-Url: https://plomlompom.com/repos/unset_cookie?a=commitdiff_plain;h=59775c37360985d582d798dc732dae5496a5b58b;p=redo-blog Refactor test script. --- diff --git a/test.sh b/test.sh index 26d4f33..f7d05e8 100755 --- a/test.sh +++ b/test.sh @@ -24,27 +24,38 @@ diff_test() 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 -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}$" -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 -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 -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\}ZIGNOREurn:uuid:[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}urn:uuid:IGNORE