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__"
28 Test the explicit Exit() function.
35 test
= TestSCons
.TestSCons()
39 subdir_foo_in
= os
.path
.join('subdir', 'foo.in')
40 subdir_foo_out
= os
.path
.join('subdir', 'foo.out')
42 test
.write('SConstruct', """\
43 print("SConstruct, Exit()")
47 test
.run(stdout
= """\
48 scons: Reading SConscript files ...
52 test
.write('SConstruct', """\
54 print("SConstruct, env.Exit()")
58 test
.run(stdout
= """\
59 scons: Reading SConscript files ...
60 SConstruct, env.Exit()
63 test
.write('SConstruct', """\
68 test
.run(status
= 7, stdout
= """\
69 scons: Reading SConscript files ...
73 test
.write('SConstruct', """\
75 SConscript('subdir/SConscript')
78 test
.write(['subdir', 'SConscript'], """\
79 print("subdir/SConscript")
83 test
.run(stdout
= """\
84 scons: Reading SConscript files ...
89 test
.write(['subdir', 'SConscript'], """\
90 print("subdir/SConscript")
94 test
.run(status
= 17, stdout
= """\
95 scons: Reading SConscript files ...
100 test
.write('SConstruct', """\
101 SConscript('subdir/SConscript')
104 test
.write(['subdir', 'SConscript'], """\
105 def exit_builder(env, source, target):
106 target = str(target[0])
107 with open(target, "wb") as f:
109 with open(str(src), "rb") as ifp:
112 env = Environment(BUILDERS = {'my_exit' : Builder(action=exit_builder)})
113 env.my_exit('foo.out', 'foo.in')
116 test
.write(['subdir', 'foo.in'], "subdir/foo.in\n")
118 test
.run(status
= 27,
119 stdout
= test
.wrap_stdout("""\
120 exit_builder(["%s"], ["%s"])
121 """ % (subdir_foo_out
, subdir_foo_in
), error
=1),
123 scons: *** [%s] Explicit exit, status 27
124 """ % subdir_foo_out
)
126 test
.must_match(['subdir', 'foo.out'], "subdir/foo.in\n")
128 test
.write('SConstruct', """\
129 def exit_scanner(node, env, target):
132 exitscan = Scanner(function = exit_scanner, skeys = ['.k'])
134 def cat(env, source, target):
135 target = str(target[0])
136 with open(target, 'wb') as ofp:
138 with open(str(src), "rb") as ifp:
139 outf.write(ifp.read())
141 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
142 env.Append(SCANNERS = [exitscan])
144 env.Cat('foo', 'foo.k')
147 test
.write('foo.k', "foo.k\n")
149 test
.run(status
= 37,
150 stdout
= test
.wrap_stdout("", error
=1),
151 stderr
= "scons: *** [foo] Explicit exit, status 37\n")
158 # indent-tabs-mode:nil
160 # vim: set expandtab tabstop=4 shiftwidth=4: