home · contact · privacy
8e2a024d3e96b3463858b04005708b80147cdadc
[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""/.meta/uuid"
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     basename=$(basename "$cmp_file")
52     uuid_test "${generated_files_dir}/.meta/${basename%.html}.uuid"
53   fi
54   diff_test "$file" "$cmp_file"
55 done
56
57 # To compare feed.xml, ignore all variable date and uuid strings.
58 original_file="$generated_files_dir""/feed.xml"
59 generated_file="$original_file".ignoring
60 expected_file="$expected_files_dir""/feed.xml.ignoring"
61 cat "$original_file" | \
62   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
63   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</' \
64   > "$generated_file"
65 diff_test "$expected_file" "$generated_file"
66 rm "$generated_file"
67
68 # Check symbolic links.
69 for file in "$generated_files_dir"/feed.xml "$generated_files_dir"/*.html; do
70   basename=$(basename "$file")
71   linkname=$(readlink "$generated_files_dir/public/$basename")
72   printf "== public/%s symbolic link test ==\n" "$basename"
73   if [ "$working_dir/$generated_files_dir/$basename" = "$linkname" ]; then
74     echo "== test SUCCESS =="
75   else
76     echo "== test FAILURE =="
77   fi
78 done