mirror of
https://gitlab.alpinelinux.org/alpine/abuild.git
synced 2024-12-22 07:00:28 +00:00
checkapk: add test, fix usage
print --help output to stdout and errors to stderr.
This commit is contained in:
parent
3a7fdeaaf0
commit
643637dd5d
26
checkapk.in
26
checkapk.in
@ -17,17 +17,37 @@ fi
|
||||
|
||||
|
||||
usage() {
|
||||
cat >&2 <<-__EOF__
|
||||
cat <<-__EOF__
|
||||
$program $program_version - find ABI breakages in package upgrades
|
||||
Usage: $program
|
||||
Usage: $program [-h|--help]
|
||||
|
||||
Run in the directory of a built package.
|
||||
|
||||
Options:
|
||||
-h, --help Print this help
|
||||
|
||||
__EOF__
|
||||
}
|
||||
|
||||
args=$(getopt -o h --long help \
|
||||
-n "$program" -- "$@")
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
eval set -- "$args"
|
||||
while true; do
|
||||
case $1 in
|
||||
-h|--help) usage; exit 0;;
|
||||
--) shift; break;;
|
||||
*) exit 1;; # getopt error
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
usage
|
||||
usage >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
20
tests/checkapk_test
Executable file
20
tests/checkapk_test
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env atf-sh
|
||||
|
||||
. $(atf_get_srcdir)/test_env.sh
|
||||
init_tests \
|
||||
checkapk_help \
|
||||
checkapk_invalid_opt
|
||||
|
||||
DATADIR=$(atf_get_srcdir)/testdata
|
||||
|
||||
checkapk_help_body() {
|
||||
atf_check -s exit:0 \
|
||||
-o match:"Usage:" \
|
||||
checkapk --help
|
||||
}
|
||||
|
||||
checkapk_invalid_opt_body() {
|
||||
atf_check -s not-exit:0 \
|
||||
-e match:"Usage:" \
|
||||
checkapk --invalid
|
||||
}
|
Loading…
Reference in New Issue
Block a user