2012-04-08 12:32:17 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-12-23 16:09:58 -05:00
|
|
|
source "$(dirname "$0")"/../tap.sh || exit 1
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# source the library function
|
2013-07-29 14:57:59 -04:00
|
|
|
lib=${1:-${PMTEST_SCRIPTLIB_DIR}parseopts.sh}
|
|
|
|
if [[ -z $lib || ! -f $lib ]]; then
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_bail "parseopts library ($lib) could not be located"
|
2013-11-08 00:44:40 -05:00
|
|
|
exit 1
|
2012-04-08 12:32:17 -04:00
|
|
|
fi
|
2013-07-29 14:57:59 -04:00
|
|
|
. "$lib"
|
2012-04-08 12:32:17 -04:00
|
|
|
|
2013-11-05 08:50:44 -05:00
|
|
|
if ! type -t parseopts &>/dev/null; then
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_bail "parseopts function not found"
|
2013-11-08 00:44:40 -05:00
|
|
|
exit 1
|
2012-04-08 12:32:17 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
# borrow opts from makepkg
|
|
|
|
OPT_SHORT="AcdefFghiLmop:rRsV"
|
|
|
|
OPT_LONG=('allsource' 'asroot' 'ignorearch' 'check' 'clean:' 'cleanall' 'nodeps'
|
|
|
|
'noextract' 'force' 'forcever:' 'geninteg' 'help' 'holdver'
|
2013-04-28 22:42:22 -04:00
|
|
|
'install' 'key:' 'log' 'nocolor' 'nobuild' 'nocheck' 'noprepare' 'nosign' 'pkg:' 'rmdeps'
|
2012-04-08 12:32:17 -04:00
|
|
|
'repackage' 'skipinteg' 'sign' 'source' 'syncdeps' 'version' 'config:'
|
|
|
|
'noconfirm' 'noprogressbar')
|
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse() {
|
2013-11-08 00:44:40 -05:00
|
|
|
local result=$1 tokencount=$2; shift 2
|
|
|
|
parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@" 2>/dev/null
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_is_int "${#OPTRET[@]}" "$tokencount" "$* - tokencount"
|
|
|
|
tap_is_str "$result" "${OPTRET[*]}" "$* - result"
|
2013-11-08 00:44:40 -05:00
|
|
|
unset OPTRET
|
2012-04-08 12:32:17 -04:00
|
|
|
}
|
|
|
|
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_plan 50
|
2012-04-08 12:32:17 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
# usage: tap_parse <expected result> <token count> test-params...
|
|
|
|
# a failed tap_parse will match only the end of options marker '--'
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# no options
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--' 1
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# short options
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-s -r --' 3 -s -r
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# short options, no spaces
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-s -r --' 3 -sr
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# short opt missing an opt arg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--' 1 -s -p
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# short opt with an opt arg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-p PKGBUILD -L --' 4 -p PKGBUILD -L
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# short opt with an opt arg, no space
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-p PKGBUILD --' 3 -pPKGBUILD
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# valid shortopts as a long opt
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--' 1 --sir
|
2012-04-08 12:32:17 -04:00
|
|
|
|
2013-04-14 22:33:46 -04:00
|
|
|
# long opt with no optarg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--log --' 2 --log
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with missing optarg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--' 1 -sr --pkg
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with optarg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--pkg foo --' 3 --pkg foo
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with optarg with whitespace
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--pkg foo bar -- baz' 4 --pkg "foo bar" baz
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with optarg with =
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--pkg foo=bar -- baz' 4 --pkg foo=bar baz
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with explicit optarg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--pkg bar -- foo baz' 5 foo --pkg=bar baz
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with explicit optarg, with whitespace
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--pkg foo bar -- baz' 4 baz --pkg="foo bar"
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with explicit optarg that doesn't take optarg
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--' 1 --force=always -s
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# long opt with explicit optarg with =
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--pkg foo=bar --' 3 --pkg=foo=bar
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# explicit end of options with options after
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-s -r -- foo bar baz' 6 -s -r -- foo bar baz
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# non-option parameters mixed in with options
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-s -r -- foo baz' 5 -s foo baz -r
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# optarg with whitespace
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-p foo bar -s --' 4 -p'foo bar' -s
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# non-option parameter with whitespace
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '-i -- foo bar' 3 -i 'foo bar'
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# successful stem match (opt has no arg)
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--nocolor --' 2 --nocol
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# successful stem match (opt has arg)
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--config foo --' 3 --conf foo
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# ambiguous long opt
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--' 1 '--for'
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# exact match on a possible stem (--force & --forcever)
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--force --' 2 --force
|
2012-04-08 12:32:17 -04:00
|
|
|
|
|
|
|
# exact match on possible stem (opt has optarg)
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse '--clean foo --' 3 --clean=foo
|
2014-12-23 16:53:10 -05:00
|
|
|
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_finish
|
|
|
|
|
2014-12-23 16:53:10 -05:00
|
|
|
# vim: set noet:
|