http://scons.tigris.org/issues/show_bug.cgi?id=2329
[scons.git] / src / engine / SCons / DefaultsTests.py
1 #
2 # __COPYRIGHT__
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
23
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25
26 import os
27 import os.path
28 import StringIO
29 import sys
30 import unittest
31
32 from UserDict import UserDict
33
34 import TestCmd
35
36 import SCons.Errors
37
38 from SCons.Defaults import *
39
40 class DefaultsTestCase(unittest.TestCase):
41     def test_mkdir_func0(self):
42         test = TestCmd.TestCmd(workdir = '')
43         test.subdir('sub')
44         subdir2 = test.workpath('sub', 'dir1', 'dir2')
45         # Simple smoke test
46         mkdir_func(subdir2)
47         mkdir_func(subdir2)     # 2nd time should be OK too
48
49     def test_mkdir_func1(self):
50         test = TestCmd.TestCmd(workdir = '')
51         test.subdir('sub')
52         subdir1 = test.workpath('sub', 'dir1')
53         subdir2 = test.workpath('sub', 'dir1', 'dir2')
54         # No error if asked to create existing dir
55         os.makedirs(subdir2)
56         mkdir_func(subdir2)
57         mkdir_func(subdir1)
58
59     def test_mkdir_func2(self):
60         test = TestCmd.TestCmd(workdir = '')
61         test.subdir('sub')
62         subdir1 = test.workpath('sub', 'dir1')
63         subdir2 = test.workpath('sub', 'dir1', 'dir2')
64         file = test.workpath('sub', 'dir1', 'dir2', 'file')
65
66         # make sure it does error if asked to create a dir
67         # where there's already a file
68         os.makedirs(subdir2)
69         test.write(file, "test\n")
70         try:
71             mkdir_func(file)
72         except os.error, e:
73             pass
74         else:
75             fail("expected os.error")
76         
77
78 if __name__ == "__main__":
79     suite = unittest.TestSuite()
80     tclasses = [ DefaultsTestCase,
81                ]
82     for tclass in tclasses:
83         names = unittest.getTestCaseNames(tclass, 'test_')
84         suite.addTests(list(map(tclass, names)))
85     if not unittest.TextTestRunner().run(suite).wasSuccessful():
86         sys.exit(1)
87
88 # Local Variables:
89 # tab-width:4
90 # indent-tabs-mode:nil
91 # End:
92 # vim: set expandtab tabstop=4 shiftwidth=4: