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 defaults 31*11be35a1SLionel Sambucdefaults_body() { 32*11be35a1SLionel Sambuc atf_check -s exit:0 \ 33*11be35a1SLionel Sambuc -o match:'^architecture = ' \ 34*11be35a1SLionel Sambuc -o match:'^platform = ' \ 35*11be35a1SLionel Sambuc kyua config 36*11be35a1SLionel Sambuc} 37*11be35a1SLionel Sambuc 38*11be35a1SLionel Sambuc 39*11be35a1SLionel Sambucutils_test_case all 40*11be35a1SLionel Sambucall_body() { 41*11be35a1SLionel Sambuc mkdir "${HOME}/.kyua" 42*11be35a1SLionel Sambuc cat >"${HOME}/.kyua/kyua.conf" <<EOF 43*11be35a1SLionel Sambucsyntax(2) 44*11be35a1SLionel Sambucarchitecture = "my-architecture" 45*11be35a1SLionel Sambucplatform = "my-platform" 46*11be35a1SLionel Sambucunprivileged_user = "$(id -u -n)" 47*11be35a1SLionel Sambuctest_suites.suite1["X-the-variable"] = "value1" 48*11be35a1SLionel Sambuctest_suites.suite2["X-the-variable"] = "value2" 49*11be35a1SLionel SambucEOF 50*11be35a1SLionel Sambuc 51*11be35a1SLionel Sambuc cat >expout <<EOF 52*11be35a1SLionel Sambucarchitecture = my-architecture 53*11be35a1SLionel Sambucplatform = my-platform 54*11be35a1SLionel Sambuctest_suites.suite1.X-the-variable = value1 55*11be35a1SLionel Sambuctest_suites.suite2.X-the-variable = value2 56*11be35a1SLionel Sambucunprivileged_user = $(id -u -n) 57*11be35a1SLionel SambucEOF 58*11be35a1SLionel Sambuc 59*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:expout -e empty kyua config 60*11be35a1SLionel Sambuc} 61*11be35a1SLionel Sambuc 62*11be35a1SLionel Sambuc 63*11be35a1SLionel Sambucutils_test_case one__ok 64*11be35a1SLionel Sambucone__ok_body() { 65*11be35a1SLionel Sambuc mkdir "${HOME}/.kyua" 66*11be35a1SLionel Sambuc cat >"${HOME}/.kyua/kyua.conf" <<EOF 67*11be35a1SLionel Sambucsyntax(2) 68*11be35a1SLionel Sambuctest_suites.first["X-one"] = 1 69*11be35a1SLionel Sambuctest_suites.first["X-two"] = 2 70*11be35a1SLionel SambucEOF 71*11be35a1SLionel Sambuc 72*11be35a1SLionel Sambuc cat >expout <<EOF 73*11be35a1SLionel Sambuctest_suites.first.X-two = 2 74*11be35a1SLionel SambucEOF 75*11be35a1SLionel Sambuc 76*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:expout -e empty kyua config \ 77*11be35a1SLionel Sambuc test_suites.first.X-two 78*11be35a1SLionel Sambuc} 79*11be35a1SLionel Sambuc 80*11be35a1SLionel Sambuc 81*11be35a1SLionel Sambucutils_test_case one__fail 82*11be35a1SLionel Sambucone__fail_body() { 83*11be35a1SLionel Sambuc mkdir "${HOME}/.kyua" 84*11be35a1SLionel Sambuc cat >"${HOME}/.kyua/kyua.conf" <<EOF 85*11be35a1SLionel Sambucsyntax(2) 86*11be35a1SLionel Sambuctest_suites.first["X-one"] = 1 87*11be35a1SLionel Sambuctest_suites.first["X-three"] = 3 88*11be35a1SLionel SambucEOF 89*11be35a1SLionel Sambuc 90*11be35a1SLionel Sambuc cat >experr <<EOF 91*11be35a1SLionel Sambuckyua: W: 'test_suites.first.X-two' is not defined. 92*11be35a1SLionel SambucEOF 93*11be35a1SLionel Sambuc 94*11be35a1SLionel Sambuc atf_check -s exit:1 -o empty -e file:experr kyua config \ 95*11be35a1SLionel Sambuc test_suites.first.X-two 96*11be35a1SLionel Sambuc} 97*11be35a1SLionel Sambuc 98*11be35a1SLionel Sambuc 99*11be35a1SLionel Sambucutils_test_case many__ok 100*11be35a1SLionel Sambucmany__ok_body() { 101*11be35a1SLionel Sambuc mkdir "${HOME}/.kyua" 102*11be35a1SLionel Sambuc cat >"${HOME}/.kyua/kyua.conf" <<EOF 103*11be35a1SLionel Sambucsyntax(2) 104*11be35a1SLionel Sambuctest_suites.first["X-one"] = 1 105*11be35a1SLionel Sambuctest_suites.first["X-two"] = 2 106*11be35a1SLionel SambucEOF 107*11be35a1SLionel Sambuc 108*11be35a1SLionel Sambuc cat >expout <<EOF 109*11be35a1SLionel Sambuctest_suites.first.X-two = 2 110*11be35a1SLionel Sambuctest_suites.first.X-one = 1 111*11be35a1SLionel SambucEOF 112*11be35a1SLionel Sambuc 113*11be35a1SLionel Sambuc atf_check -s exit:0 -o file:expout -e empty kyua config \ 114*11be35a1SLionel Sambuc test_suites.first.X-two \ 115*11be35a1SLionel Sambuc test_suites.first.X-one # Inverse order on purpose. 116*11be35a1SLionel Sambuc} 117*11be35a1SLionel Sambuc 118*11be35a1SLionel Sambuc 119*11be35a1SLionel Sambucutils_test_case many__fail 120*11be35a1SLionel Sambucmany__fail_body() { 121*11be35a1SLionel Sambuc mkdir "${HOME}/.kyua" 122*11be35a1SLionel Sambuc cat >"${HOME}/.kyua/kyua.conf" <<EOF 123*11be35a1SLionel Sambucsyntax(2) 124*11be35a1SLionel Sambuctest_suites.first["X-one"] = 1 125*11be35a1SLionel Sambuctest_suites.first["X-three"] = 3 126*11be35a1SLionel SambucEOF 127*11be35a1SLionel Sambuc 128*11be35a1SLionel Sambuc cat >expout <<EOF 129*11be35a1SLionel Sambuctest_suites.first.X-one = 1 130*11be35a1SLionel Sambuctest_suites.first.X-three = 3 131*11be35a1SLionel SambucEOF 132*11be35a1SLionel Sambuc 133*11be35a1SLionel Sambuc cat >experr <<EOF 134*11be35a1SLionel Sambuckyua: W: 'test_suites.first.X-two' is not defined. 135*11be35a1SLionel Sambuckyua: W: 'test_suites.first.X-fourth' is not defined. 136*11be35a1SLionel SambucEOF 137*11be35a1SLionel Sambuc 138*11be35a1SLionel Sambuc atf_check -s exit:1 -o file:expout -e file:experr kyua config \ 139*11be35a1SLionel Sambuc test_suites.first.X-one test_suites.first.X-two \ 140*11be35a1SLionel Sambuc test_suites.first.X-three test_suites.first.X-fourth 141*11be35a1SLionel Sambuc} 142*11be35a1SLionel Sambuc 143*11be35a1SLionel Sambuc 144*11be35a1SLionel Sambucutils_test_case config_flag__default_system 145*11be35a1SLionel Sambucconfig_flag__default_system_body() { 146*11be35a1SLionel Sambuc cat >kyua.conf <<EOF 147*11be35a1SLionel Sambucsyntax(2) 148*11be35a1SLionel Sambuctest_suites.foo["X-var"] = "baz" 149*11be35a1SLionel SambucEOF 150*11be35a1SLionel Sambuc 151*11be35a1SLionel Sambuc atf_check -s exit:1 -o empty \ 152*11be35a1SLionel Sambuc -e match:"kyua: W: 'test_suites.foo.X-var'.*not defined" \ 153*11be35a1SLionel Sambuc kyua config test_suites.foo.X-var 154*11be35a1SLionel Sambuc export KYUA_CONFDIR="$(pwd)" 155*11be35a1SLionel Sambuc atf_check -s exit:0 -o match:"foo.X-var = baz" -e empty \ 156*11be35a1SLionel Sambuc kyua config test_suites.foo.X-var 157*11be35a1SLionel Sambuc} 158*11be35a1SLionel Sambuc 159*11be35a1SLionel Sambuc 160*11be35a1SLionel Sambucutils_test_case config_flag__default_home 161*11be35a1SLionel Sambucconfig_flag__default_home_body() { 162*11be35a1SLionel Sambuc cat >kyua.conf <<EOF 163*11be35a1SLionel Sambucsyntax(2) 164*11be35a1SLionel Sambuctest_suites.foo["X-var"] = "bar" 165*11be35a1SLionel SambucEOF 166*11be35a1SLionel Sambuc export KYUA_CONFDIR="$(pwd)" 167*11be35a1SLionel Sambuc atf_check -s exit:0 -o match:"test_suites.foo.X-var = bar" -e empty \ 168*11be35a1SLionel Sambuc kyua config test_suites.foo.X-var 169*11be35a1SLionel Sambuc 170*11be35a1SLionel Sambuc # The previously-created "system-wide" file has to be ignored. 171*11be35a1SLionel Sambuc mkdir .kyua 172*11be35a1SLionel Sambuc cat >.kyua/kyua.conf <<EOF 173*11be35a1SLionel Sambucsyntax(2) 174*11be35a1SLionel Sambuctest_suites.foo["X-var"] = "baz" 175*11be35a1SLionel SambucEOF 176*11be35a1SLionel Sambuc atf_check -s exit:0 -o match:"test_suites.foo.X-var = baz" -e empty \ 177*11be35a1SLionel Sambuc kyua config test_suites.foo.X-var 178*11be35a1SLionel Sambuc} 179*11be35a1SLionel Sambuc 180*11be35a1SLionel Sambuc 181*11be35a1SLionel Sambucutils_test_case config_flag__explicit__ok 182*11be35a1SLionel Sambucconfig_flag__explicit__ok_body() { 183*11be35a1SLionel Sambuc cat >kyua.conf <<EOF 184*11be35a1SLionel Sambucsyntax(2) 185*11be35a1SLionel Sambuctest_suites.foo["X-var"] = "baz" 186*11be35a1SLionel SambucEOF 187*11be35a1SLionel Sambuc 188*11be35a1SLionel Sambuc atf_check -s exit:1 -o empty \ 189*11be35a1SLionel Sambuc -e match:"kyua: W: 'test_suites.foo.X-var'.*not defined" \ 190*11be35a1SLionel Sambuc kyua config test_suites.foo.X-var 191*11be35a1SLionel Sambuc atf_check -s exit:0 -o match:"test_suites.foo.X-var = baz" -e empty \ 192*11be35a1SLionel Sambuc kyua -c kyua.conf config test_suites.foo.X-var 193*11be35a1SLionel Sambuc atf_check -s exit:0 -o match:"test_suites.foo.X-var = baz" -e empty \ 194*11be35a1SLionel Sambuc kyua --config=kyua.conf config test_suites.foo.X-var 195*11be35a1SLionel Sambuc} 196*11be35a1SLionel Sambuc 197*11be35a1SLionel Sambuc 198*11be35a1SLionel Sambucutils_test_case config_flag__explicit__disable 199*11be35a1SLionel Sambucconfig_flag__explicit__disable_body() { 200*11be35a1SLionel Sambuc cat >kyua.conf <<EOF 201*11be35a1SLionel Sambucsyntax(2) 202*11be35a1SLionel Sambuctest_suites.foo["X-var"] = "baz" 203*11be35a1SLionel SambucEOF 204*11be35a1SLionel Sambuc mkdir .kyua 205*11be35a1SLionel Sambuc cp kyua.conf .kyua/kyua.conf 206*11be35a1SLionel Sambuc export KYUA_CONFDIR="$(pwd)" 207*11be35a1SLionel Sambuc 208*11be35a1SLionel Sambuc atf_check -s exit:0 -o match:"test_suites.foo.X-var = baz" -e empty \ 209*11be35a1SLionel Sambuc kyua config test_suites.foo.X-var 210*11be35a1SLionel Sambuc atf_check -s exit:1 -o empty \ 211*11be35a1SLionel Sambuc -e match:"kyua: W: 'test_suites.foo.X-var'.*not defined" \ 212*11be35a1SLionel Sambuc kyua --config=none config test_suites.foo.X-var 213*11be35a1SLionel Sambuc} 214*11be35a1SLionel Sambuc 215*11be35a1SLionel Sambuc 216*11be35a1SLionel Sambucutils_test_case config_flag__explicit__missing_file 217*11be35a1SLionel Sambucconfig_flag__explicit__missing_file_body() { 218*11be35a1SLionel Sambuc cat >experr <<EOF 219*11be35a1SLionel Sambuckyua: E: Load of 'foo' failed: File 'foo' not found. 220*11be35a1SLionel SambucEOF 221*11be35a1SLionel Sambuc atf_check -s exit:2 -o empty -e file:experr kyua --config=foo config 222*11be35a1SLionel Sambuc} 223*11be35a1SLionel Sambuc 224*11be35a1SLionel Sambuc 225*11be35a1SLionel Sambucutils_test_case config_flag__explicit__bad_file 226*11be35a1SLionel Sambucconfig_flag__explicit__bad_file_body() { 227*11be35a1SLionel Sambuc touch custom 228*11be35a1SLionel Sambuc atf_check -s exit:2 -o empty -e match:"No syntax defined" \ 229*11be35a1SLionel Sambuc kyua --config=custom config 230*11be35a1SLionel Sambuc} 231*11be35a1SLionel Sambuc 232*11be35a1SLionel Sambuc 233*11be35a1SLionel Sambucutils_test_case variable_flag__no_config 234*11be35a1SLionel Sambucvariable_flag__no_config_body() { 235*11be35a1SLionel Sambuc atf_check -s exit:0 \ 236*11be35a1SLionel Sambuc -o match:'test_suites.suite1.X-the-variable = value1' \ 237*11be35a1SLionel Sambuc -o match:'test_suites.suite2.X-the-variable = value2' \ 238*11be35a1SLionel Sambuc -e empty \ 239*11be35a1SLionel Sambuc kyua \ 240*11be35a1SLionel Sambuc -v "test_suites.suite1.X-the-variable=value1" \ 241*11be35a1SLionel Sambuc -v "test_suites.suite2.X-the-variable=value2" \ 242*11be35a1SLionel Sambuc config 243*11be35a1SLionel Sambuc 244*11be35a1SLionel Sambuc atf_check -s exit:0 \ 245*11be35a1SLionel Sambuc -o match:'test_suites.suite1.X-the-variable = value1' \ 246*11be35a1SLionel Sambuc -o match:'test_suites.suite2.X-the-variable = value2' \ 247*11be35a1SLionel Sambuc -e empty \ 248*11be35a1SLionel Sambuc kyua \ 249*11be35a1SLionel Sambuc --variable="test_suites.suite1.X-the-variable=value1" \ 250*11be35a1SLionel Sambuc --variable="test_suites.suite2.X-the-variable=value2" \ 251*11be35a1SLionel Sambuc config 252*11be35a1SLionel Sambuc} 253*11be35a1SLionel Sambuc 254*11be35a1SLionel Sambuc 255*11be35a1SLionel Sambucutils_test_case variable_flag__override_default_config 256*11be35a1SLionel Sambucvariable_flag__override_default_config_body() { 257*11be35a1SLionel Sambuc mkdir "${HOME}/.kyua" 258*11be35a1SLionel Sambuc cat >"${HOME}/.kyua/kyua.conf" <<EOF 259*11be35a1SLionel Sambucsyntax(2) 260*11be35a1SLionel Sambuctest_suites.suite1["X-the-variable"] = "value1" 261*11be35a1SLionel Sambuctest_suites.suite2["X-the-variable"] = "should not be used" 262*11be35a1SLionel SambucEOF 263*11be35a1SLionel Sambuc 264*11be35a1SLionel Sambuc atf_check -s exit:0 \ 265*11be35a1SLionel Sambuc -o match:'test_suites.suite1.X-the-variable = value1' \ 266*11be35a1SLionel Sambuc -o match:'test_suites.suite2.X-the-variable = overriden' \ 267*11be35a1SLionel Sambuc -o match:'test_suites.suite3.X-the-variable = new' \ 268*11be35a1SLionel Sambuc -e empty kyua \ 269*11be35a1SLionel Sambuc -v "test_suites.suite2.X-the-variable=overriden" \ 270*11be35a1SLionel Sambuc -v "test_suites.suite3.X-the-variable=new" \ 271*11be35a1SLionel Sambuc config 272*11be35a1SLionel Sambuc 273*11be35a1SLionel Sambuc atf_check -s exit:0 \ 274*11be35a1SLionel Sambuc -o match:'test_suites.suite1.X-the-variable = value1' \ 275*11be35a1SLionel Sambuc -o match:'test_suites.suite2.X-the-variable = overriden' \ 276*11be35a1SLionel Sambuc -o match:'test_suites.suite3.X-the-variable = new' \ 277*11be35a1SLionel Sambuc -e empty kyua \ 278*11be35a1SLionel Sambuc --variable="test_suites.suite2.X-the-variable=overriden" \ 279*11be35a1SLionel Sambuc --variable="test_suites.suite3.X-the-variable=new" \ 280*11be35a1SLionel Sambuc config 281*11be35a1SLionel Sambuc} 282*11be35a1SLionel Sambuc 283*11be35a1SLionel Sambuc 284*11be35a1SLionel Sambucutils_test_case variable_flag__override_custom_config 285*11be35a1SLionel Sambucvariable_flag__override_custom_config_body() { 286*11be35a1SLionel Sambuc cat >config <<EOF 287*11be35a1SLionel Sambucsyntax(2) 288*11be35a1SLionel Sambuctest_suites.suite1["X-the-variable"] = "value1" 289*11be35a1SLionel Sambuctest_suites.suite2["X-the-variable"] = "should not be used" 290*11be35a1SLionel SambucEOF 291*11be35a1SLionel Sambuc 292*11be35a1SLionel Sambuc atf_check -s exit:0 \ 293*11be35a1SLionel Sambuc -o match:'test_suites.suite2.X-the-variable = overriden' \ 294*11be35a1SLionel Sambuc -e empty kyua -c config \ 295*11be35a1SLionel Sambuc -v "test_suites.suite2.X-the-variable=overriden" config 296*11be35a1SLionel Sambuc 297*11be35a1SLionel Sambuc atf_check -s exit:0 \ 298*11be35a1SLionel Sambuc -o match:'test_suites.suite2.X-the-variable = overriden' \ 299*11be35a1SLionel Sambuc -e empty kyua -c config \ 300*11be35a1SLionel Sambuc --variable="test_suites.suite2.X-the-variable=overriden" config 301*11be35a1SLionel Sambuc} 302*11be35a1SLionel Sambuc 303*11be35a1SLionel Sambuc 304*11be35a1SLionel Sambucutils_test_case variable_flag__invalid 305*11be35a1SLionel Sambucvariable_flag__invalid_body() { 306*11be35a1SLionel Sambuc cat >experr <<EOF 307*11be35a1SLionel SambucUsage error: Invalid argument '' for option --variable: Argument does not have the form 'K=V'. 308*11be35a1SLionel SambucType 'kyua help' for usage information. 309*11be35a1SLionel SambucEOF 310*11be35a1SLionel Sambuc atf_check -s exit:3 -o empty -e file:experr kyua \ 311*11be35a1SLionel Sambuc -v "test_suites.a.b=c" -v "" config 312*11be35a1SLionel Sambuc 313*11be35a1SLionel Sambuc cat >experr <<EOF 314*11be35a1SLionel Sambuckyua: E: Unknown configuration property 'foo'. 315*11be35a1SLionel SambucEOF 316*11be35a1SLionel Sambuc atf_check -s exit:2 -o empty -e file:experr kyua \ 317*11be35a1SLionel Sambuc -v "test_suites.a.b=c" -v "foo=bar" config 318*11be35a1SLionel Sambuc} 319*11be35a1SLionel Sambuc 320*11be35a1SLionel Sambuc 321*11be35a1SLionel Sambucatf_init_test_cases() { 322*11be35a1SLionel Sambuc atf_add_test_case defaults 323*11be35a1SLionel Sambuc atf_add_test_case all 324*11be35a1SLionel Sambuc atf_add_test_case one__ok 325*11be35a1SLionel Sambuc atf_add_test_case one__fail 326*11be35a1SLionel Sambuc atf_add_test_case many__ok 327*11be35a1SLionel Sambuc atf_add_test_case many__fail 328*11be35a1SLionel Sambuc 329*11be35a1SLionel Sambuc atf_add_test_case config_flag__default_system 330*11be35a1SLionel Sambuc atf_add_test_case config_flag__default_home 331*11be35a1SLionel Sambuc atf_add_test_case config_flag__explicit__ok 332*11be35a1SLionel Sambuc atf_add_test_case config_flag__explicit__disable 333*11be35a1SLionel Sambuc atf_add_test_case config_flag__explicit__missing_file 334*11be35a1SLionel Sambuc atf_add_test_case config_flag__explicit__bad_file 335*11be35a1SLionel Sambuc 336*11be35a1SLionel Sambuc atf_add_test_case variable_flag__no_config 337*11be35a1SLionel Sambuc atf_add_test_case variable_flag__override_default_config 338*11be35a1SLionel Sambuc atf_add_test_case variable_flag__override_custom_config 339*11be35a1SLionel Sambuc atf_add_test_case variable_flag__invalid 340*11be35a1SLionel Sambuc} 341