Fix: False positive in agg_fail.
[agg.git] / tests_usr / libtests.sh
blob621658f37a67ab62ff2747322876db53c3c3639a
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 #set -x
11 function agg_run()
13 (cat "$1" | ../src/agg)
14 res=$?
15 if [ $res -ne 0 ]; then
16 echo "Failed to run agg ($res)."
17 exit $res
21 function agg_fail()
23 (cat "$1" | ../src/agg)
24 res=$?
25 if [ $res -eq 0 ]; then
26 echo "Failed to fail running agg."
27 exit 1
31 function agg_clean()
33 find "$1" -mindepth 1 \
34 -maxdepth 1 \
35 -type d \
36 -exec ../src/nomtime "rm -rf" '{}' \;
37 res=$?
38 if [ $res -ne 0 ]; then
39 echo "Failed to run nomtime."
40 exit $res
44 function t()
46 printf " %-32s: " "$1"
48 result=$?
49 if [ $result -ne 0 ]; then
50 echo "FAIL"
51 exit $result
52 else
53 echo "OK"
57 function assert_exists() { [ -d "$1" ]; }
58 function assert_date() { [ `stat -c %Y "$1"` = "$2" ]; }
59 function assert_empty() { [ `ls "$1" | wc -l` = "0" ]; }
60 function assert_missing() { [ ! -e "$1" ]; }
61 # BUG: "`cat`" drops trailing \n.
62 function assert_value() { [ "`cat \"$1/$2\"`" = "$3" ]; }
63 function assert_delete() {
64 BASENAME="`dirname "$1"`"
65 OLD_DATE="`stat -c %Y "$BASENAME"`"
66 ../src/nomtime "rm -rf" "$1"
67 assert_date "$BASENAME" "$OLD_DATE"