Merged revisions 2454-2525 via svnmerge from
[scons.git] / test / option / debug-includes.py
1 #!/usr/bin/env python
2 #
3 # __COPYRIGHT__
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23 #
24
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
26
27 """
28 Test that the --debug=includes option prints the implicit
29 dependencies of a target.
30 """
31
32 import TestSCons
33 import sys
34 import string
35 import re
36 import time
37
38 test = TestSCons.TestSCons()
39
40 test.write('SConstruct', """
41 env = Environment(OBJSUFFIX = '.ooo', PROGSUFFIX = '.xxx')
42 env.Program('foo', Split('foo.c bar.c'))
43 """)
44
45 test.write('foo.c', r"""
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include "foo.h"
49 int main(int argc, char *argv[])
50 {
51         argv[argc++] = "--";
52         printf("f1.c\n");
53         exit (0);
54 }
55 """)
56
57 test.write('bar.c', """
58 #include "bar.h"
59 int local = 1;
60 """)
61
62 test.write('foo.h', """
63 #ifndef FOO_H
64 #define FOO_H
65 #include "bar.h"
66 #endif
67 """)
68
69 test.write('bar.h', """
70 #ifndef BAR_H
71 #define BAR_H
72 #include "foo.h"
73 #endif
74 """)
75
76 includes = """
77 +-foo.c
78   +-foo.h
79     +-bar.h
80 """
81 test.run(arguments = "--debug=includes foo.ooo")
82 test.fail_test(string.find(test.stdout(), includes) == -1)
83
84 # In an ideal world, --debug=includes would also work when there's a build
85 # failure, but this would require even more complicated logic to scan
86 # all of the intermediate nodes that get skipped when the build failure
87 # occurs.  On the YAGNI theory, we're just not going to worry about this
88 # until it becomes an issue that someone actually cares enough about.
89
90 #test.write('bar.h', """
91 ##ifndef BAR_H
92 ##define BAR_H
93 ##include "foo.h"
94 ##endif
95 #THIS SHOULD CAUSE A BUILD FAILURE
96 #""")
97
98 #test.run(arguments = "--debug=includes foo.xxx",
99 #         status = 2,
100 #         stderr = None)
101 #test.fail_test(string.find(test.stdout(), includes) == -1)
102
103 # These shouldn't print out anything in particular, but
104 # they shouldn't crash either:
105 test.run(arguments = "--debug=includes .")
106 test.run(arguments = "--debug=includes foo.c")
107
108 test.pass_test()