1*11be35a1SLionel Sambuc# Copyright 2011 Google Inc. 2*11be35a1SLionel Sambuc# All rights reserved. 3*11be35a1SLionel Sambuc# 4*11be35a1SLionel Sambuc# Redistribution and use in source and binary forms, with or without 5*11be35a1SLionel Sambuc# modification, are permitted provided that the following conditions are 6*11be35a1SLionel Sambuc# met: 7*11be35a1SLionel Sambuc# 8*11be35a1SLionel Sambuc# * Redistributions of source code must retain the above copyright 9*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer. 10*11be35a1SLionel Sambuc# * Redistributions in binary form must reproduce the above copyright 11*11be35a1SLionel Sambuc# notice, this list of conditions and the following disclaimer in the 12*11be35a1SLionel Sambuc# documentation and/or other materials provided with the distribution. 13*11be35a1SLionel Sambuc# * Neither the name of Google Inc. nor the names of its contributors 14*11be35a1SLionel Sambuc# may be used to endorse or promote products derived from this software 15*11be35a1SLionel Sambuc# without specific prior written permission. 16*11be35a1SLionel Sambuc# 17*11be35a1SLionel Sambuc# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18*11be35a1SLionel Sambuc# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19*11be35a1SLionel Sambuc# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20*11be35a1SLionel Sambuc# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21*11be35a1SLionel Sambuc# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22*11be35a1SLionel Sambuc# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23*11be35a1SLionel Sambuc# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*11be35a1SLionel Sambuc# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*11be35a1SLionel Sambuc# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*11be35a1SLionel Sambuc# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27*11be35a1SLionel Sambuc# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*11be35a1SLionel Sambuc 29*11be35a1SLionel Sambuc 30*11be35a1SLionel Sambucutils_test_case no_args 31*11be35a1SLionel Sambucno_args_body() { 32*11be35a1SLionel Sambuc cat >experr <<EOF 33*11be35a1SLionel SambucUsage error: No command provided. 34*11be35a1SLionel SambucType 'kyua help' for usage information. 35*11be35a1SLionel SambucEOF 36*11be35a1SLionel Sambuc 37*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e file:experr kyua 38*11be35a1SLionel Sambuc} 39*11be35a1SLionel Sambuc 40*11be35a1SLionel Sambuc 41*11be35a1SLionel Sambucutils_test_case unknown_option 42*11be35a1SLionel Sambucunknown_option_body() { 43*11be35a1SLionel Sambuc cat >experr <<EOF 44*11be35a1SLionel SambucUsage error: Unknown option --this_is_unknown. 45*11be35a1SLionel SambucType 'kyua help' for usage information. 46*11be35a1SLionel SambucEOF 47*11be35a1SLionel Sambuc 48*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e file:experr kyua --this_is_unknown 49*11be35a1SLionel Sambuc} 50*11be35a1SLionel Sambuc 51*11be35a1SLionel Sambuc 52*11be35a1SLionel Sambucutils_test_case unknown_command 53*11be35a1SLionel Sambucunknown_command_body() { 54*11be35a1SLionel Sambuc cat >experr <<EOF 55*11be35a1SLionel SambucUsage error: Unknown command 'i_am_not_known'. 56*11be35a1SLionel SambucType 'kyua help' for usage information. 57*11be35a1SLionel SambucEOF 58*11be35a1SLionel Sambuc 59*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e file:experr kyua i_am_not_known 60*11be35a1SLionel Sambuc} 61*11be35a1SLionel Sambuc 62*11be35a1SLionel Sambuc 63*11be35a1SLionel Sambucutils_test_case logfile__default 64*11be35a1SLionel Sambuclogfile__default_body() { 65*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -d .kyua/logs/ 66*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e ignore kyua 67*11be35a1SLionel Sambuc atf_check -s exit:0 test -d .kyua/logs/ 68*11be35a1SLionel Sambuc} 69*11be35a1SLionel Sambuc 70*11be35a1SLionel Sambuc 71*11be35a1SLionel Sambucutils_test_case logfile__override 72*11be35a1SLionel Sambuclogfile__override_body() { 73*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -f test.log 74*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log 75*11be35a1SLionel Sambuc 76*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -d .kyua/logs/ 77*11be35a1SLionel Sambuc atf_check -s exit:0 test -f test.log 78*11be35a1SLionel Sambuc 79*11be35a1SLionel Sambuc grep ' E .* No command provided' test.log || atf_fail "Log file does" \ 80*11be35a1SLionel Sambuc "contain required message" 81*11be35a1SLionel Sambuc} 82*11be35a1SLionel Sambuc 83*11be35a1SLionel Sambuc 84*11be35a1SLionel Sambucutils_test_case loglevel__default 85*11be35a1SLionel Sambucloglevel__default_body() { 86*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -f test.log 87*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log 88*11be35a1SLionel Sambuc 89*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -d .kyua/logs/ 90*11be35a1SLionel Sambuc atf_check -s exit:0 test -f test.log 91*11be35a1SLionel Sambuc 92*11be35a1SLionel Sambuc grep ' E .* No command provided' test.log || atf_fail "Log file does" \ 93*11be35a1SLionel Sambuc "contain required message" 94*11be35a1SLionel Sambuc if grep ' D ' test.log; then 95*11be35a1SLionel Sambuc atf_fail "Log file contains debug messages but it should not" 96*11be35a1SLionel Sambuc fi 97*11be35a1SLionel Sambuc} 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambuc 100*11be35a1SLionel Sambucutils_test_case loglevel__lower 101*11be35a1SLionel Sambucloglevel__lower_body() { 102*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -f test.log 103*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log \ 104*11be35a1SLionel Sambuc --loglevel=warning 105*11be35a1SLionel Sambuc 106*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -d .kyua/logs/ 107*11be35a1SLionel Sambuc atf_check -s exit:0 test -f test.log 108*11be35a1SLionel Sambuc 109*11be35a1SLionel Sambuc grep ' E .* No command provided' test.log || atf_fail "Log file does" \ 110*11be35a1SLionel Sambuc "contain required message" 111*11be35a1SLionel Sambuc if grep ' I ' test.log; then 112*11be35a1SLionel Sambuc atf_fail "Log file contains info messages but it should not" 113*11be35a1SLionel Sambuc fi 114*11be35a1SLionel Sambuc} 115*11be35a1SLionel Sambuc 116*11be35a1SLionel Sambuc 117*11be35a1SLionel Sambucutils_test_case loglevel__higher 118*11be35a1SLionel Sambucloglevel__higher_body() { 119*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -f test.log 120*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e ignore kyua --logfile=test.log \ 121*11be35a1SLionel Sambuc --loglevel=debug 122*11be35a1SLionel Sambuc 123*11be35a1SLionel Sambuc atf_check -s exit:0 test ! -d .kyua/logs/ 124*11be35a1SLionel Sambuc atf_check -s exit:0 test -f test.log 125*11be35a1SLionel Sambuc 126*11be35a1SLionel Sambuc grep ' E .* No command provided' test.log || atf_fail "Log file does" \ 127*11be35a1SLionel Sambuc "contain required message" 128*11be35a1SLionel Sambuc grep ' D ' test.log || atf_fail "Log file does not contain debug messages" 129*11be35a1SLionel Sambuc} 130*11be35a1SLionel Sambuc 131*11be35a1SLionel Sambuc 132*11be35a1SLionel Sambucatf_init_test_cases() { 133*11be35a1SLionel Sambuc atf_add_test_case no_args 134*11be35a1SLionel Sambuc atf_add_test_case unknown_option 135*11be35a1SLionel Sambuc atf_add_test_case unknown_command 136*11be35a1SLionel Sambuc 137*11be35a1SLionel Sambuc atf_add_test_case logfile__default 138*11be35a1SLionel Sambuc atf_add_test_case logfile__override 139*11be35a1SLionel Sambuc 140*11be35a1SLionel Sambuc atf_add_test_case loglevel__default 141*11be35a1SLionel Sambuc atf_add_test_case loglevel__lower 142*11be35a1SLionel Sambuc atf_add_test_case loglevel__higher 143*11be35a1SLionel Sambuc 144*11be35a1SLionel Sambuc # Tests for the global configuration-related flags are found in the 145*11be35a1SLionel Sambuc # cmd_config_test test program. 146*11be35a1SLionel Sambuc} 147