From 2481ce63ddaadf51d3e064bc6f3c0d157c5757b7 Mon Sep 17 00:00:00 2001 From: Andreas Waidler Date: Mon, 4 Apr 2011 08:44:36 +0200 Subject: [PATCH] Work on acceptance tests. * testing whether items without date get a UNIX timestamp of 0 * acceptance tests now continue even if a tests fails * cleaned code of acceptance tests --- TODO | 2 + tests_usr.sh | 190 ++++++++++++----------------------------------------------- 2 files changed, 39 insertions(+), 153 deletions(-) diff --git a/TODO b/TODO index 894bd8a..aaacb3b 100644 --- a/TODO +++ b/TODO @@ -6,6 +6,8 @@ * refactoring * split into subdirectories + * split acceptance test into seperate dir, + tests into seperate files * test driven refactoring * more assertions * replace assertions by proper error handling diff --git a/tests_usr.sh b/tests_usr.sh index 33743c6..7fd63cb 100755 --- a/tests_usr.sh +++ b/tests_usr.sh @@ -42,6 +42,7 @@ function cleanup() rm -rf "$FEED" item "simple feed" "simple feed t" "simple feed d" "long feed" || exit 1 } +FAILURES=0 function t() { printf " %-32s: " "$1" @@ -49,141 +50,46 @@ function t() result=$? if [ $result -ne 0 ]; then echo "FAIL" - exit $result + FAILURES=`expr $FAILURES + 1 ` else echo "OK" fi } -function test_feed_exists() -{ - [ -d "$1" ] && return 0 - return 1 -} - -function test_feed_empty() -{ - [ `ls "$1" | wc -l` = "0" ] && return 0 - return 1 -} - -function test_feed_date() -{ - [ `stat -c %Y "$1"` = "$2" ] && return 0 - return 1 -} - -function test_item_exists() -{ - [ -f "$1" ] && return 0 - return 1 -} - -function test_item_date() -{ - [ `stat -c %Y "$1"` = "$2" ] && return 0 - return 1 -} - -function test_item_missing() -{ - [ ! -e "$1" ] && return 0 - return 1 -} +function test_feed_exists() { [ -d "$1" ]; } +function test_feed_empty() { [ `ls "$1" | wc -l` = "0" ]; } +function test_feed_date() { [ `stat -c %Y "$1"` = "$2" ]; } +function test_item_exists() { [ -f "$1" ]; } +function test_item_date() { [ `stat -c %Y "$1"` = "$2" ]; } +function test_item_missing() { [ ! -e "$1" ]; } +# BUG: "`cat`" drops trailing \n. +function test_item_contents() { [ "`cat \"$1\"`" = "$2" ]; } -function test_item_contents() -{ - # BUG: "`cat`" drops trailing \n. - [ "`cat \"$1\"`" = "$2" ] && return 0 - return 1 -} +################## TEST CASES FOLLOW ###################### -################################################################# +function test_simple_t_feed_exists() { test_feed_exists "simple feed t"; } +function test_simple_t_item_exists() { test_item_exists "simple feed t/item"; } +function test_simple_t_item_date() { test_item_date "simple feed t/item" 0; } +function test_simple_t_item_contents() { test_item_contents "simple feed t/item" "item"; } -function test_simple_t_feed_exists() -{ - test_feed_exists "simple feed t" - return $? -} - -function test_simple_t_item_exists() -{ - test_item_exists "simple feed t/item" - return $? -} - -function test_simple_t_item_contents() -{ - test_item_contents "simple feed t/item" "item" - return $? -} - -function test_simple_d_feed_exists() -{ - test_feed_exists "simple feed d" - return $? -} - -function test_simple_d_item_contents() -{ - test_item_contents "simple feed d/item" "item" - return $? -} - -function test_complete_feed_exists() -{ - test_feed_exists "$FEED" - return $? -} - -function test_complete_feed_empty() -{ - test_feed_empty "$FEED" - return $? -} - -function test_complete_feed_date() -{ - test_feed_date "$FEED" 1286052203 - return $? -} - -function test_complete_item1_exists() -{ - test_item_exists "$FEED/$ITEM1" - return $? -} - -function test_complete_item2_exists() -{ - test_item_exists "$FEED/$ITEM2" - return $? -} - -function test_complete_item3_exists() -{ - test_item_exists "$FEED/$ITEM3" - return $? -} - -function test_complete_item1_date() -{ - test_item_date "$FEED/$ITEM1" 1286052203 - return $? -} - -function test_complete_item2_date() -{ - test_item_date "$FEED/$ITEM2" 1270203000 - return $? -} - -function test_complete_item3_date() -{ - test_item_date "$FEED/$ITEM3" 1270119246 - return $? -} +function test_simple_d_feed_exists() { test_feed_exists "simple feed d"; } +function test_simple_d_item_contents() { test_item_contents "simple feed d/item" "item"; } +LO=________________________________. +LC=________________________________ +function test_long_feed_exists() { test_feed_exists "long feed"; } +function test_long_item_exists() { test_item_exists "long feed/$LC"; } +function test_long_item_contents { test_item_contents "long feed/$LC" "$LO"; } + +function test_complete_feed_exists() { test_feed_exists "$FEED"; } +function test_complete_feed_empty() { test_feed_empty "$FEED"; } +function test_complete_feed_date() { test_feed_date "$FEED" 1286052203; } +function test_complete_item1_exists() { test_item_exists "$FEED/$ITEM1"; } +function test_complete_item2_exists() { test_item_exists "$FEED/$ITEM2"; } +function test_complete_item3_exists() { test_item_exists "$FEED/$ITEM3"; } +function test_complete_item1_date() { test_item_date "$FEED/$ITEM1" 1286052203; } +function test_complete_item2_date() { test_item_date "$FEED/$ITEM2" 1270203000; } +function test_complete_item3_date() { test_item_date "$FEED/$ITEM3" 1270119246; } function test_complete_item1_contents() { exp="\ @@ -193,9 +99,7 @@ Random item. Link: /dev/random" test_item_contents "$FEED/$ITEM1" "$exp" - return $? } - function test_complete_item2_contents() { exp="\ @@ -205,9 +109,7 @@ Not so random item. Link: /dev/urandom" test_item_contents "$FEED/$ITEM2" "$exp" - return $? } - function test_complete_item3_contents() { exp="\ @@ -217,28 +119,6 @@ No item. Link: /dev/null" test_item_contents "$FEED/$ITEM3" "$exp" - return $? -} - -function test_long_feed_exists() -{ - test_feed_exists "long feed" - return $? -} - -LO=________________________________. -LC=________________________________ - -function test_long_item_exists() -{ - test_item_exists "long feed/$LC" - return $? -} - -function test_long_item_contents -{ - test_item_contents "long feed/$LC" "$LO" - return $? } ############################################### @@ -258,6 +138,7 @@ echo "Running agg on simple feed (titles)..." agg_run tests_simple_titles.rss t test_simple_t_feed_exists t test_simple_t_item_exists +t test_simple_t_item_date t test_simple_t_item_contents echo "Running agg on simple feed (descriptions)..." @@ -328,5 +209,8 @@ t test_long_feed_exists t test_long_item_exists t test_long_item_contents -echo "Success! Cleaning up..." +echo "Cleaning up..." cleanup + +echo "Failed $FAILURES times!" +exit $FAILURES -- 2.11.4.GIT