Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/test/scripts/parseopts_test.sh
diff options
context:
space:
mode:
authorAndrew Gregory <andrew.gregory.8@gmail.com>2014-12-23 16:09:58 -0500
committerAllan McRae <allan@archlinux.org>2014-12-28 13:06:28 +1000
commit29c0d8233b32ab3ad1dcd7c3bf1161449a386dea (patch)
treea25ac6b4006b706cd65465bfd5f23eda1b1f687d /test/scripts/parseopts_test.sh
parent4c4890dd1cad52a420788e6c30a8e6eca8f83c38 (diff)
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/parseopts_test.sh')
-rwxr-xr-xtest/scripts/parseopts_test.sh44
1 files changed, 8 insertions, 36 deletions
diff --git a/test/scripts/parseopts_test.sh b/test/scripts/parseopts_test.sh
index 97679c4f..03e9d0ac 100755
--- a/test/scripts/parseopts_test.sh
+++ b/test/scripts/parseopts_test.sh
@@ -1,17 +1,17 @@
#!/bin/bash
-declare -i testcount=0 pass=0 fail=0 total=25
+source "$(dirname "$0")"/../tap.sh || exit 1
# source the library function
lib=${1:-${PMTEST_SCRIPTLIB_DIR}parseopts.sh}
if [[ -z $lib || ! -f $lib ]]; then
- printf "Bail out! parseopts library ($lib) could not be located\n"
+ tap_bail "parseopts library ($lib) could not be located"
exit 1
fi
. "$lib"
if ! type -t parseopts &>/dev/null; then
- printf "Bail out! parseopts function not found\n"
+ tap_bail "parseopts function not found"
exit 1
fi
@@ -25,43 +25,13 @@ OPT_LONG=('allsource' 'asroot' 'ignorearch' 'check' 'clean:' 'cleanall' 'nodeps'
parse() {
local result=$1 tokencount=$2; shift 2
-
- (( ++testcount ))
parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@" 2>/dev/null
- test_result "$result" "$tokencount" "$*" "${OPTRET[@]}"
+ tap_is_int "${#OPTRET[@]}" "$tokencount" "$* - tokencount"
+ tap_is_str "$result" "${OPTRET[*]}" "$* - result"
unset OPTRET
}
-test_result() {
- local result=$1 tokencount=$2 input=$3; shift 3
-
- if [[ $result = "$*" ]] && (( tokencount == $# )); then
- (( ++pass ))
- printf 'ok %d - %s\n' "$testcount" "$input"
- else
- printf 'not ok %d - %s\n' "$testcount" "$input"
- printf '# [TEST %3s]: FAIL\n' "$testcount"
- printf '# input: %s\n' "$input"
- printf '# output: %s (%s tokens)\n' "$*" "$#"
- printf '# expected: %s (%s tokens)\n' "$result" "$tokencount"
- (( ++fail ))
- fi
-}
-
-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 parseopts tests\n'
-
-echo "1..$total"
+tap_plan 50
# usage: parse <expected result> <token count> test-params...
# a failed parse will match only the end of options marker '--'
@@ -141,4 +111,6 @@ parse '--force --' 2 --force
# exact match on possible stem (opt has optarg)
parse '--clean foo --' 3 --clean=foo
+tap_finish
+
# vim: set noet: