1# Copyright 2011 Google Inc.
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met:
7#
8# * Redistributions of source code must retain the above copyright
9#   notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright
11#   notice, this list of conditions and the following disclaimer in the
12#   documentation and/or other materials provided with the distribution.
13# * Neither the name of Google Inc. nor the names of its contributors
14#   may be used to endorse or promote products derived from this software
15#   without specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
30utils_test_case global
31global_body() {
32    atf_check -s exit:0 -o save:stdout -e empty kyua help
33    grep '^Usage: kyua' stdout || atf_fail 'No usage line printed'
34    grep -- '--loglevel' stdout || atf_fail 'Generic options not printed'
35    if grep -- '--show' stdout; then
36        atf_fail 'One option of the about subcommand appeared in the output'
37    fi
38    grep 'about  *Shows general' stdout || atf_fail 'Commands not printed'
39}
40
41
42utils_test_case one_command
43one_command_body() {
44    atf_check -s exit:0 -o save:stdout -e empty kyua help test
45    grep '^Usage: kyua' stdout || atf_fail 'No usage line printed'
46    grep '^Run tests' stdout || atf_fail 'No description printed'
47    grep -- '--loglevel' stdout || atf_fail 'Generic options not printed'
48    grep -- '--kyuafile' stdout || atf_fail 'Command options not printed'
49    if grep 'about: Shows general' stdout; then
50        atf_fail 'Printed table of commands, but should not have done so'
51    fi
52}
53
54
55utils_test_case ignore_bad_config
56ignore_bad_config_body() {
57    echo 'this is an invalid configuration file' >bad-config
58    atf_check -s exit:0 -o save:stdout -e empty kyua -c bad-config help
59    grep '^Usage: kyua' stdout || atf_fail 'No usage line printed'
60    grep -- '--loglevel' stdout || atf_fail 'Generic options not printed'
61}
62
63
64utils_test_case unknown_command
65unknown_command_body() {
66    cat >stderr <<EOF
67Usage error for command help: The command abc does not exist.
68Type 'kyua help help' for usage information.
69EOF
70    atf_check -s exit:3 -o empty -e file:stderr kyua help abc
71}
72
73
74utils_test_case too_many_arguments
75too_many_arguments_body() {
76    cat >stderr <<EOF
77Usage error for command help: Too many arguments.
78Type 'kyua help help' for usage information.
79EOF
80    atf_check -s exit:3 -o empty -e file:stderr kyua help about cde
81}
82
83
84atf_init_test_cases() {
85    atf_add_test_case global
86    atf_add_test_case one_command
87
88    atf_add_test_case ignore_bad_config
89    atf_add_test_case unknown_command
90    atf_add_test_case too_many_arguments
91}
92