1#!/usr/local/bin/python3.8
2#
3# Copyright (c) 2008 Steven Watanabe
4#
5# Distributed under the Boost Software License, Version 1.0. (See
6# accompanying file LICENSE_1_0.txt) or copy at
7# http://www.boost.org/LICENSE_1_0.txt)
8
9import BoostBuild
10
11def test_default_order():
12    tester = BoostBuild.Tester(use_test_config=False)
13    tester.write("jamroot.jam", """
14
15    import order ;
16    import "class" : new ;
17
18    obj test : test.cpp : <include>b <include>a ;
19    """)
20
21    tester.write("test.cpp", """
22    #include <test.hpp>
23    int main() { f(); }
24    """)
25
26    tester.write("a/test.hpp", """
27    void f();
28    """)
29
30    tester.write("b/test.hpp", """
31    """)
32
33    tester.run_build_system()
34
35    tester.expect_addition("bin/$toolset/debug*/test.obj")
36
37    # Check that the dependencies are correct
38    tester.touch("a/test.hpp")
39    tester.run_build_system()
40    tester.expect_touch("bin/$toolset/debug*/test.obj")
41    tester.expect_nothing_more()
42
43    tester.touch("b/test.hpp")
44    tester.run_build_system()
45    tester.expect_nothing_more()
46
47    tester.cleanup()
48
49def test_default_order_mixed():
50    tester = BoostBuild.Tester(use_test_config=False)
51    tester.write("jamroot.jam", """
52
53    import order ;
54    import "class" : new ;
55
56    obj test : test.cpp : <include>b <include>a <include>c&&d ;
57    """)
58
59    tester.write("test.cpp", """
60    #include <test.hpp>
61    int main() { f(); }
62    """)
63
64    tester.write("a/test.hpp", """
65    void f();
66    """)
67
68    tester.write("b/test.hpp", """
69    """)
70
71    tester.run_build_system()
72
73    tester.expect_addition("bin/$toolset/debug*/test.obj")
74
75    # Check that the dependencies are correct
76    tester.touch("a/test.hpp")
77    tester.run_build_system()
78    tester.expect_touch("bin/$toolset/debug*/test.obj")
79    tester.expect_nothing_more()
80
81    tester.touch("b/test.hpp")
82    tester.run_build_system()
83    tester.expect_nothing_more()
84
85    tester.cleanup()
86
87def test_basic():
88    tester = BoostBuild.Tester(use_test_config=False)
89    tester.write("jamroot.jam", """
90    obj test : test.cpp : <include>a&&b ;
91    """)
92
93    tester.write("test.cpp", """
94    #include <test1.hpp>
95    #include <test2.hpp>
96    int main() {}
97    """)
98
99    tester.write("a/test1.hpp", """
100    """)
101
102    tester.write("b/test2.hpp", """
103    """)
104
105    tester.run_build_system()
106
107    tester.expect_addition("bin/$toolset/debug*/test.obj")
108
109    # Check that the dependencies are correct
110    tester.touch("a/test1.hpp")
111    tester.run_build_system()
112    tester.expect_touch("bin/$toolset/debug*/test.obj")
113
114    tester.touch("b/test2.hpp")
115    tester.run_build_system()
116    tester.expect_touch("bin/$toolset/debug*/test.obj")
117
118    tester.cleanup()
119
120def test_order1():
121    t = BoostBuild.Tester(use_test_config=False)
122    t.write("jamroot.jam", """
123    obj test : test.cpp : <include>a&&b ;
124    """)
125    t.write("test.cpp", """
126    #include <test.h>
127    int main() {}
128    """)
129    t.write("a/test.h", """
130    """)
131    t.write("b/test.h", """
132    #error should find a/test.h
133    """)
134    t.run_build_system()
135
136    t.touch("a/test.h")
137    t.run_build_system()
138    t.expect_touch("bin/$toolset/debug*/test.obj")
139    t.expect_nothing_more()
140
141    t.touch("b/test.h")
142    t.run_build_system()
143    t.expect_nothing_more()
144
145    t.cleanup()
146
147def test_order2():
148    t = BoostBuild.Tester(use_test_config=False)
149    t.write("jamroot.jam", """
150    obj test : test.cpp : <include>b&&a ;
151    """)
152    t.write("test.cpp", """
153    #include <test.h>
154    int main() {}
155    """)
156    t.write("a/test.h", """
157    #error should find b/test.h
158    """)
159    t.write("b/test.h", """
160    """)
161    t.run_build_system()
162
163    t.touch("a/test.h")
164    t.run_build_system()
165    t.expect_nothing_more()
166
167    t.touch("b/test.h")
168    t.run_build_system()
169    t.expect_touch("bin/$toolset/debug*/test.obj")
170    t.expect_nothing_more()
171
172    t.cleanup()
173
174def test_order_graph():
175    t = BoostBuild.Tester(use_test_config=False)
176    t.write("jamroot.jam", """
177    obj test : test.cpp :
178        <include>b&&a
179        <include>c&&b
180        <include>a
181        <include>c
182        <include>b
183        <include>e&&b&&d
184      ;
185    """)
186    t.write("test.cpp", """
187    #include <test1.h>
188    #include <test2.h>
189    #include <test3.h>
190    #include <test4.h>
191    int main() {}
192    """)
193    t.write("b/test1.h", "")
194    t.write("a/test1.h", "#error should find b/test1.h\n")
195
196    t.write("c/test2.h", "")
197    t.write("b/test2.h", "#error should find c/test2.h\n")
198
199    t.write("e/test3.h", "")
200    t.write("b/test3.h", "#error should find e/test3.h\n")
201
202    t.write("b/test4.h", "")
203    t.write("d/test4.h", "#error should find b/test4.h\n")
204
205    t.run_build_system()
206    t.expect_addition("bin/$toolset/debug*/test.obj")
207
208    t.touch("b/test1.h")
209    t.run_build_system()
210    t.expect_touch("bin/$toolset/debug*/test.obj")
211    t.expect_nothing_more()
212
213    t.touch("a/test1.h")
214    t.run_build_system()
215    t.expect_nothing_more()
216
217    t.touch("c/test2.h")
218    t.run_build_system()
219    t.expect_touch("bin/$toolset/debug*/test.obj")
220    t.expect_nothing_more()
221
222    t.touch("b/test2.h")
223    t.run_build_system()
224    t.expect_nothing_more()
225
226    t.touch("e/test3.h")
227    t.run_build_system()
228    t.expect_touch("bin/$toolset/debug*/test.obj")
229    t.expect_nothing_more()
230
231    t.touch("b/test3.h")
232    t.run_build_system()
233    t.expect_nothing_more()
234
235    t.touch("b/test4.h")
236    t.run_build_system()
237    t.expect_touch("bin/$toolset/debug*/test.obj")
238    t.expect_nothing_more()
239
240    t.touch("d/test4.h")
241    t.run_build_system()
242    t.expect_nothing_more()
243
244    t.cleanup()
245
246test_default_order()
247test_default_order_mixed()
248test_basic()
249test_order1()
250test_order2()
251test_order_graph()
252