cmd_debug_test.sh revision 1.1.1.1 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 no_args
31 no_args_body() {
32 cat >Kyuafile <<EOF
33 syntax(2)
34 test_suite("integration")
35 atf_test_program{name="simple_all_pass"}
36 EOF
37 utils_cp_helper simple_all_pass .
38
39 cat >experr <<EOF
40 Usage error for command debug: Not enough arguments.
41 Type 'kyua help debug' for usage information.
42 EOF
43 atf_check -s exit:3 -o empty -e file:experr kyua debug
44 }
45
46
47 utils_test_case many_args
48 many_args_body() {
49 cat >Kyuafile <<EOF
50 syntax(2)
51 test_suite("integration")
52 atf_test_program{name="first"}
53 atf_test_program{name="second"}
54 EOF
55 utils_cp_helper simple_all_pass first
56 utils_cp_helper simple_all_pass second
57
58 cat >experr <<EOF
59 Usage error for command debug: Too many arguments.
60 Type 'kyua help debug' for usage information.
61 EOF
62 atf_check -s exit:3 -o empty -e file:experr kyua debug first:pass \
63 second:pass
64 }
65
66
67 utils_test_case one_arg__ok_pass
68 one_arg__ok_pass_body() {
69 cat >Kyuafile <<EOF
70 syntax(2)
71 test_suite("integration")
72 atf_test_program{name="first"}
73 atf_test_program{name="second"}
74 EOF
75 utils_cp_helper expect_all_pass first
76 utils_cp_helper simple_all_pass second
77
78 cat >expout <<EOF
79 This is the stdout of pass
80 second:pass -> passed
81 EOF
82 cat >experr <<EOF
83 This is the stderr of pass
84 EOF
85 atf_check -s exit:0 -o file:expout -e file:experr kyua debug second:pass
86 }
87
88
89 utils_test_case one_arg__ok_fail
90 one_arg__ok_fail_body() {
91 cat >Kyuafile <<EOF
92 syntax(2)
93 test_suite("integration")
94 atf_test_program{name="first"}
95 EOF
96 utils_cp_helper simple_some_fail first
97
98 cat >expout <<EOF
99 This is the stdout of fail
100 first:fail -> failed: This fails on purpose
101 EOF
102 cat >experr <<EOF
103 This is the stderr of fail
104 EOF
105 atf_check -s exit:1 -o file:expout -e file:experr kyua debug first:fail
106 }
107
108
109 utils_test_case one_arg__no_match
110 one_arg__no_match_body() {
111 cat >Kyuafile <<EOF
112 syntax(2)
113 test_suite("integration")
114 atf_test_program{name="first"}
115 atf_test_program{name="second"}
116 EOF
117 utils_cp_helper expect_all_pass first
118 utils_cp_helper simple_all_pass second
119
120 cat >experr <<EOF
121 kyua: E: Unknown test case 'second:die'.
122 EOF
123 atf_check -s exit:2 -o empty -e file:experr kyua debug second:die
124 }
125
126
127 utils_test_case one_arg__no_test_case
128 one_arg__no_test_case_body() {
129 cat >experr <<EOF
130 Usage error for command debug: 'foo' is not a test case identifier (missing ':'?).
131 Type 'kyua help debug' for usage information.
132 EOF
133 atf_check -s exit:3 -o empty -e file:experr kyua debug foo
134 }
135
136
137 utils_test_case one_arg__bad_filter
138 one_arg__bad_filter_body() {
139 cat >experr <<EOF
140 kyua: E: Test case component in 'foo:' is empty.
141 EOF
142 atf_check -s exit:2 -o empty -e file:experr kyua debug foo:
143 }
144
145
146 utils_test_case body_and_cleanup
147 body_and_cleanup_body() {
148 cat >Kyuafile <<EOF
149 syntax(2)
150 test_suite("integration")
151 atf_test_program{name="single"}
152 EOF
153 utils_cp_helper metadata single
154
155 cat >expout <<EOF
156 single:with_cleanup -> passed
157 EOF
158 atf_check -s exit:0 -o file:expout -e empty kyua debug \
159 --stdout=saved.out --stderr=saved.err single:with_cleanup
160
161 cat >expout <<EOF
162 Body message to stdout
163 Cleanup message to stdout
164 EOF
165 atf_check -s exit:0 -o file:expout -e empty cat saved.out
166
167 cat >experr <<EOF
168 Body message to stderr
169 Cleanup message to stderr
170 EOF
171 atf_check -s exit:0 -o file:experr -e empty cat saved.err
172 }
173
174
175 utils_test_case stdout_stderr_flags
176 stdout_stderr_flags_body() {
177 cat >Kyuafile <<EOF
178 syntax(2)
179 test_suite("integration")
180 atf_test_program{name="first"}
181 atf_test_program{name="second"}
182 EOF
183 utils_cp_helper expect_all_pass first
184 utils_cp_helper simple_all_pass second
185
186 cat >expout <<EOF
187 second:pass -> passed
188 EOF
189 atf_check -s exit:0 -o file:expout -e empty kyua debug \
190 --stdout=saved.out --stderr=saved.err second:pass
191
192 cat >expout <<EOF
193 This is the stdout of pass
194 EOF
195 cmp -s saved.out expout || atf_fail "--stdout did not redirect the" \
196 "standard output to the desired file"
197
198 cat >experr <<EOF
199 This is the stderr of pass
200 EOF
201 cmp -s saved.err experr || atf_fail "--stderr did not redirect the" \
202 "standard error to the desired file"
203 }
204
205
206 utils_test_case args_are_relative
207 args_are_relative_body() {
208 mkdir root
209 cat >root/Kyuafile <<EOF
210 syntax(2)
211 test_suite("integration")
212 include("subdir/Kyuafile")
213 atf_test_program{name="prog"}
214 EOF
215 utils_cp_helper simple_all_pass root/prog
216
217 mkdir root/subdir
218 cat >root/subdir/Kyuafile <<EOF
219 syntax(2)
220 test_suite("integration")
221 atf_test_program{name="prog"}
222 EOF
223 utils_cp_helper simple_some_fail root/subdir/prog
224
225 cat >expout <<EOF
226 This is the stdout of fail
227 subdir/prog:fail -> failed: This fails on purpose
228 EOF
229 cat >experr <<EOF
230 This is the stderr of fail
231 EOF
232 atf_check -s exit:1 -o file:expout -e file:experr kyua debug \
233 -k "$(pwd)/root/Kyuafile" subdir/prog:fail
234 }
235
236
237 utils_test_case only_load_used_test_programs
238 only_load_used_test_programs_body() {
239 cat >Kyuafile <<EOF
240 syntax(2)
241 test_suite("integration")
242 atf_test_program{name="first"}
243 atf_test_program{name="second"}
244 EOF
245 utils_cp_helper simple_all_pass first
246 utils_cp_helper bad_test_program second
247
248 cat >expout <<EOF
249 This is the stdout of pass
250 first:pass -> passed
251 EOF
252 cat >experr <<EOF
253 This is the stderr of pass
254 EOF
255 CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE
256 atf_check -s exit:0 -o file:expout -e file:experr kyua debug first:pass
257 if test -f "${CREATE_COOKIE}"; then
258 atf_fail "An unmatched test case has been executed, which harms" \
259 "performance"
260 fi
261 }
262
263
264 utils_test_case config_behavior
265 config_behavior_body() {
266 cat >"my-config" <<EOF
267 syntax(2)
268 test_suites.suite1["X-the-variable"] = "value1"
269 test_suites.suite2["X-the-variable"] = "override me"
270 EOF
271
272 cat >Kyuafile <<EOF
273 syntax(2)
274 atf_test_program{name="config1", test_suite="suite1"}
275 atf_test_program{name="config2", test_suite="suite2"}
276 atf_test_program{name="config3", test_suite="suite3"}
277 EOF
278 utils_cp_helper config config1
279 utils_cp_helper config config2
280 utils_cp_helper config config3
281
282 atf_check -s exit:1 -o match:'failed' -e empty \
283 kyua -c my-config -v test_suites.suite2.X-the-variable=value2 \
284 debug config1:get_variable
285 atf_check -s exit:0 -o match:'passed' -e empty \
286 kyua -c my-config -v test_suites.suite2.X-the-variable=value2 \
287 debug config2:get_variable
288 atf_check -s exit:0 -o match:'skipped' -e empty \
289 kyua -c my-config -v test_suites.suite2.X-the-variable=value2 \
290 debug config3:get_variable
291 }
292
293
294 utils_test_case build_root_flag
295 build_root_flag_body() {
296 cat >Kyuafile <<EOF
297 syntax(2)
298 test_suite("integration")
299 atf_test_program{name="first"}
300 atf_test_program{name="second"}
301 EOF
302 mkdir build
303 utils_cp_helper expect_all_pass build/first
304 utils_cp_helper simple_all_pass build/second
305
306 cat >expout <<EOF
307 This is the stdout of pass
308 second:pass -> passed
309 EOF
310 cat >experr <<EOF
311 This is the stderr of pass
312 EOF
313 atf_check -s exit:0 -o file:expout -e file:experr \
314 kyua debug --build-root=build second:pass
315 }
316
317
318 utils_test_case kyuafile_flag__ok
319 kyuafile_flag__ok_body() {
320 cat >Kyuafile <<EOF
321 This file is bogus but it is not loaded.
322 EOF
323
324 cat >myfile <<EOF
325 syntax(2)
326 test_suite("hello-world")
327 atf_test_program{name="sometest"}
328 EOF
329 utils_cp_helper simple_all_pass sometest
330
331 atf_check -s exit:0 -o match:passed -e empty kyua test -k myfile sometest
332 atf_check -s exit:0 -o match:passed -e empty kyua test --kyuafile=myfile \
333 sometest
334 }
335
336
337 utils_test_case missing_kyuafile
338 missing_kyuafile_body() {
339 cat >experr <<EOF
340 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
341 EOF
342 atf_check -s exit:2 -o empty -e file:experr kyua debug foo:bar
343 }
344
345
346 utils_test_case bogus_kyuafile
347 bogus_kyuafile_body() {
348 cat >Kyuafile <<EOF
349 Hello, world.
350 EOF
351
352 cat >experr <<EOF
353 kyua: E: Load of 'Kyuafile' failed: Failed to load Lua file 'Kyuafile': Kyuafile:2: '<name>' expected near '<eof>'.
354 EOF
355 atf_check -s exit:2 -o empty -e file:experr kyua debug foo:bar
356 }
357
358
359 utils_test_case bogus_test_program
360 bogus_test_program_body() {
361 cat >Kyuafile <<EOF
362 syntax(2)
363 test_suite("integration")
364 atf_test_program{name="crash_on_list"}
365 atf_test_program{name="non_executable"}
366 EOF
367 utils_cp_helper bad_test_program crash_on_list
368 echo 'I am not executable' >non_executable
369
370 cat >experr <<EOF
371 kyua: E: Unknown test case 'crash_on_list:a'.
372 EOF
373 atf_check -s exit:2 -o empty -e file:experr kyua debug crash_on_list:a
374
375 cat >experr <<EOF
376 kyua: E: Unknown test case 'non_executable:a'.
377 EOF
378 atf_check -s exit:2 -o empty -e file:experr kyua debug non_executable:a
379
380 cat >expout <<EOF
381 crash_on_list:__test_cases_list__ -> broken: Tester did not exit cleanly: kyua-atf-tester: Invalid test cases list header 'This is not a valid test program!'
382 EOF
383 atf_check -s exit:1 -o file:expout -e empty kyua debug crash_on_list:__test_cases_list__
384
385 cat >expout <<EOF
386 non_executable:__test_cases_list__ -> broken: Tester did not exit cleanly: kyua-atf-tester: execvp failed: Permission denied
387 EOF
388 atf_check -s exit:1 -o file:expout -e empty kyua debug non_executable:__test_cases_list__
389 }
390
391
392 atf_init_test_cases() {
393 atf_add_test_case no_args
394 atf_add_test_case many_args
395 atf_add_test_case one_arg__ok_pass
396 atf_add_test_case one_arg__ok_fail
397 atf_add_test_case one_arg__no_match
398 atf_add_test_case one_arg__no_test_case
399 atf_add_test_case one_arg__bad_filter
400
401 atf_add_test_case body_and_cleanup
402
403 atf_add_test_case stdout_stderr_flags
404
405 atf_add_test_case args_are_relative
406
407 atf_add_test_case only_load_used_test_programs
408
409 atf_add_test_case config_behavior
410
411 atf_add_test_case build_root_flag
412 atf_add_test_case kyuafile_flag__ok
413 atf_add_test_case missing_kyuafile
414 atf_add_test_case bogus_kyuafile
415 atf_add_test_case bogus_test_program
416 }
417