From 02c0c317035796053ff9ed049c690beb0692477f Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 4 May 2023 11:50:22 +0200 Subject: [PATCH] tiny-cloud: Print usage on invalid option and add test Add test that verifies invalid option and `tiny-cloud --help` --- sbin/tiny-cloud | 4 ++-- tests/tiny-cloud.test | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100755 tests/tiny-cloud.test diff --git a/sbin/tiny-cloud b/sbin/tiny-cloud index c9f89a0..4a960fa 100755 --- a/sbin/tiny-cloud +++ b/sbin/tiny-cloud @@ -21,8 +21,8 @@ bootstrap_incomplete() { rm -f "$TINY_CLOUD_VAR/.bootstrap-complete" } -args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@") -if [ $? -ne 0 ] || [ $# -eq 0 ]; then +args=$(getopt -o hsb: --long help,setup,bootstrap: -n ${0##*/} -- "$@") || { usage >&2; exit 1; } +if [ $# -eq 0 ]; then usage >&2 exit 1 fi diff --git a/tests/tiny-cloud.test b/tests/tiny-cloud.test new file mode 100755 index 0000000..93013a2 --- /dev/null +++ b/tests/tiny-cloud.test @@ -0,0 +1,19 @@ +#!/usr/bin/env atf-sh + +. $(atf_get_srcdir)/test_env.sh + +export PREFIX="$srcdir" +export MOCK=echo + +init_tests \ + tiny_cloud_help + +tiny_cloud_help_body() { + CLOUD=nocloud atf_check -s not-exit:0 \ + -e match:"Usage" \ + tiny-cloud --invalid + + CLOUD=nocloud atf_check -s exit:0 \ + -o match:"Usage" \ + tiny-cloud --help +}