summaryrefslogtreecommitdiffstats
path: root/test/scripts/human_to_size_test.sh
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2014-12-23 22:09:58 +0100
committerAllan McRae <allan@archlinux.org>2014-12-28 04:06:28 +0100
commit29c0d8233b32ab3ad1dcd7c3bf1161449a386dea (patch)
treea25ac6b4006b706cd65465bfd5f23eda1b1f687d /test/scripts/human_to_size_test.sh
parent4c4890dd1cad52a420788e6c30a8e6eca8f83c38 (diff)
downloadpacman-29c0d8233b32ab3ad1dcd7c3bf1161449a386dea.tar.gz
pacman-29c0d8233b32ab3ad1dcd7c3bf1161449a386dea.tar.xz
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 <andrew.gregory.8@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'test/scripts/human_to_size_test.sh')
-rwxr-xr-xtest/scripts/human_to_size_test.sh39
1 files changed, 6 insertions, 33 deletions
diff --git a/test/scripts/human_to_size_test.sh b/test/scripts/human_to_size_test.sh
index 2dacfd14..e412e836 100755
--- a/test/scripts/human_to_size_test.sh
+++ b/test/scripts/human_to_size_test.sh
@@ -1,53 +1,26 @@
#!/bin/bash
-declare -i testcount=0 fail=0 pass=0 total=15
+source "$(dirname "$0")"/../tap.sh || exit 1
# source the library function
lib=${1:-${PMTEST_SCRIPTLIB_DIR}human_to_size.sh}
if [[ -z $lib || ! -f $lib ]]; then
- printf "Bail out! human_to_size library (%s) could not be located\n" "${lib}"
+ tap_bail "human_to_size library (%s) could not be located" "${lib}"
exit 1
fi
. "$lib"
if ! type -t human_to_size &>/dev/null; then
- printf "Bail out! human_to_size function not found\n"
+ tap_bail "human_to_size function not found"
exit 1
fi
parse_hts() {
- local input=$1 expected=$2 result
-
- (( ++testcount ))
-
- result=$(human_to_size "$1")
- if [[ $result = "$expected" ]]; then
- (( ++pass ))
- printf "ok %d - %s\n" "$testcount" "$input"
- else
- (( ++fail ))
- printf "not ok %d - %s\n" "$testcount" "$input"
- printf '# [TEST %3s]: FAIL\n' "$testcount"
- printf '# input: %s\n' "$input"
- printf '# output: %s\n' "$result"
- printf '# expected: %s\n' "$expected"
- fi
+ local input=$1 expected=$2
+ tap_is_str "$(human_to_size "$input")" "$expected" "$input"
}
-summarize() {
- if (( !fail )); then
- printf '# All %s tests successful\n\n' "$testcount"
- exit 0
- else
- printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
- exit 1
- fi
-}
-trap 'summarize' EXIT
-
-printf '# Beginning human_to_size tests\n'
-
-echo "1..$total"
+tap_plan 15
# parse_hts <input> <expected output>