Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / v2 / test / regression.py
1 #!/usr/bin/python
2
3 # Copyright (C) Vladimir Prus 2003.
4 # Distributed under the Boost Software License, Version 1.0.
5 #    (See accompanying file LICENSE_1_0.txt or copy at
6 #         http://www.boost.org/LICENSE_1_0.txt)
7
8 # Test for the regression testing framework.
9
10 import BoostBuild
11
12 # Create a temporary working directory.
13 t = BoostBuild.Tester()
14
15 t.write("c.cpp", "\n")
16
17 t.write("r.cpp", """
18 void helper();
19
20 #include <iostream>
21 int main( int ac, char * av[] )
22 {
23     helper();
24     for ( int i = 1; i < ac; ++i )
25        std::cout << av[ i ] << '\\n';
26 }
27 """)
28
29 t.write("c-f.cpp", """
30 int
31 """)
32
33 t.write("r-f.cpp", """
34 int main() { return 1; }
35 """)
36
37
38 t.write("jamfile.jam", """
39 import testing ;
40 compile c.cpp ;
41 compile-fail c-f.cpp ;
42 run r.cpp libs//helper : foo bar ;
43 run-fail r-f.cpp ;
44 """)
45
46 t.write("libs/jamfile.jam", """
47 lib helper : helper.cpp ;
48 """)
49
50 t.write("libs/helper.cpp", """
51 void
52 #if defined(_WIN32)
53 __declspec(dllexport)
54 #endif
55 helper() {}
56 """)
57
58 t.write("jamroot.jam", "")
59
60 # First test that when outcomes are expected, all .test files are created.
61 t.run_build_system("hardcode-dll-paths=false", stderr=None, status=None)
62 t.expect_addition("bin/c.test/$toolset/debug/c.test")
63 t.expect_addition("bin/c-f.test/$toolset/debug/c-f.test")
64 t.expect_addition("bin/r.test/$toolset/debug/r.test")
65 t.expect_addition("bin/r-f.test/$toolset/debug/r-f.test")
66
67 # Make sure args are handled.
68 t.expect_content("bin/r.test/$toolset/debug/r.output",
69                  "foo\nbar\n*\nEXIT STATUS: 0*\n", True)
70
71 # Test that input file is handled as well.
72 t.write("r.cpp", """
73 #include <iostream>
74 #include <fstream>
75 int main( int ac, char * av[] )
76 {
77     for ( int i = 1; i < ac; ++i )
78     {
79         std::ifstream ifs( av[ i ] );
80         std::cout << ifs.rdbuf();
81     }
82 }
83 """)
84
85 t.write("dir/input.txt", "test input")
86
87 t.write("jamfile.jam", """
88 import testing ;
89 compile c.cpp ;
90 obj c-obj : c.cpp ;
91 compile-fail c-f.cpp ;
92 run r.cpp : : dir/input.txt ;
93 run-fail r-f.cpp ;
94 time execution : r ;
95 time compilation : c-obj ;
96 """)
97
98 t.run_build_system('hardcode-dll-paths=false')
99 t.expect_content("bin/r.test/$toolset/debug/r.output",
100                  "test input\nEXIT STATUS: 0\n")
101
102 t.expect_addition('bin/$toolset/debug/execution.time')
103 t.expect_addition('bin/$toolset/debug/compilation.time')
104
105 # Make sure test failures are detected. Reverse expectation and see if .test
106 # files are created or not.
107 t.write("jamfile.jam", """
108 import testing ;
109
110 compile-fail c.cpp ;
111 compile c-f.cpp ;
112 run-fail r.cpp : : dir/input.txt ;
113 run r-f.cpp ;
114 """)
115
116 t.touch(BoostBuild.List("c.cpp c-f.cpp r.cpp r-f.cpp"))
117
118 t.run_build_system("hardcode-dll-paths=false", stderr=None, status=1)
119 t.expect_removal("bin/c.test/$toolset/debug/c.test")
120 t.expect_removal("bin/c-f.test/$toolset/debug/c-f.test")
121 t.expect_removal("bin/r.test/$toolset/debug/r.test")
122 t.expect_removal("bin/r-f.test/$toolset/debug/r-f.test")
123
124 t.cleanup()