Updated docs.
[agg.git] / tests_usr.sh
blob9f3b9568a725dea7b00948b7a3e60b10aaf23312
1 #!/bin/sh
2 # Copyright (C) 2011 Andreas Waidler <arandes@programmers.at>
4 # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
5 # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7 # 0. You just DO WHAT THE FUCK YOU WANT TO.
9 FEED="agg test feed"
10 ITEM1="Item 1"
11 ITEM2="Item 2"
12 ITEM3="Item 3"
14 function agg_run()
16 cat "$1" | ./agg
17 res=$?
18 if [ $res -ne 0 ]; then
19 echo "Failed to run agg ($res)."
20 exit 1
24 function agg_fail()
26 cat "$1" | ./agg
27 res=$?
28 if [ $res -eq 0 ]; then
29 echo "Failed to fail running agg."
30 exit 1
34 function agg_clean()
36 cd "$FEED"
37 find -type f -exec ../nomtime "rm '{}'" \;
38 res=$?
39 if [ $res -ne 0 ]; then
40 echo "Failed to run nomtime."
41 exit 1
43 cd ..
46 function cleanup()
48 rm -rf "$FEED" item "simple feed" "simple feed t" "simple feed d" "long feed" || exit 1
51 FAILURES=0
52 function t()
54 printf " %-32s: " "$1"
56 result=$?
57 if [ $result -ne 0 ]; then
58 echo "FAIL"
59 FAILURES=`expr $FAILURES + 1 `
60 else
61 echo "OK"
65 function test_feed_exists() { [ -d "$1" ]; }
66 function test_feed_empty() { [ `ls "$1" | wc -l` = "0" ]; }
67 function test_feed_date() { [ `stat -c %Y "$1"` = "$2" ]; }
68 function test_item_exists() { [ -f "$1" ]; }
69 function test_item_date() { [ `stat -c %Y "$1"` = "$2" ]; }
70 function test_item_missing() { [ ! -e "$1" ]; }
71 # BUG: "`cat`" drops trailing \n.
72 function test_item_contents() { [ "`cat \"$1\"`" = "$2" ]; }
74 ################## TEST CASES FOLLOW ######################
76 function test_simple_t_feed_exists() { test_feed_exists "simple feed t"; }
77 function test_simple_t_item_exists() { test_item_exists "simple feed t/item"; }
78 function test_simple_t_item_date() { test_item_date "simple feed t/item" 0; }
79 function test_simple_t_item_contents() { test_item_contents "simple feed t/item" "item"; }
81 function test_simple_d_feed_exists() { test_feed_exists "simple feed d"; }
82 function test_simple_d_item_contents() { test_item_contents "simple feed d/item" "item"; }
84 LO=________________________________________________________________.
85 LC=________________________________________________________________
86 function test_long_feed_exists() { test_feed_exists "long feed"; }
87 function test_long_item_exists() { test_item_exists "long feed/$LC"; }
88 function test_long_item_contents { test_item_contents "long feed/$LC" "$LO"; }
90 function test_complete_feed_exists() { test_feed_exists "$FEED"; }
91 function test_complete_feed_empty() { test_feed_empty "$FEED"; }
92 function test_complete_feed_date() { test_feed_date "$FEED" 1286052203; }
93 function test_complete_item1_exists() { test_item_exists "$FEED/$ITEM1"; }
94 function test_complete_item2_exists() { test_item_exists "$FEED/$ITEM2"; }
95 function test_complete_item3_exists() { test_item_exists "$FEED/$ITEM3"; }
96 function test_complete_item1_date() { test_item_date "$FEED/$ITEM1" 1286052203; }
97 function test_complete_item2_date() { test_item_date "$FEED/$ITEM2" 1270203000; }
98 function test_complete_item3_date() { test_item_date "$FEED/$ITEM3" 1270119246; }
99 function test_complete_item1_contents()
101 exp="\
102 Item 1
104 Random item.
106 Link: <a href=\"/dev/random\">/dev/random</a>"
107 test_item_contents "$FEED/$ITEM1" "$exp"
109 function test_complete_item2_contents()
111 exp="\
112 Item 2
114 Not so random item.
116 Link: <a href=\"/dev/urandom\">/dev/urandom</a>"
117 test_item_contents "$FEED/$ITEM2" "$exp"
119 function test_complete_item3_contents()
121 exp="\
122 Item 3
124 No item.
126 Link: <a href=\"/dev/null\">/dev/null</a>"
127 test_item_contents "$FEED/$ITEM3" "$exp"
130 ###############################################
132 echo "Cleaning directory..."
133 cleanup
135 echo "Running agg on feed without title..."
136 agg_fail tests_titleless.rss
137 t test_item_missing
139 echo "Running agg on feed with title after items..."
140 agg_fail tests_titlelate.rss
141 t test_item_missing
143 echo "Running agg on simple feed (titles)..."
144 agg_run tests_simple_titles.rss
145 t test_simple_t_feed_exists
146 t test_simple_t_item_exists
147 t test_simple_t_item_date
148 t test_simple_t_item_contents
150 echo "Running agg on simple feed (descriptions)..."
151 agg_run tests_simple_descriptions.rss
152 t test_simple_d_feed_exists
153 t test_simple_d_item_contents
155 echo "Running agg on missing directory..."
156 agg_run tests.rss
157 t test_complete_feed_exists
158 t test_complete_feed_date
159 t test_complete_item1_exists
160 t test_complete_item2_exists
161 t test_complete_item3_exists
162 t test_complete_item1_date
163 t test_complete_item2_date
164 t test_complete_item3_date
165 t test_complete_item1_contents
166 t test_complete_item2_contents
167 t test_complete_item3_contents
169 echo "Running agg on up-to-date directory..."
170 agg_run tests.rss
171 t test_complete_feed_exists
172 t test_complete_feed_date
173 t test_complete_item1_exists
174 t test_complete_item2_exists
175 t test_complete_item3_exists
176 t test_complete_item1_date
177 t test_complete_item2_date
178 t test_complete_item3_date
179 t test_complete_item1_contents
180 t test_complete_item2_contents
181 t test_complete_item3_contents
183 echo "Deleting old news..."
184 agg_clean
185 t test_complete_feed_exists
186 t test_complete_feed_date
187 t test_complete_feed_empty
189 echo "Running agg on clean up-to-date directory..."
190 agg_run tests.rss
191 t test_complete_feed_exists
192 t test_complete_feed_date
193 t test_complete_feed_empty
195 echo "Changing mtime..."
196 touch -md "1970-01-01 00:00:00.000000000 +0000" "$FEED"
198 echo "Running agg on clean outdated directory..."
199 agg_run tests.rss
200 t test_complete_feed_exists
201 t test_complete_feed_date
202 t test_complete_item1_exists
203 t test_complete_item2_exists
204 t test_complete_item3_exists
205 t test_complete_item1_date
206 t test_complete_item2_date
207 t test_complete_item3_date
208 t test_complete_item1_contents
209 t test_complete_item2_contents
210 t test_complete_item3_contents
212 echo "Running agg on feed with long items..."
213 agg_run tests_long.rss
214 t test_long_feed_exists
215 t test_long_item_exists
216 t test_long_item_contents
218 echo "Cleaning up..."
219 cleanup
221 echo "Failed $FAILURES times!"
222 exit $FAILURES