1# Copyright 2011 The Kyua Authors.
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 -E 'kyua .*[0-9]+\.[0-9]+' stdout || atf_fail 'No version reported'
34    grep '^Usage: kyua' stdout || atf_fail 'No usage line printed'
35    grep -- '--loglevel' stdout || atf_fail 'Generic options not printed'
36    if grep -- '--show' stdout; then
37        atf_fail 'One option of the about subcommand appeared in the output'
38    fi
39    grep 'about  *Shows detailed' stdout || atf_fail 'Commands not printed'
40}
41
42
43utils_test_case one_command
44one_command_body() {
45    atf_check -s exit:0 -o save:stdout -e empty kyua help test
46    grep -E 'kyua .*[0-9]+\.[0-9]+' stdout || atf_fail 'No version reported'
47    grep '^Usage: kyua' stdout || atf_fail 'No usage line printed'
48    grep '^Run tests' stdout || atf_fail 'No description printed'
49    grep -- '--loglevel' stdout || atf_fail 'Generic options not printed'
50    grep -- '--kyuafile' stdout || atf_fail 'Command options not printed'
51    if grep 'about: Shows detailed' stdout; then
52        atf_fail 'Printed table of commands, but should not have done so'
53    fi
54}
55
56
57utils_test_case ignore_bad_config
58ignore_bad_config_body() {
59    echo 'this is an invalid configuration file' >bad-config
60    atf_check -s exit:0 -o save:stdout -e empty kyua -c bad-config help
61    grep '^Usage: kyua' stdout || atf_fail 'No usage line printed'
62    grep -- '--loglevel' stdout || atf_fail 'Generic options not printed'
63}
64
65
66utils_test_case unknown_command
67unknown_command_body() {
68    cat >stderr <<EOF
69Usage error for command help: The command abc does not exist.
70Type 'kyua help help' for usage information.
71EOF
72    atf_check -s exit:3 -o empty -e file:stderr kyua help abc
73}
74
75
76utils_test_case too_many_arguments
77too_many_arguments_body() {
78    cat >stderr <<EOF
79Usage error for command help: Too many arguments.
80Type 'kyua help help' for usage information.
81EOF
82    atf_check -s exit:3 -o empty -e file:stderr kyua help about cde
83}
84
85
86atf_init_test_cases() {
87    atf_add_test_case global
88    atf_add_test_case one_command
89
90    atf_add_test_case ignore_bad_config
91    atf_add_test_case unknown_command
92    atf_add_test_case too_many_arguments
93}
94