home · contact · privacy
Merge branch 'master' of github.com:plomlompom/redo-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 cp "$expected_files_dir"/test.md "$generated_files_dir"/
36 cp "$expected_files_dir"/foo.rst "$generated_files_dir"/
37 cp "$expected_files_dir"/bar\ baz.md "$generated_files_dir"/
38 cd "$generated_files_dir"
39 redo
40 cd "$working_dir" 
41
42 # Simple file comparison tests and UUID tests.
43 uuid_test "$generated_files_dir""/uuid.meta"
44 for file in "$expected_files_dir"/*.html "$expected_files_dir"/*.meta; do
45   sed_expression='s/'"$expected_files_dir_escaped"'/'"$generated_files_dir_escaped"'/'
46   cmp_file=`echo "$file" | sed "$sed_expression"`
47   if [ ! "$file" = "$expected_files_dir""/index.html" ] && \
48       echo "$file" | grep -q "\.html$"; then
49     uuid_test "${cmp_file%.html}.uuid"
50   fi
51   diff_test "$file" "$cmp_file"
52 done
53
54 # To compare feed.xml, ignore all variable date and uuid strings.
55 original_file="$generated_files_dir""/feed.xml"
56 generated_file="$original_file".ignoring
57 expected_file="$expected_files_dir""/feed.xml.ignoring"
58 cat "$original_file" | \
59   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
60   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</' \
61   > "$generated_file"
62 diff_test "$expected_file" "$generated_file"
63 rm "$generated_file"