home · contact · privacy
26d4f33782712436b488a9546b313998c8ae2bbf
[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 rm -rf test/test_dir
28 ./add_dir.sh test/test_dir
29 cp test/test_files/test.md test/test_dir/
30 cp test/test_files/foo.rst test/test_dir/
31 cp test/test_files/bar\ baz.md test/test_dir/
32 cd test/test_dir
33 redo
34 cd ../..
35 uuid_regex="^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
36 for file in test/test_files/*.html test/test_files/*.meta; do
37   cmp_file=`echo "$file" | sed 's/test_files/test_dir/'`
38   if [ ! "$file" = "test/test_files/index.html" ] && \
39       echo "$file" | grep -q "\.html$"; then
40     uuid_test "${cmp_file%.html}.uuid"
41   fi
42   diff_test "$file" "$cmp_file"
43 done
44 uuid_test "test/test_dir/uuid.meta"
45 original_file="test/test_dir/feed.xml"
46 generated_file="$original_file".ignoring
47 expected_file="test/test_files/feed.xml.ignoring"
48 cat "$original_file" | \
49   sed 's/>[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}T[0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}Z</>IGNORE</' | \
50   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</' \
51   > "$generated_file"
52 diff_test "$expected_file" "$generated_file"
53 rm "$generated_file"