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.
27 Test the EnumVariable canned Variable type.
32 test
= TestSCons
.TestSCons()
34 SConstruct_path
= test
.workpath('SConstruct')
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)
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))
67 Default(env.Alias('dummy', None))
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'])
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)
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)
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)
101 # indent-tabs-mode:nil
103 # vim: set expandtab tabstop=4 shiftwidth=4: