checkapk: add test, fix usage

print --help output to stdout and errors to stderr.
This commit is contained in:
Natanael Copa 2023-10-18 11:07:24 +02:00
parent 3a7fdeaaf0
commit 643637dd5d
2 changed files with 43 additions and 3 deletions

View File

@ -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
View 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
}