]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/test/testing.py
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)
8 # Tests different aspects of Boost Builds automated testing support.
14 t
= BoostBuild
.Tester(use_test_config
=False)
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")
21 t
.write("Jamroot.jam", """import testing ;
23 run fail-compile.cpp ;
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")
35 t
.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
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")
41 t
.expect_nothing_more()
46 t
= BoostBuild
.Tester(use_test_config
=False)
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")
53 t
.write("Jamroot.jam", """import testing ;
55 run-fail fail-compile.cpp ;
56 run-fail fail-link.cpp ;
57 run-fail fail-run.cpp ;
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")
65 t
.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
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")
73 t
.expect_nothing_more()
77 def test_run_change():
78 """Tests that the test file is removed when a test fails after it
81 t
= BoostBuild
.Tester(use_test_config
=False)
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")
88 t
.write("Jamroot.jam", """import testing ;
90 run fail-compile.cpp ;
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)
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)
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")
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)
127 __declspec(dllexport)
131 t
.write("pass.cpp", "void f(); int main() { f(); }\n")
133 t
.write("Jamroot.jam", """import testing ;
134 lib l : l.cpp : <link>shared ;
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")
150 """Tests the handling of args and input-files"""
151 t
= BoostBuild
.Tester(use_test_config
=False)
152 t
.write("test.cpp", """
155 int main(int argc, const char ** argv)
157 for(int i = 1; i < argc; ++i)
159 if(argv[i][0] == '-')
161 std::cout << argv[i] << std::endl;
165 std::ifstream ifs(argv[i]);
166 std::cout << ifs.rdbuf();
171 t
.write("input1.in", "first input\n")
172 t
.write("input2.in", "second input\n")
173 t
.write("Jamroot.jam", """import testing ;
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 ;
186 t
.expect_content("bin/test.test/$toolset/debug*/test.output", """\
197 t
= BoostBuild
.Tester(use_test_config
=False)
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")
204 t
.write("Jamroot.jam", """import testing ;
206 link fail-compile.cpp ;
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")
216 t
.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.obj")
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")
222 t
.expect_nothing_more()
226 def test_link_fail():
227 t
= BoostBuild
.Tester(use_test_config
=False)
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")
234 t
.write("Jamroot.jam", """import testing ;
236 link-fail fail-compile.cpp ;
237 link-fail fail-link.cpp ;
238 link-fail fail-run.cpp ;
241 t
.run_build_system(status
=1)
242 t
.expect_addition("bin/pass.test/$toolset/debug*/pass.obj")
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")
248 t
.expect_addition("bin/fail-run.test/$toolset/debug*/fail-run.obj")
250 t
.expect_nothing_more()
254 def test_link_change():
255 """Tests that the test file is removed when a test fails after it
256 previously passed."""
258 t
= BoostBuild
.Tester(use_test_config
=False)
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")
264 t
.write("Jamroot.jam", """import testing ;
266 link fail-compile.cpp ;
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)
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)
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")
289 t
= BoostBuild
.Tester(use_test_config
=False)
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")
296 t
.write("Jamroot.jam", """import testing ;
298 compile fail-compile.cpp ;
299 compile fail-link.cpp ;
300 compile fail-run.cpp ;
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")
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")
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")
313 t
.expect_nothing_more()
317 def test_compile_fail():
318 t
= BoostBuild
.Tester(use_test_config
=False)
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")
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 ;
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")
336 t
.expect_nothing_more()
340 def test_compile_change():
341 """Tests that the test file is removed when a test fails after it
342 previously passed."""
344 t
= BoostBuild
.Tester(use_test_config
=False)
346 t
.write("pass.cpp", "#error expected to fail\n")
347 t
.write("fail-compile.cpp", "int main() {}\n")
349 t
.write("Jamroot.jam", """import testing ;
350 compile-fail pass.cpp ;
351 compile fail-compile.cpp ;
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)
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)
364 t
.expect_removal("bin/pass.test/$toolset/debug*/pass.test")
365 t
.expect_removal("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
369 def test_remove_test_targets(option
):
370 t
= BoostBuild
.Tester(use_test_config
=False)
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")
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 ;
390 t
.run_build_system([option
])
392 t
.expect_addition("bin/$toolset/debug*/source.obj")
394 t
.expect_addition("bin/pass-compile.test/$toolset/debug*/pass-compile.test")
396 t
.expect_addition("bin/pass-link.test/$toolset/debug*/pass-link.test")
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")
402 t
.expect_addition("bin/fail-compile.test/$toolset/debug*/fail-compile.test")
404 t
.expect_addition("bin/fail-link.test/$toolset/debug*/fail-link.test")
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")
410 t
.expect_nothing_more()
414 def test_dump_tests():
415 """Tests the output of the --dump-tests option"""
416 t
= BoostBuild
.Tester(use_test_config
=False)
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")
425 t
.write("Jamroot.jam", """import testing ;
427 run-fail fail-run.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 ;
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"
472 ################################################################################
474 # test_files_with_spaces_in_their_name()
475 # --------------------------------------
477 ################################################################################
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.
484 t
= BoostBuild
.Tester(use_test_config
=False)
486 t
.write("valid source.cpp", "int main() {}\n");
488 t
.write("invalid source.cpp", "this is not valid source code");
490 t
.write("jamroot.jam", """
492 testing.compile "valid source.cpp" ;
493 testing.compile-fail "invalid source.cpp" ;
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")
502 t
.expect_content("bin/valid source.test/$toolset/debug*/valid source.test", \
505 "bin/invalid source.test/$toolset/debug*/invalid source.test", \
508 "bin/invalid source.test/$toolset/debug*/invalid source.obj", \
509 "failed as expected" )
514 ################################################################################
519 ################################################################################
531 test_compile_change()
532 test_remove_test_targets("--remove-test-targets")
533 test_remove_test_targets("preserve-test-targets=off")
535 test_files_with_spaces_in_their_name()