index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
diff --git a/test/scripts/Makefile.am b/test/scripts/Makefile.am index 8d6bc842..ed1a9511 100644 --- a/test/scripts/Makefile.am +++ b/test/scripts/Makefile.am @@ -1,6 +1,7 @@ check_SCRIPTS = \ parseopts_test.sh \ pacman-db-upgrade-v9.py \ + makepkg-template_test.sh \ human_to_size_test.sh noinst_SCRIPTS = $(check_SCRIPTS) diff --git a/test/scripts/human_to_size_test.sh b/test/scripts/human_to_size_test.sh index dfa01f72..6334495f 100755 --- a/test/scripts/human_to_size_test.sh +++ b/test/scripts/human_to_size_test.sh @@ -1,82 +1,57 @@ #!/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 +tap_parse_hts() { + 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' +tap_plan 15 -echo "1..$total" +# tap_parse_hts <input> <expected output> -# parse_hts <input> <expected output> +tap_parse_hts '1MiB' 1048576 -parse_hts '1MiB' 1048576 +tap_parse_hts '10XiB' '' -parse_hts '10XiB' '' +tap_parse_hts '10 MiB' 10485760 -parse_hts '10 MiB' 10485760 +tap_parse_hts '10 XiB' '' -parse_hts '10 XiB' '' +tap_parse_hts '.1 TiB' 109951162778 -parse_hts '.1 TiB' 109951162778 +tap_parse_hts ' -3 KiB ' -3072 -parse_hts ' -3 KiB ' -3072 +tap_parse_hts 'foo3KiB' '' -parse_hts 'foo3KiB' '' +tap_parse_hts '3KiBfoo' '' -parse_hts '3KiBfoo' '' +tap_parse_hts '3kib' '' -parse_hts '3kib' '' +tap_parse_hts '+1KiB' 1024 -parse_hts '+1KiB' 1024 +tap_parse_hts '+1.0 KiB' 1024 -parse_hts '+1.0 KiB' 1024 +tap_parse_hts '1MB' 1000000 -parse_hts '1MB' 1000000 +tap_parse_hts '1M' 1048576 -parse_hts '1M' 1048576 +tap_parse_hts ' 1 G ' 1073741824 -parse_hts ' 1 G ' 1073741824 +tap_parse_hts '1Q' '' -parse_hts '1Q' '' +# vim: set noet: diff --git a/test/scripts/makepkg-template-tests/invalid-key/PKGBUILD b/test/scripts/makepkg-template-tests/invalid-key/PKGBUILD new file mode 100644 index 00000000..02bfadcc --- /dev/null +++ b/test/scripts/makepkg-template-tests/invalid-key/PKGBUILD @@ -0,0 +1 @@ +# template input; []³|>=bar; diff --git a/test/scripts/makepkg-template-tests/invalid-key/testcase-config b/test/scripts/makepkg-template-tests/invalid-key/testcase-config new file mode 100644 index 00000000..4e4725e2 --- /dev/null +++ b/test/scripts/makepkg-template-tests/invalid-key/testcase-config @@ -0,0 +1,11 @@ +arguments+=() +expected_exitcode=255 + +# set IFS="" if you want trailing new lines, otherwise remove it +IFS="" read -d '' expected_output <<'EOF' +invalid key/value pair +./makepkg-template-tests/invalid-key/PKGBUILD:1: # template input; []³|>=bar; +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD new file mode 100644 index 00000000..d0a20c18 --- /dev/null +++ b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD @@ -0,0 +1 @@ +# template input; diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config new file mode 100644 index 00000000..6bfda327 --- /dev/null +++ b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config @@ -0,0 +1,11 @@ +arguments+=() +expected_exitcode=255 + +# set IFS="" if you want trailing new lines, otherwise remove it +IFS="" read -d '' expected_output <<'EOF' +invalid template line: can't find template name +./makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD:1: # template input; +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD new file mode 100644 index 00000000..645ea371 --- /dev/null +++ b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD @@ -0,0 +1,9 @@ +pkgname=foo +pkgver=1 + +build() { +# template boom; name=test +perl Makefile.pl +make +# template end; +} diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config new file mode 100644 index 00000000..077a85c3 --- /dev/null +++ b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config @@ -0,0 +1,11 @@ +arguments+=() +expected_exitcode=255 + +# set IFS="" if you want trailing new lines, otherwise remove it +IFS="" read -d '' expected_output <<'EOF' +Unknown template marker 'boom' +./makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD:5: # template boom; name=test +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD b/test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD new file mode 100644 index 00000000..09da2e03 --- /dev/null +++ b/test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD @@ -0,0 +1,15 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=perl-module; version=1.0; +echo "before bla template" +# template start; name=perl-bla; version=1.2; +bla bla +# template end; +echo "after bla template" +perl Makefile.pl +make +make install +# template end; +} diff --git a/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template new file mode 100644 index 00000000..b72e7d48 --- /dev/null +++ b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template @@ -0,0 +1 @@ +bla bla diff --git a/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template new file mode 100644 index 00000000..415025ac --- /dev/null +++ b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template @@ -0,0 +1,6 @@ +echo "before bla template" +# template input; name=perl-bla +echo "after bla template" +perl Makefile.pl +make +make install diff --git a/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template new file mode 100644 index 00000000..5ad32c3c --- /dev/null +++ b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template @@ -0,0 +1,7 @@ +echo "perl-module version 1.1" +echo "before bla template" +# template input; name=perl-bla +echo "after bla template" +perl Makefile.pl +make +make install diff --git a/test/scripts/makepkg-template-tests/keep-old-version/testcase-config b/test/scripts/makepkg-template-tests/keep-old-version/testcase-config new file mode 100644 index 00000000..b9448a08 --- /dev/null +++ b/test/scripts/makepkg-template-tests/keep-old-version/testcase-config @@ -0,0 +1,29 @@ +arguments+=() +expected_exitcode=0 + +_setup_testcase() { + ln -sr "templates/"{perl-bla-1.2.template,perl-bla.template} + ln -sr "templates/"{perl-module-1.1.template,perl-module.template} +} + +# set IFS="" if you want trailing new lines, otherwise remove it +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +build() { +# template start; name=perl-module; version=1.0; +echo "before bla template" +# template start; name=perl-bla; version=1.2; +bla bla +# template end; +echo "after bla template" +perl Makefile.pl +make +make install +# template end; +} +EOF diff --git a/test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD b/test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD new file mode 100644 index 00000000..dbfda1dd --- /dev/null +++ b/test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD @@ -0,0 +1,7 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=perl-module; version=1.0; +# template end; +} diff --git a/test/scripts/makepkg-template-tests/missing-template-file/testcase-config b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config new file mode 100644 index 00000000..bdfde40d --- /dev/null +++ b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config @@ -0,0 +1,14 @@ +arguments+=() +expected_exitcode=2 + +_setup_testcase() { + ln -sr "templates/"{perl-module-1.0.template,perl-module.template} +} + +# set IFS="" if you want trailing new lines, otherwise remove it +IFS="" read -d '' expected_output <<'EOF' +failed to open './makepkg-template-tests/missing-template-file/templates/perl-module-1.0.template': No such file or directory +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD b/test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD new file mode 100644 index 00000000..8ee94aca --- /dev/null +++ b/test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD @@ -0,0 +1,7 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=perl-module; +# template end; +} diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template b/test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template new file mode 100644 index 00000000..f499d252 --- /dev/null +++ b/test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template @@ -0,0 +1 @@ +this should not be included diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config new file mode 100644 index 00000000..c0eabe0d --- /dev/null +++ b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config @@ -0,0 +1,9 @@ +arguments+=() +expected_exitcode=255 + +IFS="" read -d '' expected_output <<'EOF' +Couldn't detect version for template 'perl-module' +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD b/test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD new file mode 100644 index 00000000..36ed75bb --- /dev/null +++ b/test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD @@ -0,0 +1,8 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=foo/ +make install +# template end; +} diff --git a/test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config b/test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config new file mode 100644 index 00000000..7ea9502c --- /dev/null +++ b/test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config @@ -0,0 +1,10 @@ +arguments+=() +expected_exitcode=255 + +IFS="" read -d '' expected_output <<'EOF' +invalid chars used in name 'foo/'. allowed: [:alnum:]+_.@- +./makepkg-template-tests/name-charset-invalid/PKGBUILD:5: # template start; name=foo/ +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD b/test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD new file mode 100644 index 00000000..ec21cdb4 --- /dev/null +++ b/test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD @@ -0,0 +1,8 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=foo@-_.+a +make install +# template end; +} diff --git a/test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template b/test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template new file mode 100644 index 00000000..d0884a6c --- /dev/null +++ b/test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template @@ -0,0 +1 @@ +42 cookies diff --git a/test/scripts/makepkg-template-tests/name-charset-valid/testcase-config b/test/scripts/makepkg-template-tests/name-charset-valid/testcase-config new file mode 100644 index 00000000..409444a9 --- /dev/null +++ b/test/scripts/makepkg-template-tests/name-charset-valid/testcase-config @@ -0,0 +1,19 @@ +arguments+=() +expected_exitcode=0 + +_setup_testcase() { + ln -sr "templates/"{foo\@-_.+a-1.template,foo\@-_.+a.template} +} +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +build() { +# template start; name=foo@-_.+a; version=1; +42 cookies +# template end; +} +EOF diff --git a/test/scripts/makepkg-template-tests/template-without-version/PKGBUILD b/test/scripts/makepkg-template-tests/template-without-version/PKGBUILD new file mode 100644 index 00000000..a4509a1a --- /dev/null +++ b/test/scripts/makepkg-template-tests/template-without-version/PKGBUILD @@ -0,0 +1,8 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=template-without_version +make install +# template end; +} diff --git a/test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template b/test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template diff --git a/test/scripts/makepkg-template-tests/template-without-version/testcase-config b/test/scripts/makepkg-template-tests/template-without-version/testcase-config new file mode 100644 index 00000000..ec04f2fa --- /dev/null +++ b/test/scripts/makepkg-template-tests/template-without-version/testcase-config @@ -0,0 +1,9 @@ +arguments+=() +expected_exitcode=255 + +IFS="" read -d '' expected_output <<'EOF' +Couldn't detect version for template 'template-without_version' +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/testcase-config-template b/test/scripts/makepkg-template-tests/testcase-config-template new file mode 100644 index 00000000..66267d3b --- /dev/null +++ b/test/scripts/makepkg-template-tests/testcase-config-template @@ -0,0 +1,9 @@ +arguments+=() +expected_exitcode=0 + +# set IFS="" if you want trailing new line(s), otherwise remove it +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +EOF diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD b/test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD new file mode 100644 index 00000000..e1687cc8 --- /dev/null +++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD @@ -0,0 +1,7 @@ +pkgname=foo +pkgver=1 + +build() { +# template start; name=perl-module; version=1.0 +# template end; +} diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template new file mode 100644 index 00000000..b72e7d48 --- /dev/null +++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template @@ -0,0 +1 @@ +bla bla diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template new file mode 100644 index 00000000..415025ac --- /dev/null +++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template @@ -0,0 +1,6 @@ +echo "before bla template" +# template input; name=perl-bla +echo "after bla template" +perl Makefile.pl +make +make install diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template new file mode 100644 index 00000000..5ad32c3c --- /dev/null +++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template @@ -0,0 +1,7 @@ +echo "perl-module version 1.1" +echo "before bla template" +# template input; name=perl-bla +echo "after bla template" +perl Makefile.pl +make +make install diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config b/test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config new file mode 100644 index 00000000..5956a0a2 --- /dev/null +++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config @@ -0,0 +1,29 @@ +arguments+=(-n) +expected_exitcode=0 + +_setup_testcase() { + ln -sr "templates/"{perl-bla-1.2.template,perl-bla.template} + ln -sr "templates/"{perl-module-1.1.template,perl-module.template} +} + +IFS="" read -d '' expected_output <<'EOF' +EOF + +IFS="" read -d '' expected_result <<'EOF' +pkgname=foo +pkgver=1 + +build() { +# template start; name=perl-module; version=1.1; +echo "perl-module version 1.1" +echo "before bla template" +# template start; name=perl-bla; version=1.2; +bla bla +# template end; +echo "after bla template" +perl Makefile.pl +make +make install +# template end; +} +EOF diff --git a/test/scripts/makepkg-template_test.sh b/test/scripts/makepkg-template_test.sh new file mode 100755 index 00000000..b2531d4a --- /dev/null +++ b/test/scripts/makepkg-template_test.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +source "$(dirname "$0")"/../tap.sh || exit 1 + +script=${1:-${PMTEST_SCRIPT_DIR}makepkg-template} + +if ! type -p "$script" &>/dev/null; then + tap_bail "makepkg-template executable (%s) could not be located" "${script}" + exit 1 +fi + +TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")" +trap "rm -rf '${TMPDIR}'" EXIT TERM +cp -r "${0%/*}/makepkg-template-tests" "$TMPDIR/makepkg-template-tests" + +# normalize paths +script="$(readlink -f $(type -p "$script"))" +cd "$TMPDIR" +testdir="./makepkg-template-tests" + + +total=$(find "$testdir" -maxdepth 1 -mindepth 1 -type d | wc -l) +if [[ -z "$total" ]]; then + tap_bail "unable to determine total number of tests" + exit 1 +fi +tap_plan "$((total*3))" + +run_test() { + local testcase=$1 exitcode expected_result expected_output + local -a arguments + local -i expected_exitcode=-1 + + [[ -f "$testdir/$testcase/testcase-config" ]] || continue + source "$testdir/$testcase/testcase-config" + + mkdir "$TMPDIR/$testcase" + touch "$TMPDIR/$testcase/result" + + # work around autotools not putting symlinks into the release tarball + [[ -d "$TMPDIR/$testdir/$testcase/templates" ]] || mkdir "$TMPDIR/$testdir/$testcase/templates" + if type -t _setup_testcase >/dev/null; then + cd "$TMPDIR/$testdir/$testcase" + _setup_testcase + unset -f _setup_testcase + cd "$TMPDIR" + fi + + LC_ALL=C "$script" \ + --template-dir "$testdir/$testcase/templates" \ + -p "$testdir/$testcase/PKGBUILD" \ + -o "$TMPDIR/$testcase/result" \ + &> "$TMPDIR/$testcase/output" "${arguments[@]}" + exitcode=$? + + tap_is_int "$exitcode" "$expected_exitcode" "$testcase exitcode" + tap_diff "$TMPDIR/$testcase/output" <(printf "%s" "$expected_output") "$testcase output" + tap_diff "$TMPDIR/$testcase/result" <(printf "%s" "$expected_result") "$testcase resulting PKGBUILD" +} + +for dir in "$testdir/"*; do + if [[ -d "$dir" ]]; then + run_test "${dir##*/}" + fi +done + +tap_finish diff --git a/test/scripts/parseopts_test.sh b/test/scripts/parseopts_test.sh index 2c055b1b..a8738a4c 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 @@ -23,120 +23,94 @@ OPT_LONG=('allsource' 'asroot' 'ignorearch' 'check' 'clean:' 'cleanall' 'nodeps' 'repackage' 'skipinteg' 'sign' 'source' 'syncdeps' 'version' 'config:' 'noconfirm' 'noprogressbar') -parse() { +tap_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 '--' +# usage: tap_parse <expected result> <token count> test-params... +# a failed tap_parse will match only the end of options marker '--' # no options -parse '--' 1 +tap_parse '--' 1 # short options -parse '-s -r --' 3 -s -r +tap_parse '-s -r --' 3 -s -r # short options, no spaces -parse '-s -r --' 3 -sr +tap_parse '-s -r --' 3 -sr # short opt missing an opt arg -parse '--' 1 -s -p +tap_parse '--' 1 -s -p # short opt with an opt arg -parse '-p PKGBUILD -L --' 4 -p PKGBUILD -L +tap_parse '-p PKGBUILD -L --' 4 -p PKGBUILD -L # short opt with an opt arg, no space -parse '-p PKGBUILD --' 3 -pPKGBUILD +tap_parse '-p PKGBUILD --' 3 -pPKGBUILD # valid shortopts as a long opt -parse '--' 1 --sir +tap_parse '--' 1 --sir # long opt with no optarg -parse '--log --' 2 --log +tap_parse '--log --' 2 --log # long opt with missing optarg -parse '--' 1 -sr --pkg +tap_parse '--' 1 -sr --pkg # long opt with optarg -parse '--pkg foo --' 3 --pkg foo +tap_parse '--pkg foo --' 3 --pkg foo # long opt with optarg with whitespace -parse '--pkg foo bar -- baz' 4 --pkg "foo bar" baz +tap_parse '--pkg foo bar -- baz' 4 --pkg "foo bar" baz # long opt with optarg with = -parse '--pkg foo=bar -- baz' 4 --pkg foo=bar baz +tap_parse '--pkg foo=bar -- baz' 4 --pkg foo=bar baz # long opt with explicit optarg -parse '--pkg bar -- foo baz' 5 foo --pkg=bar baz +tap_parse '--pkg bar -- foo baz' 5 foo --pkg=bar baz # long opt with explicit optarg, with whitespace -parse '--pkg foo bar -- baz' 4 baz --pkg="foo bar" +tap_parse '--pkg foo bar -- baz' 4 baz --pkg="foo bar" # long opt with explicit optarg that doesn't take optarg -parse '--' 1 --force=always -s +tap_parse '--' 1 --force=always -s # long opt with explicit optarg with = -parse '--pkg foo=bar --' 3 --pkg=foo=bar +tap_parse '--pkg foo=bar --' 3 --pkg=foo=bar # explicit end of options with options after -parse '-s -r -- foo bar baz' 6 -s -r -- foo bar baz +tap_parse '-s -r -- foo bar baz' 6 -s -r -- foo bar baz # non-option parameters mixed in with options -parse '-s -r -- foo baz' 5 -s foo baz -r +tap_parse '-s -r -- foo baz' 5 -s foo baz -r # optarg with whitespace -parse '-p foo bar -s --' 4 -p'foo bar' -s +tap_parse '-p foo bar -s --' 4 -p'foo bar' -s # non-option parameter with whitespace -parse '-i -- foo bar' 3 -i 'foo bar' +tap_parse '-i -- foo bar' 3 -i 'foo bar' # successful stem match (opt has no arg) -parse '--nocolor --' 2 --nocol +tap_parse '--nocolor --' 2 --nocol # successful stem match (opt has arg) -parse '--config foo --' 3 --conf foo +tap_parse '--config foo --' 3 --conf foo # ambiguous long opt -parse '--' 1 '--for' +tap_parse '--' 1 '--for' # exact match on a possible stem (--force & --forcever) -parse '--force --' 2 --force +tap_parse '--force --' 2 --force # exact match on possible stem (opt has optarg) -parse '--clean foo --' 3 --clean=foo +tap_parse '--clean foo --' 3 --clean=foo + +tap_finish + +# vim: set noet: |