From 29c0d8233b32ab3ad1dcd7c3bf1161449a386dea Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Tue, 23 Dec 2014 16:09:58 -0500 Subject: use tap.sh for bash tests tap.sh is a reusable TAP library that handles test counting and provides useful diagnostic messages on test failures. Signed-off-by: Andrew Gregory Signed-off-by: Allan McRae --- test/util/pacsorttest.sh | 36 ++++++------------------------- test/util/vercmptest.sh | 55 ++++++++---------------------------------------- 2 files changed, 15 insertions(+), 76 deletions(-) (limited to 'test/util') diff --git a/test/util/pacsorttest.sh b/test/util/pacsorttest.sh index a29d8f19..3414e767 100755 --- a/test/util/pacsorttest.sh +++ b/test/util/pacsorttest.sh @@ -18,15 +18,13 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +source "$(dirname "$0")"/../tap.sh || exit 1 + # default binary if one was not specified as $1 bin=${1:-${PMTEST_UTIL_DIR}pacsort} -# holds counts of tests -total=26 -run=0 -failure=0 if ! type -p "$bin" &>/dev/null; then - echo "Bail out! pacsort binary ($bin) could not be located" + tap_bail "pacsort binary ($bin) could not be located" exit 1 fi @@ -34,24 +32,10 @@ fi # runtest input expected test_description optional_opts runtest() { # run the test - ((run++)) - out=$(diff -u <(printf "$1" | $bin $4) <(printf "$2")) - if [[ $? -eq 0 ]]; then - echo "ok $run - $3" - else - ((failure++)) - echo "not ok $run - $3" - while read line; do - echo " # $line" - done <<<"$out" - fi + tap_diff <(printf "$1" | $bin $4) <(printf "$2") "$3" } -echo "# Running pacsort tests..." - -echo "1..$total" - -# BEGIN TESTS +tap_plan 26 in="1\n2\n3\n4\n" runtest $in $in "already ordered" @@ -124,14 +108,6 @@ runtest "$separator_reverse" "$separator" "really long input, sort key, separato runtest "$separator_reverse" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r" runtest "$separator" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r" -#END TESTS - -if [[ $failure -eq 0 ]]; then - echo "# All $run tests successful" - exit 0 -fi - -echo "# $failure of $run tests failed" -exit 1 +tap_finish # vim: set noet: diff --git a/test/util/vercmptest.sh b/test/util/vercmptest.sh index ba279a78..3f626434 100755 --- a/test/util/vercmptest.sh +++ b/test/util/vercmptest.sh @@ -18,57 +18,28 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +source "$(dirname "$0")"/../tap.sh || exit 1 + # default binary if one was not specified as $1 bin=${1:-${PMTEST_UTIL_DIR}vercmp} -# holds counts of tests -total=92 -run=0 -failure=0 # use first arg as our binary if specified if ! type -p "$bin" &>/dev/null; then - echo "Bail out! vercmp binary ($bin) could not be located" + tap_bail "vercmp binary ($bin) could not be located" exit 1 fi -# args: -# pass ver1 ver2 ret expected -pass() { - echo "ok $run - ver1: $1 ver2: $2 ret: $3" -} - -# args: -# fail ver1 ver2 ret expected -fail() { - echo "not ok $run - test: ver1: $1 ver2: $2 ret: $3 expected: $4" - ((failure++)) -} - # args: # runtest ver1 ver2 expected runtest() { - # run the test - ((run++)) - ret=$($bin $1 $2) - func='pass' - [[ -n $ret && $ret -eq $3 ]] || func='fail' - $func $1 $2 $ret $3 + local ver1=$1 ver2=$2 exp=$3 + tap_is_str "$($bin "$ver1" "$ver2")" "$exp" "$ver1 $ver2" # and run its mirror case just to be sure - ((run++)) - reverse=0 - [[ $3 -eq 1 ]] && reverse=-1 - [[ $3 -eq -1 ]] && reverse=1 - ret=$($bin $2 $1) - func='pass' - [[ -n $ret && $ret -eq $reverse ]] || func='fail' - $func $2 $1 $ret $reverse + (( exp *= -1 )) + tap_is_str "$($bin "$ver2" "$ver1")" "$exp" "$ver2 $ver1" } -echo "# Running vercmp tests..." - -echo "1..$total" - -# BEGIN TESTS +tap_plan 92 # all similar length, no pkgrel runtest 1.5.0 1.5.0 0 @@ -142,14 +113,6 @@ runtest 1:1.0 1.0 1 runtest 1:1.0 1.1 1 runtest 1:1.1 1.1 1 -#END TESTS - -if [[ $failure -eq 0 ]]; then - echo "# All $run tests successful" - exit 0 -fi - -echo "# $failure of $run tests failed" -exit 1 +tap_finish # vim: set noet: -- cgit v1.2.3-70-g09d2