apkgrel: fix usage and invalid options and add test

This commit is contained in:
Natanael Copa 2022-12-01 17:25:06 +01:00
parent 115e41fd1f
commit 3695cd2008
2 changed files with 17 additions and 4 deletions

View File

@ -73,9 +73,9 @@ do_nothing() {
}
usage() {
cat >&2 <<-__EOF__
cat <<-__EOF__
$program $program_version - display or bump pkgrel in APKBUILDs
Usage: $program [-z|--zero] [-a|--add] [-g|--clean-git] [-s|--set NUM]
usage: $program [-z|--zero] [-a|--add] [-g|--clean-git] [-s|--set NUM]
[-t|--test] [-f|--force] DIR or APKBUILD...
Options:
-z, --zero Set pkgrel to 0
@ -98,7 +98,7 @@ only_clean_git=
args=$(getopt -o zags:tfqh --long zero,add,clean-git,set:,test,force,quiet,help \
-n "$program" -- "$@")
if [ $? -ne 0 ]; then
usage
usage >&2
exit 2
fi
eval set -- "$args"
@ -121,7 +121,7 @@ while true; do
shift
done
if [ $# -eq 0 ]; then
usage
usage >&2
exit 2
fi

13
tests/apkgrel_test Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/env atf-sh
. $(atf_get_srcdir)/test_env.sh
init_tests \
apkgrel_usage
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
apkgrel_usage_body() {
atf_check -o match:"usage" apkgrel -h
atf_check -s exit:2 -e match:"usage" apkgrel -Z
}