Merged revisions 3088-3319,3321-3322,3324-3349,3351-3481,3483-3484,3486-3520,3522...
[scons.git] / src / engine / SCons / Platform / PlatformTests.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 sys
27 import unittest
28
29 import SCons.Errors
30 import SCons.Platform
31 import UserDict
32
33 class Environment(UserDict.UserDict):
34     def Detect(self, cmd):
35         return cmd
36     def AppendENVPath(self, key, value):
37         pass
38
39 class PlatformTestCase(unittest.TestCase):
40     def test_Platform(self):
41         """Test the Platform() function"""
42         p = SCons.Platform.Platform('cygwin')
43         assert str(p) == 'cygwin', p
44         env = Environment()
45         p(env)
46         assert env['PROGSUFFIX'] == '.exe', env
47         assert env['LIBSUFFIX'] == '.a', env
48         assert env['SHELL'] == 'sh', env
49
50         p = SCons.Platform.Platform('os2')
51         assert str(p) == 'os2', p
52         env = Environment()
53         p(env)
54         assert env['PROGSUFFIX'] == '.exe', env
55         assert env['LIBSUFFIX'] == '.lib', env
56
57         p = SCons.Platform.Platform('posix')
58         assert str(p) == 'posix', p
59         env = Environment()
60         p(env)
61         assert env['PROGSUFFIX'] == '', env
62         assert env['LIBSUFFIX'] == '.a', env
63         assert env['SHELL'] == 'sh', env
64
65         p = SCons.Platform.Platform('irix')
66         assert str(p) == 'irix', p
67         env = Environment()
68         p(env)
69         assert env['PROGSUFFIX'] == '', env
70         assert env['LIBSUFFIX'] == '.a', env
71         assert env['SHELL'] == 'sh', env
72
73         p = SCons.Platform.Platform('aix')
74         assert str(p) == 'aix', p
75         env = Environment()
76         p(env)
77         assert env['PROGSUFFIX'] == '', env
78         assert env['LIBSUFFIX'] == '.a', env
79         assert env['SHELL'] == 'sh', env
80
81         p = SCons.Platform.Platform('sunos')
82         assert str(p) == 'sunos', p
83         env = Environment()
84         p(env)
85         assert env['PROGSUFFIX'] == '', env
86         assert env['LIBSUFFIX'] == '.a', env
87         assert env['SHELL'] == 'sh', env
88
89         p = SCons.Platform.Platform('hpux')
90         assert str(p) == 'hpux', p
91         env = Environment()
92         p(env)
93         assert env['PROGSUFFIX'] == '', env
94         assert env['LIBSUFFIX'] == '.a', env
95         assert env['SHELL'] == 'sh', env
96
97         p = SCons.Platform.Platform('win32')
98         assert str(p) == 'win32', p
99         env = Environment()
100         p(env)
101         assert env['PROGSUFFIX'] == '.exe', env
102         assert env['LIBSUFFIX'] == '.lib', env
103         assert str
104
105         try:
106             p = SCons.Platform.Platform('_does_not_exist_')
107         except SCons.Errors.UserError:
108             pass
109         else:
110             raise
111
112         env = Environment()
113         SCons.Platform.Platform()(env)
114         assert env != {}, env
115
116
117 if __name__ == "__main__":
118     suite = unittest.makeSuite(PlatformTestCase, 'test_')
119     if not unittest.TextTestRunner().run(suite).wasSuccessful():
120         sys.exit(1)
121
122 # Local Variables:
123 # tab-width:4
124 # indent-tabs-mode:nil
125 # End:
126 # vim: set expandtab tabstop=4 shiftwidth=4: