[ci skip] remove umerged conflict markers in RELEASE.txt
[scons.git] / test / CPPSUFFIXES.py
blob9b8dd9089f404dfc329188f04fb3559adf72ed20
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 the ability to scan additional filesuffixes added to $CPPSUFFIXES.
29 """
31 import TestSCons
33 _python_ = TestSCons._python_
35 test = TestSCons.TestSCons()
37 test.write('mycc.py', r"""
38 import sys
39 def do_file(outf, inf):
40 with open(inf, 'r') as ifp:
41 for line in ifp.readlines():
42 if line[:10] == '#include <':
43 do_file(outf, line[10:-2])
44 else:
45 outf.write(line)
46 with open(sys.argv[1], 'w') as outf:
47 for f in sys.argv[2:]:
48 do_file(outf, f)
49 sys.exit(0)
50 """)
52 test.write('SConstruct', """
53 DefaultEnvironment(tools=[])
54 env = Environment(CPPPATH = ['.'],
55 CC = r'%(_python_)s mycc.py',
56 CCFLAGS = [],
57 CCCOM = '$CC $TARGET $SOURCES',
58 OBJSUFFIX = '.o')
59 env.Append(CPPSUFFIXES = ['.x'])
60 env.Object(target = 'test1', source = 'test1.c')
61 env.InstallAs('test1_c', 'test1.c')
62 env.InstallAs('test1_h', 'test1.h')
63 env.InstallAs('test1_x', 'test1.x')
64 """ % locals())
66 test.write('test1.c', """\
67 test1.c 1
68 #include <test1.h>
69 #include <test1.x>
70 """)
72 test.write('test1.h', """\
73 test1.h 1
74 #include <foo.h>
75 """)
77 test.write('test1.x', """\
78 test1.x 1
79 #include <foo.h>
80 """)
82 test.write('foo.h', "foo.h 1\n")
84 expect = test.wrap_stdout("""\
85 %(_python_)s mycc.py test1.o test1.c
86 Install file: "test1.c" as "test1_c"
87 Install file: "test1.h" as "test1_h"
88 Install file: "test1.x" as "test1_x"
89 """ % locals())
91 test.run(arguments='.', stdout=expect)
93 test.must_match('test1.o', """\
94 test1.c 1
95 test1.h 1
96 foo.h 1
97 test1.x 1
98 foo.h 1
99 """, mode='r')
101 test.up_to_date(arguments='.')
103 test.write('foo.h', "foo.h 2\n")
105 expect = test.wrap_stdout("""\
106 %(_python_)s mycc.py test1.o test1.c
107 """ % locals())
109 test.run(arguments='.', stdout=expect)
111 test.must_match('test1.o', """\
112 test1.c 1
113 test1.h 1
114 foo.h 2
115 test1.x 1
116 foo.h 2
117 """, mode='r')
119 test.up_to_date(arguments='.')
121 test.write('test1.x', """\
122 test1.x 2
123 #include <foo.h>
124 """)
126 expect = test.wrap_stdout("""\
127 %(_python_)s mycc.py test1.o test1.c
128 Install file: "test1.x" as "test1_x"
129 """ % locals())
131 test.run(arguments='.', stdout=expect)
133 test.must_match('test1.o', """\
134 test1.c 1
135 test1.h 1
136 foo.h 2
137 test1.x 2
138 foo.h 2
139 """, mode='r')
141 test.up_to_date(arguments='.')
143 test.write('test1.h', """\
144 test1.h 2
145 #include <foo.h>
146 """)
148 expect = test.wrap_stdout("""\
149 %(_python_)s mycc.py test1.o test1.c
150 Install file: "test1.h" as "test1_h"
151 """ % locals())
153 test.run(arguments='.', stdout=expect)
155 test.must_match('test1.o', """\
156 test1.c 1
157 test1.h 2
158 foo.h 2
159 test1.x 2
160 foo.h 2
161 """, mode='r')
163 test.up_to_date(arguments='.')
165 test.pass_test()
167 # Local Variables:
168 # tab-width:4
169 # indent-tabs-mode:nil
170 # End:
171 # vim: set expandtab tabstop=4 shiftwidth=4: