home · contact · privacy
To feed generator, add handler for case of empty blog.
[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 redo
37 cp "$working_dir/$expected_files_dir"/test.md .
38 redo
39 cp "$working_dir/$expected_files_dir"/bar\ baz.md .
40 redo
41 cp "$working_dir/$expected_files_dir"/foo.rst .
42 redo
43 cd "$working_dir"
44
45 # Simple file comparison tests and UUID tests.
46 uuid_test "$generated_files_dir""/metadata/uuid"
47 for file in "$expected_files_dir"/*.html "$expected_files_dir"/metadata/*; do
48   sed_expression='s/'"$expected_files_dir_escaped"'/'"$generated_files_dir_escaped"'/'
49   cmp_file=`echo "$file" | sed "$sed_expression"`
50   if [ ! "$file" = "$expected_files_dir""/index.html" ] && \
51       echo "$file" | grep -q "\.html$"; then
52     basename=$(basename "$cmp_file")
53     uuid_test "${generated_files_dir}/metadata/${basename%.html}.uuid"
54   fi
55   diff_test "$file" "$cmp_file"
56 done
57
58 # To compare feed.xml, ignore all variable date and uuid strings.
59 original_file="$generated_files_dir""/feed.xml"
60 generated_file="$original_file".ignoring
61 expected_file="$expected_files_dir""/feed.xml.ignoring"
62 cat "$original_file" | \
63   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
64   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</' \
65   > "$generated_file"
66 diff_test "$expected_file" "$generated_file"
67 rm "$generated_file"
68
69 # Check symbolic links.
70 for file in "$generated_files_dir"/feed.xml "$generated_files_dir"/*.html; do
71   basename=$(basename "$file")
72   linkname=$(readlink "$generated_files_dir/public/$basename")
73   printf "== public/%s symbolic link test ==\n" "$basename"
74   if [ "$working_dir/$generated_files_dir/$basename" = "$linkname" ]; then
75     echo "== test SUCCESS =="
76   else
77     echo "== test FAILURE =="
78   fi
79 done