added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Exit.py
blobabaa382c0ab2b21df7ff2e8d783ea66265051086
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 explicit Exit() function.
29 """
31 import os.path
33 import TestSCons
35 test = TestSCons.TestSCons()
37 test.subdir('subdir')
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()")
44 Exit()
45 """)
47 test.run(stdout = """\
48 scons: Reading SConscript files ...
49 SConstruct, Exit()
50 """)
52 test.write('SConstruct', """\
53 env = Environment()
54 print("SConstruct, env.Exit()")
55 env.Exit()
56 """)
58 test.run(stdout = """\
59 scons: Reading SConscript files ...
60 SConstruct, env.Exit()
61 """)
63 test.write('SConstruct', """\
64 print("SConstruct")
65 Exit(7)
66 """)
68 test.run(status = 7, stdout = """\
69 scons: Reading SConscript files ...
70 SConstruct
71 """)
73 test.write('SConstruct', """\
74 print("SConstruct")
75 SConscript('subdir/SConscript')
76 """)
78 test.write(['subdir', 'SConscript'], """\
79 print("subdir/SConscript")
80 Exit()
81 """)
83 test.run(stdout = """\
84 scons: Reading SConscript files ...
85 SConstruct
86 subdir/SConscript
87 """)
89 test.write(['subdir', 'SConscript'], """\
90 print("subdir/SConscript")
91 Exit(17)
92 """)
94 test.run(status = 17, stdout = """\
95 scons: Reading SConscript files ...
96 SConstruct
97 subdir/SConscript
98 """)
100 test.write('SConstruct', """\
101 SConscript('subdir/SConscript')
102 """)
104 test.write(['subdir', 'SConscript'], """\
105 def exit_builder(env, source, target):
106 target = str(target[0])
107 with open(target, "wb") as f:
108 for src in source:
109 with open(str(src), "rb") as ifp:
110 f.write(ifp.read())
111 Exit(27)
112 env = Environment(BUILDERS = {'my_exit' : Builder(action=exit_builder)})
113 env.my_exit('foo.out', 'foo.in')
114 """)
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),
122 stderr = """\
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):
130 Exit(37)
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:
137 for src in source:
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')
145 """)
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")
154 test.pass_test()
156 # Local Variables:
157 # tab-width:4
158 # indent-tabs-mode:nil
159 # End:
160 # vim: set expandtab tabstop=4 shiftwidth=4: