Updates and slight refactor in fix
[scons.git] / test / Variables / EnumVariable.py
bloba81e8060bef7204ab7be3a8173cc755646da273f
1 #!/usr/bin/env python
3 # MIT License
5 # Copyright The SCons Foundation
7 # Permission is hereby granted, free of charge, to any person obtaining
8 # a copy of this software and associated documentation files (the
9 # "Software"), to deal in the Software without restriction, including
10 # without limitation the rights to use, copy, modify, merge, publish,
11 # distribute, sublicense, and/or sell copies of the Software, and to
12 # permit persons to whom the Software is furnished to do so, subject to
13 # the following conditions:
15 # The above copyright notice and this permission notice shall be included
16 # in all copies or substantial portions of the Software.
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 """
27 Test the EnumVariable canned Variable type.
28 """
30 import TestSCons
32 test = TestSCons.TestSCons()
34 SConstruct_path = test.workpath('SConstruct')
36 def check(expect):
37 result = test.stdout().split('\n')
38 assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect)
40 test.write(SConstruct_path, """\
41 from SCons.Variables.EnumVariable import EnumVariable as EV
42 from SCons.Variables import EnumVariable
44 list_of_libs = Split('x11 gl qt ical')
46 opts = Variables(args=ARGUMENTS)
47 opts.AddVariables(
48 EnumVariable('debug', 'debug output and symbols', 'no',
49 allowed_values=('yes', 'no', 'full'),
50 map={}, ignorecase=0), # case sensitive
51 EnumVariable('guilib', 'gui lib to use', 'gtk',
52 allowed_values=('motif', 'gtk', 'kde'),
53 map={}, ignorecase=1), # case insensitive
54 EV('some', 'some option', 'xaver',
55 allowed_values=('xaver', 'eins'),
56 map={}, ignorecase=2), # make lowercase
59 _ = DefaultEnvironment(tools=[])
60 env = Environment(variables=opts, tools=[])
61 Help(opts.GenerateHelpText(env))
63 print(env['debug'])
64 print(env['guilib'])
65 print(env['some'])
67 Default(env.Alias('dummy', None))
68 """)
70 test.run()
71 check(['no', 'gtk', 'xaver'])
73 test.run(arguments='debug=yes guilib=Motif some=xAVER')
74 check(['yes', 'Motif', 'xaver'])
76 test.run(arguments='debug=full guilib=KdE some=EiNs')
77 check(['full', 'KdE', 'eins'])
79 expect_stderr = """
80 scons: *** Invalid value for enum variable 'debug': 'FULL'. Valid values are: ('yes', 'no', 'full')
81 """ + test.python_file_line(SConstruct_path, 20)
83 test.run(arguments='debug=FULL', stderr=expect_stderr, status=2)
85 expect_stderr = """
86 scons: *** Invalid value for enum variable 'guilib': 'irgendwas'. Valid values are: ('motif', 'gtk', 'kde')
87 """ + test.python_file_line(SConstruct_path, 20)
89 test.run(arguments='guilib=IrGeNdwas', stderr=expect_stderr, status=2)
91 expect_stderr = """
92 scons: *** Invalid value for enum variable 'some': 'irgendwas'. Valid values are: ('xaver', 'eins')
93 """ + test.python_file_line(SConstruct_path, 20)
95 test.run(arguments='some=IrGeNdwas', stderr=expect_stderr, status=2)
97 test.pass_test()
99 # Local Variables:
100 # tab-width:4
101 # indent-tabs-mode:nil
102 # End:
103 # vim: set expandtab tabstop=4 shiftwidth=4: