Merge pull request #4655 from bdbaddog/fix_new_ninja_package
[scons.git] / test / Win32 / scons-bat-error.py
blobd772132a9d2039b80e97486a620648581ba88bf2
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 """
26 Verify that the scons.bat file returns error codes as we expect.
27 """
29 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
31 import os
32 import sys
34 import TestSCons
36 test = TestSCons.TestSCons()
38 if sys.platform != 'win32':
39 msg = "Skipping scons.bat test on non-Windows platform '%s'\n" % sys.platform
40 test.skip_test(msg)
42 python = test.where_is('python')
44 if not python:
45 msg = "Skipping scons.bat test; python is not on %PATH%.\n"
46 test.skip_test(msg)
48 scons_bat = os.path.splitext(test.program)[0] + '.bat'
50 if not os.path.exists(scons_bat):
51 msg = "Skipping scons.bat test; %s does not exist.\n" % scons_bat
52 test.skip_test(msg)
54 test.write('scons.bat', test.read(scons_bat))
56 # The scons.bat file tries to import SCons.Script from its sys.prefix
57 # directories first (i.e., site-packages) which means this test might
58 # end up using an installed SCons in preference to something local.
59 # If so, create a SConstruct file that will exit with our expected
60 # error status. If there is *not* an installed SCons, we still want
61 # this test to work, so we make a "SCons" package in the local
62 # directory with a Script.py module that contains a main() function
63 # that just exits with the expected status.
65 test.subdir('SCons')
67 test.write(['SCons', '__init__.py'], "")
69 test.write(['SCons', 'Script.py'], """\
70 import sys
71 def main():
72 sys.exit(7)
73 """)
75 test.write('SConstruct', """\
76 import sys
77 sys.exit(7)
78 """)
80 test.run(program = 'scons.bat', status = 7)
84 test.pass_test()
86 # Local Variables:
87 # tab-width:4
88 # indent-tabs-mode:nil
89 # End:
90 # vim: set expandtab tabstop=4 shiftwidth=4: