abuild: show usage on stderr on invalid options

This commit is contained in:
Natanael Copa 2022-06-15 13:31:57 +02:00
parent 0a9f7d1e31
commit f69cbe8b96
2 changed files with 23 additions and 3 deletions

View File

@ -2731,7 +2731,6 @@ usage() {
CTARGET Arch or hostspec of machine to generate compiler for
EOF
exit 0
}
APKBUILD="${APKBUILD:-./APKBUILD}"
@ -2745,7 +2744,7 @@ while getopts ":AcdD:fFhkKmnP:qrRs:uvV" opt; do
'D') DESCRIPTION=$OPTARG;;
'f') force="-f";;
'F') forceroot="-F";;
'h') usage;;
'h') usage; exit 0;;
'k') keep="-k";;
'K') keep_build="-K";;
'm') disable_colors
@ -2757,7 +2756,7 @@ while getopts ":AcdD:fFhkKmnP:qrRs:uvV" opt; do
's') SRCDEST=$OPTARG;;
'v') set -x;;
'V') echo "$program $program_version"; exit 0;;
'?') die "Unrecognized option: $OPTARG";;
'?') error "Unrecognized option: $OPTARG"; usage >&2; exit 1;;
esac
done
shift $(( $OPTIND - 1 ))

21
tests/abuild_test Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env atf-sh
. $(atf_get_srcdir)/test_env.sh
init_tests \
abuild_help \
abuild_invalid_opt
DATADIR=$(atf_get_srcdir)/testdata
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
abuild_help_body() {
atf_check -s exit:0 \
-o match:"usage:" \
abuild -h
}
abuild_invalid_opt_body() {
atf_check -s exit:1 \
-e match:"usage:" \
abuild -@
}