summaryrefslogtreecommitdiff
path: root/tests/test-help.sh
diff options
context:
space:
mode:
authorJonathan Lebon <jlebon@redhat.com>2017-09-05 14:27:20 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2017-09-13 14:32:20 +0000
commit077de8ea460562c9372f45b13a9b42867f9ad832 (patch)
tree19672d0d57403d84f6e901d7a6f69212846aea6a /tests/test-help.sh
parentec9a58f2476bbce1e0ae6f267995b64f7c85162c (diff)
downloadostree-077de8ea460562c9372f45b13a9b42867f9ad832.tar.gz
tests/test-help.sh: Rework and strengthen checks
The `sed` expression wasn't actually matching the main output, so we weren't recursing into the subcommands. Update the syntax to match the current output and add a check so we don't miss that happening again. Add a check that the help output is only printed once in all circumstances. Also add a check for proper handling of non-existent commands. Closes: #1126 Approved by: cgwalters
Diffstat (limited to 'tests/test-help.sh')
-rwxr-xr-xtests/test-help.sh61
1 files changed, 43 insertions, 18 deletions
diff --git a/tests/test-help.sh b/tests/test-help.sh
index ca555b1b..75fe0c11 100755
--- a/tests/test-help.sh
+++ b/tests/test-help.sh
@@ -23,41 +23,66 @@ set -euo pipefail
echo "1..1"
-echo "Testing:" 1>&2
+test_usage_output() {
+ file=$1; shift
+ cmd=$1; shift
+ assert_file_has_content $file '^Usage'
+ # check that it didn't print twice somehow
+ if [ "$(grep --count '^Usage' $file)" != 1 ]; then
+ _fatal_print_file "$file" "File '$file' has '^Usage' more than once."
+ fi
+ assert_file_has_content $file "$cmd"
+}
+
+# check that we found at least one command with subcommands
+found_subcommands=0
+
test_recursive() {
local cmd=$1
- local root=$2
echo "$cmd" 1>&2
$cmd --help 1>out 2>err
# --help message goes to standard output
- if [ "$root" = "1" ] ; then
- assert_file_has_content out "[Uu]sage"
- assert_file_has_content out "$cmd"
- fi
+ test_usage_output out "$cmd"
assert_file_empty err
- builtins=`sed -n '/^Builtin commands/,/^[^ ]/p' <out | tail -n +2`
+
+ builtins=`sed -n '/^Builtin \("[^"]*" \)\?Commands:$/,/^$/p' <out | tail -n +2`
if [ "$builtins" != "" ] ; then
+
+ found_subcommands=1
+
# A command with subcommands
# Running the command without a subcommand should produce the help output, but fail
- set +e
- $cmd 1>out 2>err
- if [ $? = 0 ] ; then
- echo 1>&2 "missing subcommand but 0 exit status"; exit 1
+ rc=0
+ $cmd 1>out 2>err || rc=$?
+ if [ $rc = 0 ] ; then
+ assert_not_reached "missing subcommand but 0 exit status"
fi
- set -euo pipefail
+
# error message and usage goes to standard error
- assert_file_has_content err "[Uu]sage"
- assert_file_has_content err "$cmd"
- assert_file_has_content err "Builtin commands"
+ test_usage_output err "$cmd"
+ assert_file_has_content err 'No \("[^"]*" sub\)\?command specified'
+ assert_file_empty out
+
+ rc=0
+ $cmd non-existent-subcommand 1>out 2>err || rc=$?
+ if [ $rc = 0 ] ; then
+ assert_not_reached "non-existent subcommand but 0 exit status"
+ fi
+
+ test_usage_output err "$cmd"
+ assert_file_has_content err 'Unknown \("[^"]*" sub\)\?command'
assert_file_empty out
- for subcmd in $builtins ; do
- test_recursive "$cmd $subcmd" 0
+ for subcmd in $builtins; do
+ test_recursive "$cmd $subcmd"
done
fi
}
-test_recursive ostree 1
+test_recursive ostree
+if [ $found_subcommands != 1 ]; then
+ assert_not_reached "no ostree commands with subcommands found!"
+fi
echo "ok help option is properly supported"