]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/kyua/integration/cmd_list_test.sh
Import PCG-C into sys/contrib
[FreeBSD/FreeBSD.git] / contrib / kyua / integration / cmd_list_test.sh
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
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="metadata"}
36 atf_test_program{name="simple_all_pass"}
37 include("subdir/Kyuafile")
38 EOF
39     utils_cp_helper metadata .
40     utils_cp_helper simple_all_pass .
41
42     mkdir subdir
43     cat >subdir/Kyuafile <<EOF
44 syntax(2)
45 test_suite("integration2")
46 atf_test_program{name="simple_some_fail"}
47 EOF
48     utils_cp_helper simple_some_fail subdir
49
50     cat >expout <<EOF
51 metadata:many_properties
52 metadata:no_properties
53 metadata:one_property
54 metadata:with_cleanup
55 simple_all_pass:pass
56 simple_all_pass:skip
57 subdir/simple_some_fail:fail
58 subdir/simple_some_fail:pass
59 EOF
60     atf_check -s exit:0 -o file:expout -e empty kyua list
61 }
62
63
64 utils_test_case one_arg__subdir
65 one_arg__subdir_body() {
66     cat >Kyuafile <<EOF
67 syntax(2)
68 test_suite("top-level")
69 include("subdir/Kyuafile")
70 EOF
71
72     mkdir subdir
73     cat >subdir/Kyuafile <<EOF
74 syntax(2)
75 test_suite("in-subdir")
76 atf_test_program{name="simple_all_pass"}
77 EOF
78     utils_cp_helper simple_all_pass subdir
79
80     cat >expout <<EOF
81 subdir/simple_all_pass:pass
82 subdir/simple_all_pass:skip
83 EOF
84     atf_check -s exit:0 -o file:expout -e empty kyua list subdir
85 }
86
87
88 utils_test_case one_arg__test_case
89 one_arg__test_case_body() {
90     cat >Kyuafile <<EOF
91 syntax(2)
92 test_suite("top-level")
93 atf_test_program{name="first"}
94 atf_test_program{name="second"}
95 EOF
96     utils_cp_helper simple_all_pass first
97     utils_cp_helper simple_all_pass second
98
99     cat >expout <<EOF
100 first:skip
101 EOF
102     atf_check -s exit:0 -o file:expout -e empty kyua list first:skip
103 }
104
105
106 utils_test_case one_arg__test_program
107 one_arg__test_program_body() {
108     cat >Kyuafile <<EOF
109 syntax(2)
110 test_suite("top-level")
111 atf_test_program{name="first"}
112 atf_test_program{name="second"}
113 EOF
114     utils_cp_helper simple_all_pass first
115     utils_cp_helper simple_some_fail second
116
117     cat >expout <<EOF
118 second:fail
119 second:pass
120 EOF
121     atf_check -s exit:0 -o file:expout -e empty kyua list second
122 }
123
124
125 utils_test_case one_arg__invalid
126 one_arg__invalid_body() {
127 cat >experr <<EOF
128 kyua: E: Test case component in 'foo:' is empty.
129 EOF
130     atf_check -s exit:2 -o empty -e file:experr kyua list foo:
131
132 cat >experr <<EOF
133 kyua: E: Program name '/a/b' must be relative to the test suite, not absolute.
134 EOF
135     atf_check -s exit:2 -o empty -e file:experr kyua list /a/b
136 }
137
138
139 utils_test_case many_args__ok
140 many_args__ok_body() {
141     cat >Kyuafile <<EOF
142 syntax(2)
143 test_suite("top-level")
144 include("subdir/Kyuafile")
145 atf_test_program{name="first"}
146 EOF
147     utils_cp_helper simple_all_pass first
148
149     mkdir subdir
150     cat >subdir/Kyuafile <<EOF
151 syntax(2)
152 test_suite("in-subdir")
153 atf_test_program{name="second"}
154 EOF
155     utils_cp_helper simple_some_fail subdir/second
156
157     cat >expout <<EOF
158 subdir/second:fail (in-subdir)
159 subdir/second:pass (in-subdir)
160 first:pass (top-level)
161 EOF
162     atf_check -s exit:0 -o file:expout -e empty kyua list -v subdir first:pass
163 }
164
165
166 utils_test_case many_args__invalid
167 many_args__invalid_body() {
168 cat >experr <<EOF
169 kyua: E: Program name component in ':badbad' is empty.
170 EOF
171     atf_check -s exit:2 -o empty -e file:experr kyua list this-is-ok :badbad
172
173 cat >experr <<EOF
174 kyua: E: Program name '/foo' must be relative to the test suite, not absolute.
175 EOF
176     atf_check -s exit:2 -o empty -e file:experr kyua list this-is-ok /foo
177 }
178
179
180 utils_test_case many_args__no_match__all
181 many_args__no_match__all_body() {
182     cat >Kyuafile <<EOF
183 syntax(2)
184 test_suite("top-level")
185 atf_test_program{name="first"}
186 atf_test_program{name="second"}
187 EOF
188     utils_cp_helper simple_all_pass first
189     utils_cp_helper simple_all_pass second
190
191     cat >experr <<EOF
192 kyua: W: No test cases matched by the filter 'first1'.
193 EOF
194     atf_check -s exit:1 -o empty -e file:experr kyua list first1
195 }
196
197
198 utils_test_case many_args__no_match__some
199 many_args__no_match__some_body() {
200     cat >Kyuafile <<EOF
201 syntax(2)
202 test_suite("top-level")
203 atf_test_program{name="first"}
204 atf_test_program{name="second"}
205 atf_test_program{name="third"}
206 EOF
207     utils_cp_helper simple_all_pass first
208     utils_cp_helper simple_all_pass second
209     utils_cp_helper simple_some_fail third
210
211     cat >expout <<EOF
212 first:pass
213 first:skip
214 third:fail
215 third:pass
216 EOF
217
218     cat >experr <<EOF
219 kyua: W: No test cases matched by the filter 'fifth'.
220 kyua: W: No test cases matched by the filter 'fourth'.
221 EOF
222     atf_check -s exit:1 -o file:expout -e file:experr kyua list first fourth \
223         third fifth
224 }
225
226
227 utils_test_case args_are_relative
228 args_are_relative_body() {
229     mkdir root
230     cat >root/Kyuafile <<EOF
231 syntax(2)
232 test_suite("integration-1")
233 atf_test_program{name="first"}
234 atf_test_program{name="second"}
235 include("subdir/Kyuafile")
236 EOF
237     utils_cp_helper simple_all_pass root/first
238     utils_cp_helper simple_some_fail root/second
239
240     mkdir root/subdir
241     cat >root/subdir/Kyuafile <<EOF
242 syntax(2)
243 test_suite("integration-2")
244 atf_test_program{name="third"}
245 atf_test_program{name="fourth"}
246 EOF
247     utils_cp_helper simple_all_pass root/subdir/third
248     utils_cp_helper simple_some_fail root/subdir/fourth
249
250     cat >expout <<EOF
251 first:pass (integration-1)
252 first:skip (integration-1)
253 subdir/fourth:fail (integration-2)
254 EOF
255     atf_check -s exit:0 -o file:expout -e empty kyua list \
256         -v -k "$(pwd)/root/Kyuafile" first subdir/fourth:fail
257 }
258
259
260 utils_test_case only_load_used_test_programs
261 only_load_used_test_programs_body() {
262     cat >Kyuafile <<EOF
263 syntax(2)
264 test_suite("integration")
265 atf_test_program{name="first"}
266 atf_test_program{name="second"}
267 EOF
268     utils_cp_helper simple_all_pass first
269     utils_cp_helper bad_test_program second
270
271     cat >expout <<EOF
272 first:pass
273 first:skip
274 EOF
275     CREATE_COOKIE="$(pwd)/cookie"; export CREATE_COOKIE
276     atf_check -s exit:0 -o file:expout -e empty kyua list first
277     if [ -f "${CREATE_COOKIE}" ]; then
278         atf_fail "An unmatched test case has been executed, which harms" \
279             "performance"
280     fi
281 }
282
283
284 utils_test_case config_behavior
285 config_behavior_body() {
286     cat >"my-config" <<EOF
287 syntax(2)
288 test_suites.suite1["the-variable"] = "value1"
289 EOF
290
291     cat >Kyuafile <<EOF
292 syntax(2)
293 atf_test_program{name="config1", test_suite="suite1"}
294 EOF
295     utils_cp_helper config config1
296
297     CONFIG_VAR_FILE="$(pwd)/cookie"; export CONFIG_VAR_FILE
298     if [ -f "${CONFIG_VAR_FILE}" ]; then
299         atf_fail "Cookie file already created; test case list may have gotten" \
300             "a bad configuration"
301     fi
302     atf_check -s exit:0 -o ignore -e empty kyua -c my-config list
303     [ -f "${CONFIG_VAR_FILE}" ] || \
304         atf_fail "Cookie file not created; test case list did not get" \
305             "configuration variables"
306     value="$(cat "${CONFIG_VAR_FILE}")"
307     [ "${value}" = "value1" ] || \
308         atf_fail "Invalid value (${value}) in cookie file; test case list did" \
309             "not get the correct configuration variables"
310 }
311
312
313 utils_test_case build_root_flag
314 build_root_flag_body() {
315     mkdir subdir
316     mkdir build
317     mkdir build/subdir
318
319     cat >Kyuafile <<EOF
320 syntax(2)
321 test_suite("top-level")
322 include("subdir/Kyuafile")
323 atf_test_program{name="first"}
324 EOF
325     echo 'invalid' >first
326     utils_cp_helper simple_all_pass build/first
327
328     cat >subdir/Kyuafile <<EOF
329 syntax(2)
330 test_suite("in-subdir")
331 atf_test_program{name="second"}
332 EOF
333     echo 'invalid' >subdir/second
334     utils_cp_helper simple_some_fail build/subdir/second
335
336     cat >expout <<EOF
337 subdir/second:fail
338 subdir/second:pass
339 first:pass
340 EOF
341     atf_check -s exit:0 -o file:expout -e empty kyua list --build-root=build \
342         subdir first:pass
343 }
344
345
346 utils_test_case kyuafile_flag__no_args
347 kyuafile_flag__no_args_body() {
348     cat >Kyuafile <<EOF
349 This file is bogus but it is not loaded.
350 EOF
351
352     cat >myfile <<EOF
353 syntax(2)
354 test_suite("integration")
355 atf_test_program{name="sometest"}
356 EOF
357     utils_cp_helper simple_all_pass sometest
358
359     cat >expout <<EOF
360 sometest:pass
361 sometest:skip
362 EOF
363     atf_check -s exit:0 -o file:expout -e empty kyua list -k myfile
364     atf_check -s exit:0 -o file:expout -e empty kyua list --kyuafile=myfile
365 }
366
367
368 utils_test_case kyuafile_flag__some_args
369 kyuafile_flag__some_args_body() {
370     cat >Kyuafile <<EOF
371 This file is bogus but it is not loaded.
372 EOF
373
374     cat >myfile <<EOF
375 syntax(2)
376 test_suite("hello-world")
377 atf_test_program{name="sometest"}
378 EOF
379     utils_cp_helper simple_all_pass sometest
380
381     cat >expout <<EOF
382 sometest:pass (hello-world)
383 sometest:skip (hello-world)
384 EOF
385     atf_check -s exit:0 -o file:expout -e empty kyua list -v -k myfile sometest
386     atf_check -s exit:0 -o file:expout -e empty kyua list -v --kyuafile=myfile \
387         sometest
388 }
389
390
391 utils_test_case verbose_flag
392 verbose_flag_body() {
393     cat >Kyuafile <<EOF
394 syntax(2)
395 test_suite("integration-suite-1")
396 atf_test_program{name="simple_all_pass"}
397 plain_test_program{name="i_am_plain", timeout=654}
398 include("subdir/Kyuafile")
399 EOF
400     utils_cp_helper simple_all_pass .
401     touch i_am_plain
402
403     mkdir subdir
404     cat >subdir/Kyuafile <<EOF
405 syntax(2)
406 test_suite("integration-suite-2")
407 atf_test_program{name="metadata"}
408 EOF
409     utils_cp_helper metadata subdir
410
411     cat >expout <<EOF
412 simple_all_pass:pass (integration-suite-1)
413 simple_all_pass:skip (integration-suite-1)
414 i_am_plain:main (integration-suite-1)
415     timeout = 654
416 subdir/metadata:many_properties (integration-suite-2)
417     allowed_architectures = some-architecture
418     allowed_platforms = some-platform
419     custom.no-meaning = I am a custom variable
420     description =     A description with some padding
421     required_configs = var1 var2 var3
422     required_files = /my/file1 /some/other/file
423     required_programs = /nonexistent/bin3 bin1 bin2
424     required_user = root
425 subdir/metadata:no_properties (integration-suite-2)
426 subdir/metadata:one_property (integration-suite-2)
427     description = Does nothing but has one metadata property
428 subdir/metadata:with_cleanup (integration-suite-2)
429     has_cleanup = true
430     timeout = 250
431 EOF
432     atf_check -s exit:0 -o file:expout -e empty kyua list -v
433     atf_check -s exit:0 -o file:expout -e empty kyua list --verbose
434 }
435
436
437 utils_test_case no_test_program_match
438 no_test_program_match_body() {
439     cat >Kyuafile <<EOF
440 syntax(2)
441 test_suite("integration")
442 atf_test_program{name="first"}
443 EOF
444     utils_cp_helper simple_all_pass first
445     utils_cp_helper simple_all_pass second
446
447     cat >experr <<EOF
448 kyua: W: No test cases matched by the filter 'second'.
449 EOF
450     atf_check -s exit:1 -o empty -e file:experr kyua list second
451 }
452
453
454 utils_test_case no_test_case_match
455 no_test_case_match_body() {
456     cat >Kyuafile <<EOF
457 syntax(2)
458 test_suite("integration")
459 atf_test_program{name="first"}
460 EOF
461     utils_cp_helper simple_all_pass first
462
463     cat >experr <<EOF
464 kyua: W: No test cases matched by the filter 'first:foobar'.
465 EOF
466     atf_check -s exit:1 -o empty -e file:experr kyua list first:foobar
467 }
468
469
470 utils_test_case missing_kyuafile__no_args
471 missing_kyuafile__no_args_body() {
472     cat >experr <<EOF
473 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
474 EOF
475     atf_check -s exit:2 -o empty -e file:experr kyua list
476 }
477
478
479 utils_test_case missing_kyuafile__test_program
480 missing_kyuafile__test_program_body() {
481     mkdir subdir
482     cat >subdir/Kyuafile <<EOF
483 syntax(2)
484 test_suite("integration")
485 atf_test_program{name="unused"}
486 EOF
487     utils_cp_helper simple_all_pass subdir/unused
488
489     cat >experr <<EOF
490 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
491 EOF
492     atf_check -s exit:2 -o empty -e file:experr kyua list subdir/unused
493 }
494
495
496 utils_test_case missing_kyuafile__subdir
497 missing_kyuafile__subdir_body() {
498     mkdir subdir
499     cat >subdir/Kyuafile <<EOF
500 syntax(2)
501 test_suite("integration")
502 atf_test_program{name="unused"}
503 EOF
504     utils_cp_helper simple_all_pass subdir/unused
505
506     cat >experr <<EOF
507 kyua: E: Load of 'Kyuafile' failed: File 'Kyuafile' not found.
508 EOF
509     atf_check -s exit:2 -o empty -e file:experr kyua list subdir
510 }
511
512
513 utils_test_case bogus_kyuafile
514 bogus_kyuafile_body() {
515     cat >Kyuafile <<EOF
516 Hello, world.
517 EOF
518     atf_check -s exit:2 -o empty \
519         -e match:"Load of 'Kyuafile' failed: .* Kyuafile:2:" kyua list
520 }
521
522
523 utils_test_case bogus_test_program
524 bogus_test_program_body() {
525     cat >Kyuafile <<EOF
526 syntax(2)
527 test_suite("integration")
528 atf_test_program{name="crash_on_list"}
529 atf_test_program{name="non_executable"}
530 EOF
531     utils_cp_helper bad_test_program crash_on_list
532     echo 'I am not executable' >non_executable
533
534     cat >expout <<EOF
535 crash_on_list:__test_cases_list__
536 non_executable:__test_cases_list__
537 EOF
538     atf_check -s exit:0 -o file:expout -e empty kyua list
539 }
540
541
542 utils_test_case missing_test_program
543 missing_test_program_body() {
544     cat >Kyuafile <<EOF
545 syntax(2)
546 include("subdir/Kyuafile")
547 EOF
548     mkdir subdir
549     cat >subdir/Kyuafile <<EOF
550 syntax(2)
551 test_suite("integration")
552 atf_test_program{name="ok"}
553 atf_test_program{name="i-am-missing"}
554 EOF
555     echo 'I should not be touched because the Kyuafile is bogus' >subdir/ok
556
557 # CHECK_STYLE_DISABLE
558     cat >experr <<EOF
559 kyua: E: Load of 'Kyuafile' failed: .*Non-existent test program 'subdir/i-am-missing'.
560 EOF
561 # CHECK_STYLE_ENABLE
562     atf_check -s exit:2 -o empty -e "match:$(cat experr)" kyua list
563 }
564
565
566 atf_init_test_cases() {
567     atf_add_test_case no_args
568     atf_add_test_case one_arg__subdir
569     atf_add_test_case one_arg__test_case
570     atf_add_test_case one_arg__test_program
571     atf_add_test_case one_arg__invalid
572     atf_add_test_case many_args__ok
573     atf_add_test_case many_args__invalid
574     atf_add_test_case many_args__no_match__all
575     atf_add_test_case many_args__no_match__some
576
577     atf_add_test_case args_are_relative
578
579     atf_add_test_case only_load_used_test_programs
580
581     atf_add_test_case config_behavior
582
583     atf_add_test_case build_root_flag
584
585     atf_add_test_case kyuafile_flag__no_args
586     atf_add_test_case kyuafile_flag__some_args
587
588     atf_add_test_case verbose_flag
589
590     atf_add_test_case no_test_program_match
591     atf_add_test_case no_test_case_match
592
593     atf_add_test_case missing_kyuafile__no_args
594     atf_add_test_case missing_kyuafile__test_program
595     atf_add_test_case missing_kyuafile__subdir
596
597     atf_add_test_case bogus_kyuafile
598     atf_add_test_case bogus_test_program
599     atf_add_test_case missing_test_program
600 }