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