Add emacs and vim editing settings to the bottom of *.py files.
[scons.git] / test / Exit.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 """
28 Test the explicit Exit() function.
29 """
30
31 import os.path
32
33 import TestSCons
34
35 test = TestSCons.TestSCons()
36
37 test.subdir('subdir')
38
39 subdir_foo_in = os.path.join('subdir', 'foo.in')
40 subdir_foo_out = os.path.join('subdir', 'foo.out')
41
42 test.write('SConstruct', """\
43 print "SConstruct, Exit()"
44 Exit()
45 """)
46
47 test.run(stdout = """\
48 scons: Reading SConscript files ...
49 SConstruct, Exit()
50 """)
51
52 test.write('SConstruct', """\
53 env = Environment()
54 print "SConstruct, env.Exit()"
55 env.Exit()
56 """)
57
58 test.run(stdout = """\
59 scons: Reading SConscript files ...
60 SConstruct, env.Exit()
61 """)
62
63 test.write('SConstruct', """\
64 print "SConstruct"
65 Exit(7)
66 """)
67
68 test.run(status = 7, stdout = """\
69 scons: Reading SConscript files ...
70 SConstruct
71 """)
72
73 test.write('SConstruct', """\
74 print "SConstruct"
75 SConscript('subdir/SConscript')
76 """)
77
78 test.write(['subdir', 'SConscript'], """\
79 print "subdir/SConscript"
80 Exit()
81 """)
82
83 test.run(stdout = """\
84 scons: Reading SConscript files ...
85 SConstruct
86 subdir/SConscript
87 """)
88
89 test.write(['subdir', 'SConscript'], """\
90 print "subdir/SConscript"
91 Exit(17)
92 """)
93
94 test.run(status = 17, stdout = """\
95 scons: Reading SConscript files ...
96 SConstruct
97 subdir/SConscript
98 """)
99
100 test.write('SConstruct', """\
101 SConscript('subdir/SConscript')
102 """)
103
104 test.write(['subdir', 'SConscript'], """\
105 def exit_builder(env, source, target):
106     target = str(target[0])
107     source = map(str, source)
108     f = open(target, "wb")
109     for src in source:
110         f.write(open(src, "rb").read())
111     f.close()
112     Exit(27)
113 env = Environment(BUILDERS = {'my_exit' : Builder(action=exit_builder)})
114 env.my_exit('foo.out', 'foo.in')
115 """)
116
117 test.write(['subdir', 'foo.in'], "subdir/foo.in\n")
118
119 test.run(status = 27,
120          stdout = test.wrap_stdout("""\
121 exit_builder(["%s"], ["%s"])
122 """ % (subdir_foo_out, subdir_foo_in), error=1),
123          stderr = """\
124 scons: *** [%s] Explicit exit, status 27
125 """ % (subdir_foo_out))
126
127 test.must_match(['subdir', 'foo.out'], "subdir/foo.in\n")
128
129 test.write('SConstruct', """\
130 def exit_scanner(node, env, target):
131     Exit(37)
132
133 exitscan = Scanner(function = exit_scanner, skeys = ['.k'])
134
135 def cat(env, source, target):
136     target = str(target[0])
137     source = map(str, source)
138
139     outf = open(target, 'wb')
140     for src in source:
141         outf.write(open(src, "rb").read())
142     outf.close()
143
144 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
145 env.Append(SCANNERS = [exitscan])
146
147 env.Cat('foo', 'foo.k')
148 """)
149
150 test.write('foo.k', "foo.k\n")
151
152 test.run(status = 37,
153          stdout = test.wrap_stdout("", error=1),
154          stderr = "scons: *** [foo] Explicit exit, status 37\n")
155
156 #
157 test.pass_test()
158
159 # Local Variables:
160 # tab-width:4
161 # indent-tabs-mode:nil
162 # End:
163 # vim: set expandtab tabstop=4 shiftwidth=4: