Work on acceptance tests.
[agg.git] / tests_usr.sh
blob7fd63cb59cffd44d759cd959bbbe2c15b16cf849
1 #!/bin/sh
3 FEED="agg test feed"
4 ITEM1="Item 1"
5 ITEM2="Item 2"
6 ITEM3="Item 3"
8 function agg_run()
10 cat "$1" | ./agg
11 res=$?
12 if [ $res -ne 0 ]; then
13 echo "Failed to run agg ($res)."
14 exit 1
18 function agg_fail()
20 cat "$1" | ./agg
21 res=$?
22 if [ $res -eq 0 ]; then
23 echo "Failed to fail running agg."
24 exit 1
28 function agg_clean()
30 cd "$FEED"
31 ../nomtime "rm *"
32 res=$?
33 if [ $res -ne 0 ]; then
34 echo "Failed to run agg_modify."
35 exit 1
37 cd ..
40 function cleanup()
42 rm -rf "$FEED" item "simple feed" "simple feed t" "simple feed d" "long feed" || exit 1
45 FAILURES=0
46 function t()
48 printf " %-32s: " "$1"
50 result=$?
51 if [ $result -ne 0 ]; then
52 echo "FAIL"
53 FAILURES=`expr $FAILURES + 1 `
54 else
55 echo "OK"
59 function test_feed_exists() { [ -d "$1" ]; }
60 function test_feed_empty() { [ `ls "$1" | wc -l` = "0" ]; }
61 function test_feed_date() { [ `stat -c %Y "$1"` = "$2" ]; }
62 function test_item_exists() { [ -f "$1" ]; }
63 function test_item_date() { [ `stat -c %Y "$1"` = "$2" ]; }
64 function test_item_missing() { [ ! -e "$1" ]; }
65 # BUG: "`cat`" drops trailing \n.
66 function test_item_contents() { [ "`cat \"$1\"`" = "$2" ]; }
68 ################## TEST CASES FOLLOW ######################
70 function test_simple_t_feed_exists() { test_feed_exists "simple feed t"; }
71 function test_simple_t_item_exists() { test_item_exists "simple feed t/item"; }
72 function test_simple_t_item_date() { test_item_date "simple feed t/item" 0; }
73 function test_simple_t_item_contents() { test_item_contents "simple feed t/item" "item"; }
75 function test_simple_d_feed_exists() { test_feed_exists "simple feed d"; }
76 function test_simple_d_item_contents() { test_item_contents "simple feed d/item" "item"; }
78 LO=________________________________.
79 LC=________________________________
80 function test_long_feed_exists() { test_feed_exists "long feed"; }
81 function test_long_item_exists() { test_item_exists "long feed/$LC"; }
82 function test_long_item_contents { test_item_contents "long feed/$LC" "$LO"; }
84 function test_complete_feed_exists() { test_feed_exists "$FEED"; }
85 function test_complete_feed_empty() { test_feed_empty "$FEED"; }
86 function test_complete_feed_date() { test_feed_date "$FEED" 1286052203; }
87 function test_complete_item1_exists() { test_item_exists "$FEED/$ITEM1"; }
88 function test_complete_item2_exists() { test_item_exists "$FEED/$ITEM2"; }
89 function test_complete_item3_exists() { test_item_exists "$FEED/$ITEM3"; }
90 function test_complete_item1_date() { test_item_date "$FEED/$ITEM1" 1286052203; }
91 function test_complete_item2_date() { test_item_date "$FEED/$ITEM2" 1270203000; }
92 function test_complete_item3_date() { test_item_date "$FEED/$ITEM3" 1270119246; }
93 function test_complete_item1_contents()
95 exp="\
96 Item 1
98 Random item.
100 Link: <a href=\"/dev/random\">/dev/random</a>"
101 test_item_contents "$FEED/$ITEM1" "$exp"
103 function test_complete_item2_contents()
105 exp="\
106 Item 2
108 Not so random item.
110 Link: <a href=\"/dev/urandom\">/dev/urandom</a>"
111 test_item_contents "$FEED/$ITEM2" "$exp"
113 function test_complete_item3_contents()
115 exp="\
116 Item 3
118 No item.
120 Link: <a href=\"/dev/null\">/dev/null</a>"
121 test_item_contents "$FEED/$ITEM3" "$exp"
124 ###############################################
126 echo "Cleaning directory..."
127 cleanup
129 echo "Running agg on feed without title..."
130 agg_fail tests_titleless.rss
131 t test_item_missing
133 echo "Running agg on feed with title after items..."
134 agg_fail tests_titlelate.rss
135 t test_item_missing
137 echo "Running agg on simple feed (titles)..."
138 agg_run tests_simple_titles.rss
139 t test_simple_t_feed_exists
140 t test_simple_t_item_exists
141 t test_simple_t_item_date
142 t test_simple_t_item_contents
144 echo "Running agg on simple feed (descriptions)..."
145 agg_run tests_simple_descriptions.rss
146 t test_simple_d_feed_exists
147 t test_simple_d_item_contents
149 echo "Running agg on missing directory..."
150 agg_run tests.rss
151 t test_complete_feed_exists
152 t test_complete_feed_date
153 t test_complete_item1_exists
154 t test_complete_item2_exists
155 t test_complete_item3_exists
156 t test_complete_item1_date
157 t test_complete_item2_date
158 t test_complete_item3_date
159 t test_complete_item1_contents
160 t test_complete_item2_contents
161 t test_complete_item3_contents
163 echo "Running agg on up-to-date directory..."
164 agg_run tests.rss
165 t test_complete_feed_exists
166 t test_complete_feed_date
167 t test_complete_item1_exists
168 t test_complete_item2_exists
169 t test_complete_item3_exists
170 t test_complete_item1_date
171 t test_complete_item2_date
172 t test_complete_item3_date
173 t test_complete_item1_contents
174 t test_complete_item2_contents
175 t test_complete_item3_contents
177 echo "Deleting old news..."
178 agg_clean
179 t test_complete_feed_exists
180 t test_complete_feed_date
181 t test_complete_feed_empty
183 echo "Running agg on clean up-to-date directory..."
184 agg_run tests.rss
185 t test_complete_feed_exists
186 t test_complete_feed_date
187 t test_complete_feed_empty
189 echo "Changing mtime..."
190 touch -md "1970-01-01 00:00:00.000000000 +0000" "$FEED"
192 echo "Running agg on clean outdated directory..."
193 agg_run tests.rss
194 t test_complete_feed_exists
195 t test_complete_feed_date
196 t test_complete_item1_exists
197 t test_complete_item2_exists
198 t test_complete_item3_exists
199 t test_complete_item1_date
200 t test_complete_item2_date
201 t test_complete_item3_date
202 t test_complete_item1_contents
203 t test_complete_item2_contents
204 t test_complete_item3_contents
206 echo "Running agg on feed with long items..."
207 agg_run tests_long.rss
208 t test_long_feed_exists
209 t test_long_item_exists
210 t test_long_item_contents
212 echo "Cleaning up..."
213 cleanup
215 echo "Failed $FAILURES times!"
216 exit $FAILURES