Merge pull request #4584 from siegria/fix_piped_spawn_encoding
[scons.git] / test / overrides.py
blob54a174b9a70658dd84d922d03143df0b4ccff08b
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 import TestSCons
30 test = TestSCons.TestSCons()
33 _python_ = TestSCons._python_
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'] = "+str(env['LIBS']))
41 builder = Builder(action=build, CC='buildcc', LIBS='buildlibs')
42 env['BUILDERS']['Build'] = builder
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 """)
52 test.write('foo.in', "foo.in\n")
53 test.write('bar.in', "bar.in\n")
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 """)
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())
77 test.write('hello.c',"this ain't no c file!\n")
79 test.write('mycc.py',"""
80 with open('hello.not_obj', 'w') as f:
81 f.write('this is no object file!')
82 """)
84 test.write('mylink.py',"""
85 with open('hello.not_exe', 'w') as f:
86 f.write('this is not a program!')
87 """)
89 test.run(arguments='hello.not_exe')
91 assert test.read('hello.not_obj', mode='r') == 'this is no object file!'
92 assert test.read('hello.not_exe', mode='r') == 'this is not a program!'
94 test.up_to_date(arguments='hello.not_exe')
98 test.write('SConstruct', """\
99 env = Environment()
100 env.Program('goodbye', 'goodbye.c',
101 CC=r'%(_python_)s mycc.py',
102 LINK=r'%(_python_)s mylink.py',
103 OBJSUFFIX='.not_obj',
104 PROGSUFFIX='.not_exe',
105 targets='ttt',
106 sources='sss')
107 """ % locals())
109 test.write('goodbye.c',"this ain't no c file!\n")
111 test.write('mycc.py',"""
112 with open('goodbye.not_obj', 'wt') as f:
113 f.write('this is no object file!')
114 """)
116 test.write('mylink.py',"""
117 with open('goodbye.not_exe', 'wt') as f:
118 f.write('this is not a program!')
119 """)
121 test.run(arguments='goodbye.not_exe', stderr=None)
122 test.fail_test(not test.match_re(test.stderr(), r"""
123 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
124 """ + TestSCons.file_expr + r"""
125 scons: warning: Did you mean to use `(target|source)' instead of `(targets|sources)'\?
126 """ + TestSCons.file_expr))
128 assert test.read('goodbye.not_obj', mode='r') == 'this is no object file!'
129 assert test.read('goodbye.not_exe', mode='r') == 'this is not a program!'
133 test.pass_test()
135 # Local Variables:
136 # tab-width:4
137 # indent-tabs-mode:nil
138 # End:
139 # vim: set expandtab tabstop=4 shiftwidth=4: