home · contact · privacy
Display creation dates in index.html and article html files.
[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 generated_files_dir="test/test_dir"
30 rm -rf "$generated_files_dir" 
31 ./add_dir.sh "$generated_files_dir" 
32 working_dir=$(pwd)
33 cd "$generated_files_dir"
34 redo
35 cp "$working_dir/$expected_files_dir"/test.md .
36 redo
37 cp "$working_dir/$expected_files_dir"/bar\ baz.md .
38 redo
39 cp "$working_dir/$expected_files_dir"/foo.rst .
40 redo
41 cd "$working_dir"
42
43 # Compare metadata files.
44 uuid_test "$generated_files_dir""/metadata/uuid"
45 for file in "$expected_files_dir"/metadata/*; do
46   basename=$(basename "$file")
47   cmp_file="$generated_files_dir/metadata/$basename"
48   diff_test "$file" "$cmp_file"
49 done
50
51 # Compare generated HTML files. Ignore variable dates.
52 for file in "$expected_files_dir"/*.html.ignoring; do
53   basename=$(basename "$file")
54   cmp_file="$generated_files_dir/${basename%.ignoring}"
55   if [ ! "$file" = "$expected_files_dir""/index.html.ignoring" ]; then
56     uuid_test "${generated_files_dir}/metadata/${basename%.html.ignoring}.uuid"
57   fi
58   generated_file="$cmp_file".ignoring
59   cat "$cmp_file" | \
60     sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/IGNORE/g' | \
61     sed 's/IGNORET[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z/IGNORE/g' | \
62     sed 's/IGNORE [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\} (UTC)/IGNORE/g' \
63     > "$generated_file"
64   diff_test "$file" "$generated_file"
65 done
66
67 # Compare feed files. Ignore variable dates and UUIDs.
68 original_file="$generated_files_dir""/feed.xml"
69 generated_file="$original_file".ignoring
70 expected_file="$expected_files_dir""/feed.xml.ignoring"
71 cat "$original_file" | \
72   sed 's/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z/IGNORE/g' | \
73   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/g' \
74   > "$generated_file"
75 diff_test "$expected_file" "$generated_file"
76 rm "$generated_file"
77
78 # Check symbolic links.
79 for file in "$generated_files_dir"/feed.xml "$generated_files_dir"/*.html; do
80   basename=$(basename "$file")
81   linkname=$(readlink "$generated_files_dir/public/$basename")
82   printf "== public/%s symbolic link test ==\n" "$basename"
83   if [ "$working_dir/$generated_files_dir/$basename" = "$linkname" ]; then
84     echo "== test SUCCESS =="
85   else
86     echo "== test FAILURE =="
87   fi
88 done