2014-09-25 11:05:45 +04:00
#!/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.
2016-01-27 19:44:10 +03:00
set -euo pipefail
2014-09-25 11:05:45 +04:00
. $( dirname $0 ) /libtest.sh
echo "1..1"
echo "Testing:" 1>& 2
test_recursive( ) {
local cmd = $1
2014-10-21 18:20:58 +04:00
local root = $2
2014-09-25 11:05:45 +04:00
echo " $cmd " 1>& 2
$cmd --help 1>out 2>err
# --help message goes to standard output
2015-01-30 17:15:32 +03:00
if [ " $root " = "1" ] ; then
2014-10-21 18:20:58 +04:00
assert_file_has_content out "[Uu]sage"
assert_file_has_content out " $cmd "
fi
2014-09-25 11:05:45 +04:00
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
2016-01-27 19:44:10 +03:00
set -euo pipefail
2014-09-25 11:05:45 +04:00
# 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
2014-10-21 18:20:58 +04:00
test_recursive " $cmd $subcmd " 0
2014-09-25 11:05:45 +04:00
done
fi
}
2014-10-21 18:20:58 +04:00
test_recursive ostree 1
2014-09-25 11:05:45 +04:00
echo "ok help option is properly supported"