added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Win32 / bad-drive.py
blobcca54620d69c82ea7f3470cf9935f2b44d1e0063
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.
24 """
25 This test verifies (on Windows systems) that we fail gracefully and
26 provide informative messages if someone tries to use a path name
27 with an invalid drive letter.
28 """
30 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
32 import os
33 import sys
34 from string import ascii_uppercase
36 import TestSCons
38 test = TestSCons.TestSCons()
40 if sys.platform != 'win32':
41 msg = "Skipping drive-letter test on non-Windows platform '%s'\n" % sys.platform
42 test.skip_test(msg)
44 # start at the end looking for unused drive letter
45 bad_drive = None
46 for d in reversed(ascii_uppercase):
47 if not os.path.isdir(d + ':' + os.sep):
48 bad_drive = d + ':'
49 break
51 if bad_drive is None:
52 print("All drive letters appear to be in use.")
53 print("Cannot test SCons handling of invalid Windows drive letters.")
54 test.no_result(1)
56 test.write('SConstruct', """
57 def cat(env, source, target):
58 target = str(target[0])
59 source = list(map(str, source))
60 print('cat(%%s) > %%s' %% (source, target))
61 with open(target, "wb") as ofp:
62 for src in source:
63 with open(src, "rb") as ifp:
64 ofp.write(ifp.read())
66 bad_drive = '%s'
67 env = Environment(BUILDERS={'Build':Builder(action=cat)})
68 env.Build('aaa.out', 'aaa.in')
69 env.Build(bad_drive + 'no_target_1', 'bbb.exists')
70 env.Build(bad_drive + 'no_target_2', 'ccc.does_not_exist')
71 env.Build('ddd.out', bad_drive + 'no_source')
72 """ % (bad_drive + '\\' + os.sep))
74 bad_drive = bad_drive + os.sep
76 test.write("aaa.in", "aaa.in\n")
77 test.write("bbb.exists", "bbb.exists\n")
79 test.write("no_target_1", "no_target_1\n")
80 test.write("no_target_2", "no_target_2\n")
81 test.write("no_source", "no_source\n")
83 test.run(arguments = 'aaa.out')
85 test.must_match('aaa.out', "aaa.in\n", mode='r')
87 # This next test used to provide a slightly different error message:
88 # "scons: *** Do not know how to make File target `%snot_mentioned'. Stop.\n"
89 # Right now, it doesn't seem important enough to track down exactly
90 # why this changed and fix it, but we'll preserve it here in case it
91 # becomes an issue or some refactoring restores the old behavior.
93 test.run(arguments = bad_drive + 'not_mentioned',
94 stderr = "scons: *** Do not know how to make File target `%snot_mentioned' (%snot_mentioned). Stop.\n" % (bad_drive, bad_drive),
95 status = 2)
97 expect = "scons: *** [%sno_target_1] No drive `%s' for target `%sno_target_1'.\n" % (bad_drive, bad_drive, bad_drive)
98 test.run(arguments=bad_drive + 'no_target_1', stderr=expect, status=2)
100 expect = "scons: *** [%sno_target_2] Source `ccc.does_not_exist' not found, needed by target `%sno_target_2'.\n" % (bad_drive, bad_drive)
101 test.run(arguments=bad_drive + 'no_target_2', stderr=expect, status=2)
103 expect = "scons: *** [ddd.out] Source `%sno_source' not found, needed by target `ddd.out'.\n" % bad_drive
104 test.run(arguments='ddd.out', stderr=expect, status=2)
106 test.pass_test()
108 # Local Variables:
109 # tab-width:4
110 # indent-tabs-mode:nil
111 # End:
112 # vim: set expandtab tabstop=4 shiftwidth=4: