1 # Copyright 2011 The Kyua Authors.
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
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.
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.
30 utils_test_case no_args
33 Usage error: No command provided.
34 Type 'kyua help' for usage information.
37 atf_check -s exit:3 -o empty -e file:experr kyua
41 utils_test_case unknown_option
42 unknown_option_body() {
44 Usage error: Unknown option --this_is_unknown.
45 Type 'kyua help' for usage information.
48 atf_check -s exit:3 -o empty -e file:experr kyua --this_is_unknown
52 utils_test_case unknown_command
53 unknown_command_body() {
55 Usage error: Unknown command 'i_am_not_known'.
56 Type 'kyua help' for usage information.
59 atf_check -s exit:3 -o empty -e file:experr kyua i_am_not_known
63 utils_test_case logfile__default
64 logfile__default_body() {
65 atf_check -s exit:0 test ! -d .kyua/logs/
66 atf_check -s exit:3 -o empty -e ignore kyua
67 atf_check -s exit:0 test -d .kyua/logs/
71 utils_test_case logfile__override
72 logfile__override_body() {
73 atf_check -s exit:0 test ! -f test.log
74 atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log
76 atf_check -s exit:0 test ! -d .kyua/logs/
77 atf_check -s exit:0 test -f test.log
79 grep ' E .* No command provided' test.log || atf_fail "Log file does" \
80 "contain required message"
84 utils_test_case loglevel__default
85 loglevel__default_body() {
86 atf_check -s exit:0 test ! -f test.log
87 atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log
89 atf_check -s exit:0 test ! -d .kyua/logs/
90 atf_check -s exit:0 test -f test.log
92 grep ' E .* No command provided' test.log || atf_fail "Log file does" \
93 "contain required message"
94 if grep ' D ' test.log; then
95 atf_fail "Log file contains debug messages but it should not"
100 utils_test_case loglevel__lower
101 loglevel__lower_body() {
102 atf_check -s exit:0 test ! -f test.log
103 atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log \
106 atf_check -s exit:0 test ! -d .kyua/logs/
107 atf_check -s exit:0 test -f test.log
109 grep ' E .* No command provided' test.log || atf_fail "Log file does" \
110 "contain required message"
111 if grep ' I ' test.log; then
112 atf_fail "Log file contains info messages but it should not"
117 utils_test_case loglevel__higher
118 loglevel__higher_body() {
119 atf_check -s exit:0 test ! -f test.log
120 atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log \
123 atf_check -s exit:0 test ! -d .kyua/logs/
124 atf_check -s exit:0 test -f test.log
126 grep ' E .* No command provided' test.log || atf_fail "Log file does" \
127 "contain required message"
128 grep ' D ' test.log || atf_fail "Log file does not contain debug messages"
132 atf_init_test_cases() {
133 atf_add_test_case no_args
134 atf_add_test_case unknown_option
135 atf_add_test_case unknown_command
137 atf_add_test_case logfile__default
138 atf_add_test_case logfile__override
140 atf_add_test_case loglevel__default
141 atf_add_test_case loglevel__lower
142 atf_add_test_case loglevel__higher
144 # Tests for the global configuration-related flags are found in the
145 # cmd_config_test test program.