1#! __ATF_SH__ 2# Copyright 2012 Google Inc. 3# All rights reserved. 4# 5# Redistribution and use in source and binary forms, with or without 6# modification, are permitted provided that the following conditions are 7# met: 8# 9# * Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# * Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# * Neither the name of Google Inc. nor the names of its contributors 15# may be used to endorse or promote products derived from this software 16# without specific prior written permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 31. "${KYUA_ATF_COMPAT_PKGDATADIR:-__PKGDATADIR__}/tests_lib.subr" 32 33 34atf_test_case all_pass 35all_pass_body() { 36 create_test_program program1 pass skip 37 create_atffile Atffile 'prop: test-suite = "suite"' \ 38 'tp: program1' 'tp: subdir' 39 40 mkdir subdir 41 create_test_program subdir/program2 skip 42 create_atffile subdir/Atffile 'prop: test-suite = "suite"' \ 43 'tp: program2' 44 45 atf_check -s exit:0 -e ignore \ 46 -o match:'program1:pass -> passed' \ 47 -o match:'program1:skip -> skipped' \ 48 -o match:'subdir/program2:skip -> skipped' \ 49 -o match:'Committed action 1' \ 50 atf-run 51} 52 53 54atf_test_case some_fail 55some_fail_body() { 56 create_test_program program1 pass skip 57 create_atffile Atffile 'prop: test-suite = "suite"' \ 58 'tp: program1' 'tp: subdir' 59 60 mkdir subdir 61 create_atffile subdir/Atffile 'tp-glob: *' 62 63 mkdir subdir/nested 64 create_test_program subdir/nested/program2 skip fail 65 create_atffile subdir/nested/Atffile 'prop: test-suite = "suite"' \ 66 'tp-glob: program2*' 67 68 atf_check -s exit:1 -e ignore \ 69 -o match:'program1:pass -> passed' \ 70 -o match:'program1:skip -> skipped' \ 71 -o match:'subdir/nested/program2:fail -> failed' \ 72 -o match:'subdir/nested/program2:skip -> skipped' \ 73 -o match:'Committed action 1' \ 74 atf-run 75} 76 77atf_test_case prefer_kyuafiles 78prefer_kyuafiles_body() { 79 create_test_program program1 pass skip 80 cat >Kyuafile <<EOF 81syntax('kyuafile', 1) 82test_suite('foo') 83atf_test_program{name='program1'} 84EOF 85 echo "This file is invalid" >Atffile 86 87 atf_check -s exit:0 -e ignore \ 88 -o match:'program1:pass -> passed' \ 89 -o match:'program1:skip -> skipped' \ 90 atf-run 91} 92 93 94atf_test_case selectors 95selectors_body() { 96 create_test_program program1 pass skip 97 create_atffile Atffile 'prop: test-suite = "suite"' \ 98 'tp: program1' 'tp: subdir' 99 100 mkdir subdir 101 create_atffile subdir/Atffile 'tp-glob: *' 102 103 mkdir subdir/nested 104 create_test_program subdir/nested/program2 skip fail 105 create_atffile subdir/nested/Atffile 'prop: test-suite = "suite"' \ 106 'tp-glob: program2*' 107 108 atf_check -s exit:1 -e ignore \ 109 -o match:'program1:pass -> passed' \ 110 -o match:'program1:skip -> skipped' \ 111 -o match:'subdir/nested/program2:fail -> failed' \ 112 -o match:'subdir/nested/program2:skip -> skipped' \ 113 -o match:'Committed action 1' \ 114 atf-run 115 116 atf_check -s exit:0 -e ignore \ 117 -o match:'program1:pass -> passed' \ 118 -o not-match:'program1:skip -> skipped' \ 119 -o not-match:'subdir/nested/program2:fail -> failed' \ 120 -o match:'subdir/nested/program2:skip -> skipped' \ 121 -o match:'Committed action 2' \ 122 atf-run program1:pass subdir/nested/program2:skip 123 124 atf_check -s exit:1 -e ignore \ 125 -o not-match:'program1:pass -> passed' \ 126 -o not-match:'program1:skip -> skipped' \ 127 -o match:'subdir/nested/program2:fail -> failed' \ 128 -o match:'subdir/nested/program2:skip -> skipped' \ 129 -o match:'Committed action 3' \ 130 atf-run subdir/nested/program2 131} 132 133 134atf_test_case config__priorities 135config__priorities_body() 136{ 137 mkdir system 138 export ATF_CONFDIR="$(pwd)/system" 139 mkdir user 140 mkdir user/.atf 141 export HOME="$(pwd)/user" 142 143 create_test_program helper config 144 create_atffile Atffile 'prop: test-suite = "irrelevant"' 'tp: helper' 145 146 echo "Checking system-wide configuration only" 147 create_config system/common.conf ' unprivileged-user = "nobody"' 148 atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run 149 atf_check -s exit:0 -o 'inline:unprivileged-user = nobody\n' \ 150 cat config.out 151 152 echo "Checking user-specific overrides" 153 create_config user/.atf/common.conf ' unprivileged-user = "root"' 154 atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run 155 atf_check -s exit:0 -o 'inline:unprivileged-user = root\n' \ 156 cat config.out 157 158 echo "Checking command-line overrides" 159 atf_check -s exit:0 -o 'match:helper:config -> passed' -e ignore atf-run \ 160 -v"unprivileged-user=$(id -u -n)" 161 atf_check -s exit:0 -o "inline:unprivileged-user = $(id -u -n)\n" \ 162 cat config.out 163} 164 165 166atf_test_case config__test_suites__files 167config__test_suites__files_body() 168{ 169 mkdir system 170 export ATF_CONFDIR="$(pwd)/system" 171 172 create_config system/suite1.conf 'var1 = "var1-for-suite1"' \ 173 'var2 = "var2-for-suite1"' 174 create_config system/suite2.conf 'var1 = "var1-for-suite2"' \ 175 'var2 = "var2-for-suite2"' 176 177 create_test_program helper1 config 178 create_atffile Atffile 'prop: test-suite = "suite1"' 'tp: helper1' \ 179 'tp: subdir' 180 mkdir subdir 181 create_test_program subdir/helper2 config 182 create_atffile subdir/Atffile 'prop: test-suite = "suite2"' 'tp: helper2' 183 184 atf_check -s exit:0 -o ignore -e ignore atf-run helper1 185 atf_check -s exit:0 -o 'match:var1 = var1-for-suite1' \ 186 -o 'match:var2 = var2-for-suite1' -o 'not-match:suite2' \ 187 cat config.out 188 189 atf_check -s exit:0 -o ignore -e ignore atf-run subdir/helper2 190 atf_check -s exit:0 -o 'match:var1 = var1-for-suite2' \ 191 -o 'match:var2 = var2-for-suite2' -o 'not-match:suite1' \ 192 cat config.out 193} 194 195 196atf_test_case config__test_suites__vflags 197config__test_suites__vflags_body() 198{ 199 create_test_program helper1 config 200 create_atffile Atffile 'prop: test-suite = "suite1"' 'tp: helper1' \ 201 'tp: subdir' 202 mkdir subdir 203 create_test_program subdir/helper2 config 204 create_atffile subdir/Atffile 'prop: test-suite = "suite2"' 'tp: helper2' 205 206 atf_check -s exit:0 -o ignore -e ignore atf-run -v var1=foo helper1 207 atf_check -s exit:0 -o 'match:var1 = foo' cat config.out 208 209 atf_check -s exit:0 -o ignore -e ignore atf-run -v var1=bar helper1 210 atf_check -s exit:0 -o 'match:var1 = bar' cat config.out 211} 212 213 214atf_test_case unknown_option 215unknown_option_body() { 216 atf_check -s exit:1 -o empty -e match:'E: Unknown option -Z' \ 217 atf-run -Z -A 218} 219 220 221atf_init_test_cases() { 222 atf_add_test_case all_pass 223 atf_add_test_case some_fail 224 atf_add_test_case selectors 225 226 atf_add_test_case prefer_kyuafiles 227 228 atf_add_test_case config__priorities 229 atf_add_test_case config__test_suites__files 230 atf_add_test_case config__test_suites__vflags 231 232 atf_add_test_case unknown_option 233} 234