Fixed acceptance tests and requiring now that item title/desc comes first.
[agg.git] / tests_usr / tests
blobcf31af73b2e293a8878aacbdd98af3693e29275f
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 FAILURES=0
16 function agg_run()
18 cat "$1" | ../src/agg
19 res=$?
20 if [ $res -ne 0 ]; then
21 echo "Failed to run agg ($res)."
22 FAILURES=`expr $FAILURES + 1 `
26 function agg_fail()
28 cat "$1" | ../src/agg
29 res=$?
30 if [ $res -eq 0 ]; then
31 echo "Failed to fail running agg."
32 FAILURES=`expr $FAILURES + 1 `
36 function agg_clean()
38 find "$FEED" -type f -exec ../src/nomtime rm '{}' \;
39 res=$?
40 if [ $res -ne 0 ]; then
41 echo "Failed to run nomtime."
42 FAILURES=`expr $FAILURES + 1 `
46 function cleanup()
48 rm -rf "$FEED" item "feed" "simple feed" "simple feed t" "simple feed d" "long feed" || exit 1
51 function t()
53 printf " %-32s: " "$1"
55 result=$?
56 if [ $result -ne 0 ]; then
57 echo "FAIL"
58 FAILURES=`expr $FAILURES + 1 `
59 else
60 echo "OK"
64 function test_feed_exists() { [ -d "$1" ]; }
65 function test_feed_empty() { [ `ls "$1" | wc -l` = "0" ]; }
66 function test_feed_date() { [ `stat -c %Y "$1"` = "$2" ]; }
67 function test_item_exists() { [ -f "$1" ]; }
68 function test_item_date() { [ `stat -c %Y "$1"` = "$2" ]; }
69 function test_item_missing() { [ ! -e "$1" ]; }
70 # BUG: "`cat`" drops trailing \n.
71 function test_item_contents() { [ "`cat \"$1\"`" = "$2" ]; }
73 ################## TEST CASES FOLLOW ######################
75 function test_simple_t_feed_exists() { test_feed_exists "simple feed t"; }
76 function test_simple_t_item_exists() { test_item_exists "simple feed t/item"; }
77 function test_simple_t_item_date() { test_item_date "simple feed t/item" 0; }
78 function test_simple_t_item_contents() { test_item_contents "simple feed t/item" "item"; }
80 function test_simple_d_feed_exists() { test_feed_exists "simple feed d"; }
81 function test_simple_d_item_contents() { test_item_contents "simple feed d/item" "item"; }
83 LO=________________________________________________________________.
84 LC=________________________________________________________________
85 function test_long_feed_exists() { test_feed_exists "long feed"; }
86 function test_long_item_exists() { test_item_exists "long feed/$LC"; }
87 function test_long_item_contents { test_item_contents "long feed/$LC" "$LO"; }
89 function test_complete_feed_exists() { test_feed_exists "$FEED"; }
90 function test_complete_feed_empty() { test_feed_empty "$FEED"; }
91 function test_complete_feed_date() { test_feed_date "$FEED" 1286052203; }
92 function test_complete_item1_exists() { test_item_exists "$FEED/$ITEM1"; }
93 function test_complete_item2_exists() { test_item_exists "$FEED/$ITEM2"; }
94 function test_complete_item3_exists() { test_item_exists "$FEED/$ITEM3"; }
95 function test_complete_item1_date() { test_item_date "$FEED/$ITEM1" 1286052203; }
96 function test_complete_item2_date() { test_item_date "$FEED/$ITEM2" 1270203000; }
97 function test_complete_item3_date() { test_item_date "$FEED/$ITEM3" 1270119246; }
98 function test_complete_item1_contents()
100 exp="\
101 Item 1
103 Random item.
105 Link: <a href=\"/dev/random\">/dev/random</a>"
106 test_item_contents "$FEED/$ITEM1" "$exp"
108 function test_complete_item2_contents()
110 exp="\
111 Item 2
113 Not so random item.
115 Link: <a href=\"/dev/urandom\">/dev/urandom</a>"
116 test_item_contents "$FEED/$ITEM2" "$exp"
118 function test_complete_item3_contents()
120 exp="\
121 Item 3
123 No item.
125 Link: <a href=\"/dev/null\">/dev/null</a>"
126 test_item_contents "$FEED/$ITEM3" "$exp"
128 function test_fail_item_missing() { test_item_missing "feed/item"; }
130 ###############################################
132 echo "Running agg on simple feed (titles)..."
133 agg_run simple_t.rss
134 t test_simple_t_feed_exists
135 t test_simple_t_item_exists
136 t test_simple_t_item_date
137 t test_simple_t_item_contents
138 cleanup
140 echo "Running agg on simple feed (descriptions)..."
141 agg_run simple_d.rss
142 t test_simple_d_feed_exists
143 t test_simple_d_item_contents
144 cleanup
146 echo "Running agg on sample feed (directory missing)..."
147 agg_run sample.rss
148 t test_complete_feed_exists
149 t test_complete_feed_date
150 t test_complete_item1_exists
151 t test_complete_item2_exists
152 t test_complete_item3_exists
153 t test_complete_item1_date
154 t test_complete_item2_date
155 t test_complete_item3_date
156 t test_complete_item1_contents
157 t test_complete_item2_contents
158 t test_complete_item3_contents
160 echo "Running agg sample feed (up to date) ..."
161 agg_run sample.rss
162 t test_complete_feed_exists
163 t test_complete_feed_date
164 t test_complete_item1_exists
165 t test_complete_item2_exists
166 t test_complete_item3_exists
167 t test_complete_item1_date
168 t test_complete_item2_date
169 t test_complete_item3_date
170 t test_complete_item1_contents
171 t test_complete_item2_contents
172 t test_complete_item3_contents
174 echo "Deleting old news..."
175 agg_clean
176 t test_complete_feed_exists
177 t test_complete_feed_date
178 t test_complete_feed_empty
180 echo "Running agg on sample feed (directory up to date but empty)..."
181 agg_run sample.rss
182 t test_complete_feed_exists
183 t test_complete_feed_date
184 t test_complete_feed_empty
186 echo "Changing mtime..."
187 touch -md "1970-01-01 00:00:00.000000000 +0000" "$FEED"
189 echo "Running agg on sample feed (directory outdated and empty)..."
190 agg_run sample.rss
191 t test_complete_feed_exists
192 t test_complete_feed_date
193 t test_complete_item1_exists
194 t test_complete_item2_exists
195 t test_complete_item3_exists
196 t test_complete_item1_date
197 t test_complete_item2_date
198 t test_complete_item3_date
199 t test_complete_item1_contents
200 t test_complete_item2_contents
201 t test_complete_item3_contents
202 cleanup
204 echo "Running agg on feed with long items..."
205 agg_run long.rss
206 t test_long_feed_exists
207 t test_long_item_exists
208 t test_long_item_contents
209 cleanup
211 echo "Running agg on feed without title..."
212 agg_fail no_feed_title.rss
213 t test_fail_item_missing
215 echo "Running agg on feed with title after items..."
216 agg_fail feed_title_after_items.rss
217 t test_fail_item_missing
219 echo "Running agg on feed with item title after description..."
220 agg_fail title_after_description.rss
221 t test_fail_item_missing
222 cleanup
224 echo "Failed $FAILURES times!"
225 exit $FAILURES