Added fix for TeX includes with same name as subdirs.
[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     f = open(target, "wb")
108     for src in source:
109         f.write(open(str(src), "rb").read())
110     f.close()
111     Exit(27)
112 env = Environment(BUILDERS = {'my_exit' : Builder(action=exit_builder)})
113 env.my_exit('foo.out', 'foo.in')
114 """)
115
116 test.write(['subdir', 'foo.in'], "subdir/foo.in\n")
117
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))
125
126 test.must_match(['subdir', 'foo.out'], "subdir/foo.in\n")
127
128 test.write('SConstruct', """\
129 def exit_scanner(node, env, target):
130     Exit(37)
131
132 exitscan = Scanner(function = exit_scanner, skeys = ['.k'])
133
134 def cat(env, source, target):
135     target = str(target[0])
136     outf = open(target, 'wb')
137     for src in source:
138         outf.write(open(str(src), "rb").read())
139     outf.close()
140
141 env = Environment(BUILDERS={'Cat':Builder(action=cat)})
142 env.Append(SCANNERS = [exitscan])
143
144 env.Cat('foo', 'foo.k')
145 """)
146
147 test.write('foo.k', "foo.k\n")
148
149 test.run(status = 37,
150          stdout = test.wrap_stdout("", error=1),
151          stderr = "scons: *** [foo] Explicit exit, status 37\n")
152
153 #
154 test.pass_test()
155
156 # Local Variables:
157 # tab-width:4
158 # indent-tabs-mode:nil
159 # End:
160 # vim: set expandtab tabstop=4 shiftwidth=4: