Have the "Open" issue links also show UNCONFIRMED issues.
[scons.git] / src / engine / SCons / Options / PackageOptionTests.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 SCons.compat
27
28 import sys
29 import unittest
30
31 import SCons.Errors
32 import SCons.Options
33
34 import TestCmd
35
36 class PackageOptionTestCase(unittest.TestCase):
37     def test_PackageOption(self):
38         """Test PackageOption creation"""
39         opts = SCons.Options.Options()
40         opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
41
42         o = opts.options[0]
43         assert o.key == 'test', o.key
44         assert o.help == 'test option help\n    ( yes | no | /path/to/test )', repr(o.help)
45         assert o.default == '/default/path', o.default
46         assert not o.validator is None, o.validator
47         assert not o.converter is None, o.converter
48
49     def test_converter(self):
50         """Test the PackageOption converter"""
51         opts = SCons.Options.Options()
52         opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
53
54         o = opts.options[0]
55
56         true_values = [
57                 'yes',    'YES',
58                 'true',   'TRUE',
59                 'on',     'ON',
60                 'enable', 'ENABLE',
61                 'search', 'SEARCH',
62         ]
63         false_values = [
64                 'no',      'NO',
65                 'false',   'FALSE',
66                 'off',     'OFF',
67                 'disable', 'DISABLE',
68         ]
69
70         for t in true_values:
71             x = o.converter(t)
72             assert x, "converter returned false for '%s'" % t
73
74         for f in false_values:
75             x = o.converter(f)
76             assert not x, "converter returned true for '%s'" % f
77
78         x = o.converter('/explicit/path')
79         assert x == '/explicit/path', x
80
81         # Make sure the converter returns True if we give it str(True) and
82         # False when we give it str(False).  This assures consistent operation
83         # through a cycle of Options.Save(<file>) -> Options(<file>).
84         x = o.converter(str(True))
85         assert x == True, "converter returned a string when given str(True)"
86
87         x = o.converter(str(False))
88         assert x == False, "converter returned a string when given str(False)"
89
90     def test_validator(self):
91         """Test the PackageOption validator"""
92         opts = SCons.Options.Options()
93         opts.Add(SCons.Options.PackageOption('test', 'test option help', '/default/path'))
94
95         test = TestCmd.TestCmd(workdir='')
96         test.write('exists', 'exists\n')
97
98         o = opts.options[0]
99
100         env = {'F':False, 'T':True, 'X':'x'}
101
102         exists = test.workpath('exists')
103         does_not_exist = test.workpath('does_not_exist')
104
105         o.validator('F', '/path', env)
106         o.validator('T', '/path', env)
107         o.validator('X', exists, env)
108
109         caught = None
110         try:
111             o.validator('X', does_not_exist, env)
112         except SCons.Errors.UserError:
113             caught = 1
114         assert caught, "did not catch expected UserError"
115
116
117 if __name__ == "__main__":
118     suite = unittest.makeSuite(PackageOptionTestCase, 'test_')
119     if not unittest.TextTestRunner().run(suite).wasSuccessful():
120         sys.exit(1)