added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / option / tree-all.py
blob6222ba1ac94e0f38d1fb41d90df9cdbdf5c78bb4
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Test that the --tree=all option prints a tree representation of the
29 complete dependencies of a target.
30 """
32 import TestSCons
33 import sys
35 test = TestSCons.TestSCons()
37 CC = test.detect('CC')
38 LINK = test.detect('LINK')
39 if LINK is None: LINK = CC
41 test.write('SConstruct', """
42 DefaultEnvironment(tools=[])
43 env = Environment(OBJSUFFIX = '.ooo', PROGSUFFIX = '.xxx')
44 env.Program('Foo', Split('Foo.c Bar.c'))
45 """)
47 # N.B.: We use upper-case file names (Foo* and Bar*) so that the sorting
48 # order with our upper-case SConstruct file is the same on case-sensitive
49 # (UNIX/Linux) and case-insensitive (Windows) systems.
51 test.write('Foo.c', r"""
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include "Foo.h"
55 int main(int argc, char *argv[])
57 argv[argc++] = "--";
58 printf("f1.c\n");
59 exit (0);
61 """)
63 test.write('Bar.c', """
64 #include "Bar.h"
65 int local = 1;
66 """)
68 test.write('Foo.h', """
69 #ifndef FOO_H
70 #define FOO_H
71 #include "Bar.h"
72 #endif
73 """)
75 test.write('Bar.h', """
76 #ifndef BAR_H
77 #define BAR_H
78 #include "Foo.h"
79 #endif
80 """)
82 tree1 = """
83 +-Foo.xxx
84 +-Foo.ooo
85 | +-Foo.c
86 | +-Foo.h
87 | +-Bar.h
88 | +-%(CC)s
89 +-Bar.ooo
90 | +-Bar.c
91 | +-Bar.h
92 | +-Foo.h
93 | +-%(CC)s
94 +-%(LINK)s
95 """ % locals()
97 test.run(arguments = "--tree=all Foo.xxx")
98 if test.stdout().count(tree1) != 1:
99 sys.stdout.write('Did not find expected tree (or found duplicate) in the following output:\n')
100 sys.stdout.write(test.stdout())
101 test.fail_test()
103 tree2 = """
105 +-Bar.c
106 +-Bar.h
107 +-Bar.ooo
108 | +-Bar.c
109 | +-Bar.h
110 | +-Foo.h
111 | +-%(CC)s
112 +-Foo.c
113 +-Foo.h
114 +-Foo.ooo
115 | +-Foo.c
116 | +-Foo.h
117 | +-Bar.h
118 | +-%(CC)s
119 +-Foo.xxx
120 | +-Foo.ooo
121 | | +-Foo.c
122 | | +-Foo.h
123 | | +-Bar.h
124 | | +-%(CC)s
125 | +-Bar.ooo
126 | | +-Bar.c
127 | | +-Bar.h
128 | | +-Foo.h
129 | | +-%(CC)s
130 | +-%(LINK)s
131 +-SConstruct
132 """ % locals()
134 test.run(arguments = "--tree=all .")
135 test.must_contain_all_lines(test.stdout(), [tree2])
137 tree3 = """
139 +-Bar.c
140 +-Bar.h
141 +-Bar.ooo
142 | +-Bar.c
143 | +-Bar.h
144 | +-Foo.h
145 | +-%(CC)s
146 +-Foo.c
147 +-Foo.h
148 +-Foo.ooo
149 | +-Foo.c
150 | +-Foo.h
151 | +-Bar.h
152 | +-%(CC)s
153 +-Foo.xxx
154 | +-[Foo.ooo]
155 | +-[Bar.ooo]
156 | +-%(LINK)s
157 +-SConstruct
158 """ % locals()
160 test.run(arguments = "--tree=all,prune .")
161 if test.stdout().count(tree3) != 1:
162 sys.stdout.write('Did not find expected tree (or found duplicate) in the following output:\n')
163 sys.stdout.write(test.stdout())
164 test.fail_test()
166 test.run(arguments = "--tree=prune .")
167 if test.stdout().count(tree3) != 1:
168 sys.stdout.write('Did not find expected tree (or found duplicate) in the following output:\n')
169 sys.stdout.write(test.stdout())
170 test.fail_test()
172 tree4 = """
173 E = exists
174 R = exists in repository only
175 b = implicit builder
176 B = explicit builder
177 S = side effect
178 P = precious
179 A = always build
180 C = current
181 N = no clean
182 H = no cache
184 [ B ]+-Foo.xxx
185 [ B ] +-Foo.ooo
186 [E C ] | +-Foo.c
187 [E C ] | +-Foo.h
188 [E C ] | +-Bar.h
189 [E C ] | +-%(CC)s
190 [ B ] +-Bar.ooo
191 [E C ] | +-Bar.c
192 [E C ] | +-Bar.h
193 [E C ] | +-Foo.h
194 [E C ] | +-%(CC)s
195 [E C ] +-%(LINK)s
196 """ % locals()
198 test.run(arguments = '-c Foo.xxx')
200 test.run(arguments = "--no-exec --tree=all,status Foo.xxx")
201 if test.stdout().count(tree4) != 1:
202 sys.stdout.write('Did not find expected tree (or found duplicate) in the following output:\n')
203 sys.stdout.write(test.stdout())
204 test.fail_test()
206 test.run(arguments = "--no-exec --tree=status Foo.xxx")
207 if test.stdout().count(tree4) != 1:
208 sys.stdout.write('Did not find expected tree (or found duplicate) in the following output:\n')
209 sys.stdout.write(test.stdout())
210 test.fail_test()
212 # Make sure we print the debug stuff even if there's a build failure.
213 test.write('Bar.h', """
214 #ifndef BAR_H
215 #define BAR_H
216 #include "Foo.h"
217 #endif
218 THIS SHOULD CAUSE A BUILD FAILURE
219 """)
221 test.run(arguments = "--tree=all Foo.xxx",
222 status = 2,
223 stderr = None)
224 if test.stdout().count(tree1) != 1:
225 sys.stdout.write('Did not find expected tree (or found duplicate) in the following output:\n')
226 sys.stdout.write(test.stdout())
227 test.fail_test()
229 test.pass_test()
231 # Local Variables:
232 # tab-width:4
233 # indent-tabs-mode:nil
234 # End:
235 # vim: set expandtab tabstop=4 shiftwidth=4: