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