home · contact · privacy
Fix index.html generation as well.
[redo-blog] / test.sh
1 #!/bin/sh
2
3 uuid_test()
4 {
5 uuid_file="$1"
6 printf "== %s UUID pattern match test ==\n" "$uuid_file"
7 if cat "$uuid_file" | grep -Eq "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"; then
8   echo "== test SUCCESS =="
9 else
10   echo "== test FAILURE =="
11 fi
12 }
13
14 diff_test()
15 {
16   expected_file="$1"
17   generated_file="$2"
18   printf "== %s diff test ==\n" "$generated_file"
19   diff "$expected_file" "$generated_file"
20   if [ "$?" = "0" ]; then
21     echo "== test SUCCESS =="
22   else
23     echo "== test FAILURE =="
24   fi
25 }
26
27 # Set up test directory. 
28 expected_files_dir="test/test_files"
29 expected_files_dir_escaped="test\\/test_files"
30 generated_files_dir="test/test_dir"
31 generated_files_dir_escaped="test\\/test_dir"
32 rm -rf "$generated_files_dir" 
33 ./add_dir.sh "$generated_files_dir" 
34 working_dir=$(pwd)
35 cd "$generated_files_dir"
36 cp "$working_dir/$expected_files_dir"/test.md .
37 redo
38 cp "$working_dir/$expected_files_dir"/bar\ baz.md .
39 redo
40 cp "$working_dir/$expected_files_dir"/foo.rst .
41 redo
42 cd "$working_dir"
43
44 # Simple file comparison tests and UUID tests.
45 uuid_test "$generated_files_dir""/uuid.meta"
46 for file in "$expected_files_dir"/*.html "$expected_files_dir"/*.meta; do
47   sed_expression='s/'"$expected_files_dir_escaped"'/'"$generated_files_dir_escaped"'/'
48   cmp_file=`echo "$file" | sed "$sed_expression"`
49   if [ ! "$file" = "$expected_files_dir""/index.html" ] && \
50       echo "$file" | grep -q "\.html$"; then
51     uuid_test "${cmp_file%.html}.uuid"
52   fi
53   diff_test "$file" "$cmp_file"
54 done
55
56 # To compare feed.xml, ignore all variable date and uuid strings.
57 original_file="$generated_files_dir""/feed.xml"
58 generated_file="$original_file".ignoring
59 expected_file="$expected_files_dir""/feed.xml.ignoring"
60 cat "$original_file" | \
61   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
62   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</' \
63   > "$generated_file"
64 diff_test "$expected_file" "$generated_file"
65 rm "$generated_file"