]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/test/testing.py
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / tools / build / test / testing.py
1 #!/usr/bin/python
2
3 # Copyright 2008 Jurko Gospodnetic
4 # Copyright 2017 Steven Watanabe
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7
8 # Tests different aspects of Boost Builds automated testing support.
9
10 import BoostBuild
11 import TestCmd
12
13 def test_run():
14 t = BoostBuild.Tester(use_test_config=False)
15
16 t.write("pass.cpp", "int main() {}\n")
17 t.write("fail-compile.cpp", "#error expected to fail\n")
18 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
19 t.write("fail-run.cpp", "int main() { return 1; }\n")
20
21 t.write("Jamroot.jam", """import testing ;
22 run pass.cpp ;
23 run fail-compile.cpp ;
24 run fail-link.cpp ;
25 run fail-run.cpp ;
26 """)
27
28 t.run_build_system(status=1)
29 t.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
30 t.expect_addition("bin/pass.test/$toolset/debug*/pass.exe")
31 t.expect_addition("bin/pass.test/$toolset/debug*/pass.output")
32 t.expect_addition("bin/pass.test/$toolset/debug*/pass.run")
33 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
34
35 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
36
37 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.obj")
38 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.exe")
39 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.output")
40
41 t.expect_nothing_more()
42
43 t.cleanup()
44
45 def test_run_fail():
46 t = BoostBuild.Tester(use_test_config=False)
47
48 t.write("pass.cpp", "int main() {}\n")
49 t.write("fail-compile.cpp", "#error expected to fail\n")
50 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
51 t.write("fail-run.cpp", "int main() { return 1; }\n")
52
53 t.write("Jamroot.jam", """import testing ;
54 run-fail pass.cpp ;
55 run-fail fail-compile.cpp ;
56 run-fail fail-link.cpp ;
57 run-fail fail-run.cpp ;
58 """)
59
60 t.run_build_system(status=1)
61 t.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
62 t.expect_addition("bin/pass.test/$toolset/debug*/pass.exe")
63 t.expect_addition("bin/pass.test/$toolset/debug*/pass.output")
64
65 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
66
67 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.obj")
68 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.exe")
69 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.output")
70 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.run")
71 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.test")
72
73 t.expect_nothing_more()
74
75 t.cleanup()
76
77 def test_run_change():
78 """Tests that the test file is removed when a test fails after it
79 previously passed."""
80
81 t = BoostBuild.Tester(use_test_config=False)
82
83 t.write("pass.cpp", "int main() { return 1; }\n")
84 t.write("fail-compile.cpp", "int main() {}\n")
85 t.write("fail-link.cpp", "int main() {}\n")
86 t.write("fail-run.cpp", "int main() {}\n")
87
88 t.write("Jamroot.jam", """import testing ;
89 run-fail pass.cpp ;
90 run fail-compile.cpp ;
91 run fail-link.cpp ;
92 run fail-run.cpp ;
93 """)
94 t.run_build_system()
95 # Sanity check
96 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
97 t.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
98 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.test")
99 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.test")
100 t.expect_output_lines("...failed*", False)
101
102 # Now make them fail
103 t.write("pass.cpp", "int main() {}\n")
104 t.write("fail-compile.cpp", "#error expected to fail\n")
105 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
106 t.write("fail-run.cpp", "int main() { return 1; }\n")
107 t.run_build_system(status=1)
108
109 t.expect_removal("bin/pass.test/$toolset/debug*/pass.test")
110 t.expect_removal("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
111 t.expect_removal("bin/fail-link.test/$toolset/debug*/fail-link.test")
112 t.expect_removal("bin/fail-run.test/$toolset/debug*/fail-run.test")
113
114 t.cleanup()
115
116 def test_run_path():
117 """Tests that run can find shared libraries even without
118 hardcode-dll-paths. Important: The library is in neither the
119 current working directory, nor any system path, nor the same
120 directory as the executable, so it should never be found without
121 help from Boost.Build."""
122 t = BoostBuild.Tester(["hardcode-dll-paths=false"], use_test_config=False)
123
124 t.write("l.cpp", """
125 void
126 #if defined(_WIN32)
127 __declspec(dllexport)
128 #endif
129 f() {}
130 """)
131 t.write("pass.cpp", "void f(); int main() { f(); }\n")
132
133 t.write("Jamroot.jam", """import testing ;
134 lib l : l.cpp : <link>shared ;
135 run pass.cpp l ;
136 """)
137
138 t.run_build_system()
139 t.expect_addition("bin/$toolset/debug*/l.obj")
140 t.expect_addition("bin/$toolset/debug*/l.dll")
141 t.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
142 t.expect_addition("bin/pass.test/$toolset/debug*/pass.exe")
143 t.expect_addition("bin/pass.test/$toolset/debug*/pass.output")
144 t.expect_addition("bin/pass.test/$toolset/debug*/pass.run")
145 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
146
147 t.cleanup()
148
149 def test_run_args():
150 """Tests the handling of args and input-files"""
151 t = BoostBuild.Tester(use_test_config=False)
152 t.write("test.cpp", """
153 #include <iostream>
154 #include <fstream>
155 int main(int argc, const char ** argv)
156 {
157 for(int i = 1; i < argc; ++i)
158 {
159 if(argv[i][0] == '-')
160 {
161 std::cout << argv[i] << std::endl;
162 }
163 else
164 {
165 std::ifstream ifs(argv[i]);
166 std::cout << ifs.rdbuf();
167 }
168 }
169 }
170 """)
171 t.write("input1.in", "first input\n")
172 t.write("input2.in", "second input\n")
173 t.write("Jamroot.jam", """import testing ;
174 import common ;
175 # FIXME: The order actually depends on the lexigraphical
176 # ordering of the virtual target objects, which is just
177 # crazy. Switch the order of input1.txt and input2.txt
178 # to make this fail. Joining the arguments with && might
179 # work, but might get a bit complicated to implement as
180 # dependency properties do not currently support &&.
181 make input1.txt : input1.in : @common.copy ;
182 make input2.txt : input2.in : @common.copy ;
183 run test.cpp : -y -a : input1.txt input2.txt ;
184 """)
185 t.run_build_system()
186 t.expect_content("bin/test.test/$toolset/debug*/test.output", """\
187 -y
188 -a
189 first input
190 second input
191
192 EXIT STATUS: 0
193 """)
194 t.cleanup()
195
196 def test_link():
197 t = BoostBuild.Tester(use_test_config=False)
198
199 t.write("pass.cpp", "int main() {}\n")
200 t.write("fail-compile.cpp", "#error expected to fail\n")
201 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
202 t.write("fail-run.cpp", "int main() { return 1; }\n")
203
204 t.write("Jamroot.jam", """import testing ;
205 link pass.cpp ;
206 link fail-compile.cpp ;
207 link fail-link.cpp ;
208 link fail-run.cpp ;
209 """)
210
211 t.run_build_system(status=1)
212 t.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
213 t.expect_addition("bin/pass.test/$toolset/debug*/pass.exe")
214 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
215
216 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
217
218 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.obj")
219 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.exe")
220 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.test")
221
222 t.expect_nothing_more()
223
224 t.cleanup()
225
226 def test_link_fail():
227 t = BoostBuild.Tester(use_test_config=False)
228
229 t.write("pass.cpp", "int main() {}\n")
230 t.write("fail-compile.cpp", "#error expected to fail\n")
231 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
232 t.write("fail-run.cpp", "int main() { return 1; }\n")
233
234 t.write("Jamroot.jam", """import testing ;
235 link-fail pass.cpp ;
236 link-fail fail-compile.cpp ;
237 link-fail fail-link.cpp ;
238 link-fail fail-run.cpp ;
239 """)
240
241 t.run_build_system(status=1)
242 t.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
243
244 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
245 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.exe")
246 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.test")
247
248 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.obj")
249
250 t.expect_nothing_more()
251
252 t.cleanup()
253
254 def test_link_change():
255 """Tests that the test file is removed when a test fails after it
256 previously passed."""
257
258 t = BoostBuild.Tester(use_test_config=False)
259
260 t.write("pass.cpp", "int f();\nint main() { return f(); }\n")
261 t.write("fail-compile.cpp", "int main() {}\n")
262 t.write("fail-link.cpp", "int main() {}\n")
263
264 t.write("Jamroot.jam", """import testing ;
265 link-fail pass.cpp ;
266 link fail-compile.cpp ;
267 link fail-link.cpp ;
268 """)
269 t.run_build_system()
270 # Sanity check
271 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
272 t.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
273 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.test")
274 t.expect_output_lines("...failed*", False)
275
276 # Now make them fail
277 t.write("pass.cpp", "int main() {}\n")
278 t.write("fail-compile.cpp", "#error expected to fail\n")
279 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
280 t.run_build_system(status=1)
281
282 t.expect_removal("bin/pass.test/$toolset/debug*/pass.test")
283 t.expect_removal("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
284 t.expect_removal("bin/fail-link.test/$toolset/debug*/fail-link.test")
285
286 t.cleanup()
287
288 def test_compile():
289 t = BoostBuild.Tester(use_test_config=False)
290
291 t.write("pass.cpp", "int main() {}\n")
292 t.write("fail-compile.cpp", "#error expected to fail\n")
293 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
294 t.write("fail-run.cpp", "int main() { return 1; }\n")
295
296 t.write("Jamroot.jam", """import testing ;
297 compile pass.cpp ;
298 compile fail-compile.cpp ;
299 compile fail-link.cpp ;
300 compile fail-run.cpp ;
301 """)
302
303 t.run_build_system(status=1)
304 t.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
305 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
306
307 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
308 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.test")
309
310 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.obj")
311 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.test")
312
313 t.expect_nothing_more()
314
315 t.cleanup()
316
317 def test_compile_fail():
318 t = BoostBuild.Tester(use_test_config=False)
319
320 t.write("pass.cpp", "int main() {}\n")
321 t.write("fail-compile.cpp", "#error expected to fail\n")
322 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
323 t.write("fail-run.cpp", "int main() { return 1; }\n")
324
325 t.write("Jamroot.jam", """import testing ;
326 compile-fail pass.cpp ;
327 compile-fail fail-compile.cpp ;
328 compile-fail fail-link.cpp ;
329 compile-fail fail-run.cpp ;
330 """)
331
332 t.run_build_system(status=1)
333 t.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.obj")
334 t.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
335
336 t.expect_nothing_more()
337
338 t.cleanup()
339
340 def test_compile_change():
341 """Tests that the test file is removed when a test fails after it
342 previously passed."""
343
344 t = BoostBuild.Tester(use_test_config=False)
345
346 t.write("pass.cpp", "#error expected to fail\n")
347 t.write("fail-compile.cpp", "int main() {}\n")
348
349 t.write("Jamroot.jam", """import testing ;
350 compile-fail pass.cpp ;
351 compile fail-compile.cpp ;
352 """)
353 t.run_build_system()
354 # Sanity check
355 t.expect_addition("bin/pass.test/$toolset/debug*/pass.test")
356 t.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
357 t.expect_output_lines("...failed*", False)
358
359 # Now make them fail
360 t.write("pass.cpp", "int main() {}\n")
361 t.write("fail-compile.cpp", "#error expected to fail\n")
362 t.run_build_system(status=1)
363
364 t.expect_removal("bin/pass.test/$toolset/debug*/pass.test")
365 t.expect_removal("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
366
367 t.cleanup()
368
369 def test_remove_test_targets(option):
370 t = BoostBuild.Tester(use_test_config=False)
371
372 t.write("pass-compile.cpp", "int main() {}\n")
373 t.write("pass-link.cpp", "int main() {}\n")
374 t.write("pass-run.cpp", "int main() {}\n")
375 t.write("fail-compile.cpp", "#error expected to fail\n")
376 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
377 t.write("fail-run.cpp", "int main() { return 1; }\n")
378 t.write("source.cpp", "int f();\n")
379
380 t.write("Jamroot.jam", """import testing ;
381 obj source.o : source.cpp ;
382 compile pass-compile.cpp ;
383 link pass-link.cpp source.o ;
384 run pass-run.cpp source.o ;
385 compile-fail fail-compile.cpp ;
386 link-fail fail-link.cpp ;
387 run-fail fail-run.cpp ;
388 """)
389
390 t.run_build_system([option])
391
392 t.expect_addition("bin/$toolset/debug*/source.obj")
393
394 t.expect_addition("bin/pass-compile.test/$toolset/debug*/pass-compile.test")
395
396 t.expect_addition("bin/pass-link.test/$toolset/debug*/pass-link.test")
397
398 t.expect_addition("bin/pass-run.test/$toolset/debug*/pass-run.output")
399 t.expect_addition("bin/pass-run.test/$toolset/debug*/pass-run.run")
400 t.expect_addition("bin/pass-run.test/$toolset/debug*/pass-run.test")
401
402 t.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
403
404 t.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.test")
405
406 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.output")
407 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.run")
408 t.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.test")
409
410 t.expect_nothing_more()
411
412 t.cleanup()
413
414 def test_dump_tests():
415 """Tests the output of the --dump-tests option"""
416 t = BoostBuild.Tester(use_test_config=False)
417
418 t.write("pass-compile.cpp", "int main() {}\n")
419 t.write("pass-link.cpp", "int main() {}\n")
420 t.write("pass-run.cpp", "int main() {}\n")
421 t.write("fail-compile.cpp", "#error expected to fail\n")
422 t.write("fail-link.cpp", "int f();\nint main() { return f(); }\n")
423 t.write("fail-run.cpp", "int main() { return 1; }\n")
424
425 t.write("Jamroot.jam", """import testing ;
426 run pass-run.cpp ;
427 run-fail fail-run.cpp ;
428 link pass-link.cpp ;
429 link-fail fail-link.cpp ;
430 compile pass-compile.cpp ;
431 compile-fail fail-compile.cpp ;
432 build-project libs/any/test ;
433 build-project libs/any/example ;
434 build-project libs/any ;
435 build-project tools/bcp/test ;
436 build-project tools/bcp/example ;
437 build-project subdir/test ;
438 build-project status ;
439 build-project outside/project ;
440 """)
441 def write_subdir(dir):
442 t.write(dir + "/test.cpp", "int main() {}\n")
443 t.write(dir + "/Jamfile", "run test.cpp ;")
444 write_subdir("libs/any/test")
445 write_subdir("libs/any/example")
446 write_subdir("libs/any")
447 write_subdir("tools/bcp/test")
448 write_subdir("tools/bcp/example")
449 write_subdir("status")
450 write_subdir("subdir/test")
451 t.write("outside/other/test.cpp", "int main() {}\n")
452 t.write("outside/project/Jamroot", "run ../other/test.cpp ;")
453 t.run_build_system(["--dump-tests", "-n", "-d0"],
454 match=TestCmd.match_re, stdout=
455 """boost-test\(RUN\) ".*/pass-run" : "pass-run\.cpp"
456 boost-test\(RUN_FAIL\) ".*/fail-run" : "fail-run\.cpp"
457 boost-test\(LINK\) ".*/pass-link" : "pass-link\.cpp"
458 boost-test\(LINK_FAIL\) ".*/fail-link" : "fail-link\.cpp"
459 boost-test\(COMPILE\) ".*/pass-compile" : "pass-compile\.cpp"
460 boost-test\(COMPILE_FAIL\) ".*/fail-compile" : "fail-compile\.cpp"
461 boost-test\(RUN\) "any/test" : "libs/any/test\.cpp"
462 boost-test\(RUN\) "any/test" : "libs/any/test/test\.cpp"
463 boost-test\(RUN\) "any/test" : "libs/any/example/test\.cpp"
464 boost-test\(RUN\) "bcp/test" : "tools/bcp/test/test\.cpp"
465 boost-test\(RUN\) "bcp/test" : "tools/bcp/example/test\.cpp"
466 boost-test\(RUN\) ".*/subdir/test/test" : "subdir/test/test\.cpp"
467 boost-test\(RUN\) "test" : "status/test\.cpp"
468 boost-test\(RUN\) ".*/outside/project/test" : "../other/test.cpp"
469 """)
470 t.cleanup()
471
472 ################################################################################
473 #
474 # test_files_with_spaces_in_their_name()
475 # --------------------------------------
476 #
477 ################################################################################
478
479 def test_files_with_spaces_in_their_name():
480 """Regression test making sure test result files get created correctly when
481 testing files with spaces in their name.
482 """
483
484 t = BoostBuild.Tester(use_test_config=False)
485
486 t.write("valid source.cpp", "int main() {}\n");
487
488 t.write("invalid source.cpp", "this is not valid source code");
489
490 t.write("jamroot.jam", """
491 import testing ;
492 testing.compile "valid source.cpp" ;
493 testing.compile-fail "invalid source.cpp" ;
494 """)
495
496 t.run_build_system(status=0)
497 t.expect_addition("bin/invalid source.test/$toolset/debug*/invalid source.obj")
498 t.expect_addition("bin/invalid source.test/$toolset/debug*/invalid source.test")
499 t.expect_addition("bin/valid source.test/$toolset/debug*/valid source.obj")
500 t.expect_addition("bin/valid source.test/$toolset/debug*/valid source.test")
501
502 t.expect_content("bin/valid source.test/$toolset/debug*/valid source.test", \
503 "passed" )
504 t.expect_content( \
505 "bin/invalid source.test/$toolset/debug*/invalid source.test", \
506 "passed" )
507 t.expect_content( \
508 "bin/invalid source.test/$toolset/debug*/invalid source.obj", \
509 "failed as expected" )
510
511 t.cleanup()
512
513
514 ################################################################################
515 #
516 # main()
517 # ------
518 #
519 ################################################################################
520
521 test_run()
522 test_run_fail()
523 test_run_change()
524 test_run_path()
525 test_run_args()
526 test_link()
527 test_link_fail()
528 test_link_change()
529 test_compile()
530 test_compile_fail()
531 test_compile_change()
532 test_remove_test_targets("--remove-test-targets")
533 test_remove_test_targets("preserve-test-targets=off")
534 test_dump_tests()
535 test_files_with_spaces_in_their_name()