diff options
author | Owen W. Taylor <otaylor@fishsoup.net> | 2014-09-25 03:05:45 -0400 |
---|---|---|
committer | Owen W. Taylor <otaylor@fishsoup.net> | 2014-09-25 14:28:58 -0400 |
commit | 7fce7e0338f52a328387abf6b46105547476710e (patch) | |
tree | 8a881745c0f2774bf34b4a19e74771ab17778d94 | |
parent | 3400f2d2aef70ae9abc319ddb73ed407befbe528 (diff) | |
download | ostree-7fce7e0338f52a328387abf6b46105547476710e.tar.gz |
Add test for the behavior of --help
Recursive over ostree and all subcommands, and check that --help
is supported, properly outputs to standard out, and exits
with a 0 exit status. Check that for commands with subcommands,
they produce the help output to standard error when run with no arguments.
https://bugzilla.gnome.org/show_bug.cgi?id=737194
-rw-r--r-- | Makefile-tests.am | 1 | ||||
-rw-r--r-- | tests/libtest.sh | 6 | ||||
-rwxr-xr-x | tests/test-help.sh | 59 |
3 files changed, 66 insertions, 0 deletions
diff --git a/Makefile-tests.am b/Makefile-tests.am index 03a2ff6a..5d07e9ee 100644 --- a/Makefile-tests.am +++ b/Makefile-tests.am @@ -27,6 +27,7 @@ testfiles = test-basic \ test-archivez \ test-remote-add \ test-commit-sign \ + test-help \ test-libarchive \ test-pull-archive-z \ test-pull-corruption \ diff --git a/tests/libtest.sh b/tests/libtest.sh index 7d726a5c..e9d4450c 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -78,6 +78,12 @@ assert_file_has_content () { fi } +assert_file_empty() { + if test -s "$1"; then + echo 1>&2 "File '$1' is not empty"; exit 1 + fi +} + setup_test_repository () { mode=$1 shift diff --git a/tests/test-help.sh b/tests/test-help.sh new file mode 100755 index 00000000..db7f65d7 --- /dev/null +++ b/tests/test-help.sh @@ -0,0 +1,59 @@ +#!/bin/bash +# +# Copyright (C) 2014 Owen Taylor <otaylor@redhat.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +set -e + +. $(dirname $0)/libtest.sh + +echo "1..1" + +echo "Testing:" 1>&2 +test_recursive() { + local cmd=$1 + echo "$cmd" 1>&2 + $cmd --help 1>out 2>err + # --help message goes to standard output + assert_file_has_content out "[Uu]sage" + assert_file_has_content out "$cmd" + assert_file_empty err + builtins=`sed -n '/^Builtin commands/,/^[^ ]/p' <out | tail -n +2` + if [ "$builtins" != "" ] ; then + # 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 + fi + set -e + # 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" + assert_file_empty out + + for subcmd in $builtins ; do + test_recursive "$cmd $subcmd" + done + fi +} + +test_recursive ostree + +echo "ok help option is properly supported" |