Added fix for TeX includes with same name as subdirs.
[scons.git] / test / overrides.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 import TestSCons
28
29
30 test = TestSCons.TestSCons()
31
32
33 _python_ = TestSCons._python_
34
35 test.write('SConstruct', """
36 env = Environment(CCFLAGS='-DFOO', LIBS=['a'])
37 def build(target, source, env):
38     print "env['CC'] =", env['CC']
39     print "env['CCFLAGS'] =", env['CCFLAGS']
40     print "env['LIBS'] =", env['LIBS']
41 builder = Builder(action=build, CC='buildcc', LIBS='buildlibs')
42 env['BUILDERS']['Build'] = builder
43
44 foo = env.Build('foo.out', 'foo.in',
45                 CC='mycc',
46                 CCFLAGS='$CCFLAGS -DBAR',
47                 LIBS = env['LIBS']+['b'])
48 bar = env.Build('bar.out', 'bar.in')
49 Default([foo, bar])
50 """)
51
52 test.write('foo.in', "foo.in\n")
53 test.write('bar.in', "bar.in\n")
54
55 test.run(arguments = "-Q", stdout = """\
56 build(["foo.out"], ["foo.in"])
57 env['CC'] = mycc
58 env['CCFLAGS'] = -DFOO -DBAR
59 env['LIBS'] = ['a', 'b']
60 build(["bar.out"], ["bar.in"])
61 env['CC'] = buildcc
62 env['CCFLAGS'] = -DFOO
63 env['LIBS'] = buildlibs
64 """)
65
66
67
68 test.write('SConstruct', """
69 env = Environment()
70 env.Program('hello', 'hello.c',
71             CC=r'%(_python_)s mycc.py',
72             LINK=r'%(_python_)s mylink.py',
73             OBJSUFFIX='.not_obj',
74             PROGSUFFIX='.not_exe')
75 """ % locals())
76
77 test.write('hello.c',"this ain't no c file!\n")
78
79 test.write('mycc.py',"""
80 open('hello.not_obj', 'wt').write('this is no object file!')
81 """)
82
83 test.write('mylink.py',"""
84 open('hello.not_exe', 'wt').write('this is not a program!')
85 """)
86
87 test.run(arguments='hello.not_exe')
88
89 assert test.read('hello.not_obj') == 'this is no object file!'
90 assert test.read('hello.not_exe') == 'this is not a program!'
91
92 test.up_to_date(arguments='hello.not_exe')
93
94
95
96 test.write('SConstruct', """\
97 env = Environment()
98 env.Program('goodbye', 'goodbye.c',
99             CC=r'%(_python_)s mycc.py',
100             LINK=r'%(_python_)s mylink.py',
101             OBJSUFFIX='.not_obj',
102             PROGSUFFIX='.not_exe',
103             targets='ttt',
104             sources='sss')
105 """ % locals())
106
107 test.write('goodbye.c',"this ain't no c file!\n")
108
109 test.write('mycc.py',"""
110 open('goodbye.not_obj', 'wt').write('this is no object file!')
111 """)
112
113 test.write('mylink.py',"""
114 open('goodbye.not_exe', 'wt').write('this is not a program!')
115 """)
116
117 test.run(arguments='goodbye.not_exe', stderr=None)
118 test.fail_test(not test.match_re(test.stderr(), r"""
119 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
120 """ + TestSCons.file_expr + r"""
121 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
122 """ + TestSCons.file_expr))
123
124 assert test.read('goodbye.not_obj') == 'this is no object file!'
125 assert test.read('goodbye.not_exe') == 'this is not a program!'
126
127
128
129 test.pass_test()
130
131 # Local Variables:
132 # tab-width:4
133 # indent-tabs-mode:nil
134 # End:
135 # vim: set expandtab tabstop=4 shiftwidth=4: