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