xref: /freebsd/contrib/kyua/integration/global_test.sh (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
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 no_args
31no_args_body() {
32    cat >experr <<EOF
33Usage error: No command provided.
34Type 'kyua help' for usage information.
35EOF
36
37    atf_check -s exit:3 -o empty -e file:experr kyua
38}
39
40
41utils_test_case unknown_option
42unknown_option_body() {
43    cat >experr <<EOF
44Usage error: Unknown option --this_is_unknown.
45Type 'kyua help' for usage information.
46EOF
47
48    atf_check -s exit:3 -o empty -e file:experr kyua --this_is_unknown
49}
50
51
52utils_test_case unknown_command
53unknown_command_body() {
54    cat >experr <<EOF
55Usage error: Unknown command 'i_am_not_known'.
56Type 'kyua help' for usage information.
57EOF
58
59    atf_check -s exit:3 -o empty -e file:experr kyua i_am_not_known
60}
61
62
63utils_test_case logfile__default
64logfile__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/
68}
69
70
71utils_test_case logfile__override
72logfile__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
75
76    atf_check -s exit:0 test ! -d .kyua/logs/
77    atf_check -s exit:0 test -f test.log
78
79    grep ' E .* No command provided' test.log || atf_fail "Log file does" \
80        "contain required message"
81}
82
83
84utils_test_case loglevel__default
85loglevel__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
88
89    atf_check -s exit:0 test ! -d .kyua/logs/
90    atf_check -s exit:0 test -f test.log
91
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"
96    fi
97}
98
99
100utils_test_case loglevel__lower
101loglevel__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 \
104        --loglevel=warning
105
106    atf_check -s exit:0 test ! -d .kyua/logs/
107    atf_check -s exit:0 test -f test.log
108
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"
113    fi
114}
115
116
117utils_test_case loglevel__higher
118loglevel__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 \
121        --loglevel=debug
122
123    atf_check -s exit:0 test ! -d .kyua/logs/
124    atf_check -s exit:0 test -f test.log
125
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"
129}
130
131
132atf_init_test_cases() {
133    atf_add_test_case no_args
134    atf_add_test_case unknown_option
135    atf_add_test_case unknown_command
136
137    atf_add_test_case logfile__default
138    atf_add_test_case logfile__override
139
140    atf_add_test_case loglevel__default
141    atf_add_test_case loglevel__lower
142    atf_add_test_case loglevel__higher
143
144    # Tests for the global configuration-related flags are found in the
145    # cmd_config_test test program.
146}
147