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 ListVariable canned Variable type.
34 test
= TestSCons
.TestSCons()
36 SConstruct_path
= test
.workpath('SConstruct')
39 result
= test
.stdout().split('\n')
40 r
= result
[1:len(expected
)+1]
41 assert r
== expected
, (r
, expected
)
44 test
.write(SConstruct_path
, """\
45 from SCons.Variables.ListVariable import ListVariable as LV
46 from SCons.Variables import ListVariable
48 list_of_libs = Split('x11 gl qt ical')
50 optsfile = 'scons.variables'
51 opts = Variables(optsfile, args=ARGUMENTS)
53 ListVariable('shared',
54 'libraries to build as shared libraries',
57 map = {'GL':'gl', 'QT':'qt'}),
58 LV('listvariable', 'listvariable help', 'all', names=['l1', 'l2', 'l3'])
61 _ = DefaultEnvironment(tools=[]) # test speedup
62 env = Environment(variables=opts, tools=[])
63 opts.Save(optsfile, env)
64 Help(opts.GenerateHelpText(env))
68 if 'ical' in env['shared']:
73 print(" ".join(env['shared']))
75 print(env.subst('$shared'))
76 # Test subst_path() because it's used in $CPPDEFINES expansions.
77 print(env.subst_path('$shared'))
78 Default(env.Alias('dummy', None))
82 check(['all', '1', 'gl ical qt x11', 'gl ical qt x11',
83 "['gl ical qt x11']"])
85 expect
= "shared = 'all'"+os
.linesep
+"listvariable = 'all'"+os
.linesep
86 test
.must_match(test
.workpath('scons.variables'), expect
)
88 check(['all', '1', 'gl ical qt x11', 'gl ical qt x11',
89 "['gl ical qt x11']"])
91 test
.run(arguments
='shared=none')
92 check(['none', '0', '', '', "['']"])
94 test
.run(arguments
='shared=')
95 check(['none', '0', '', '', "['']"])
97 test
.run(arguments
='shared=x11,ical')
98 check(['ical,x11', '1', 'ical x11', 'ical x11',
101 test
.run(arguments
='shared=x11,,ical,,')
102 check(['ical,x11', '1', 'ical x11', 'ical x11',
105 test
.run(arguments
='shared=GL')
106 check(['gl', '0', 'gl', 'gl'])
108 test
.run(arguments
='shared=QT,GL')
109 check(['gl,qt', '0', 'gl qt', 'gl qt', "['gl qt']"])
113 scons: *** Invalid value(s) for variable 'shared': 'foo'. Valid values are: gl,ical,qt,x11,all,none
114 """ + test
.python_file_line(SConstruct_path
, 18)
116 test
.run(arguments
='shared=foo', stderr
=expect_stderr
, status
=2)
118 # be paranoid in testing some more combinations
121 scons: *** Invalid value(s) for variable 'shared': 'foo'. Valid values are: gl,ical,qt,x11,all,none
122 """ + test
.python_file_line(SConstruct_path
, 18)
124 test
.run(arguments
='shared=foo,ical', stderr
=expect_stderr
, status
=2)
127 scons: *** Invalid value(s) for variable 'shared': 'foo'. Valid values are: gl,ical,qt,x11,all,none
128 """ + test
.python_file_line(SConstruct_path
, 18)
130 test
.run(arguments
='shared=ical,foo', stderr
=expect_stderr
, status
=2)
133 scons: *** Invalid value(s) for variable 'shared': 'foo'. Valid values are: gl,ical,qt,x11,all,none
134 """ + test
.python_file_line(SConstruct_path
, 18)
136 test
.run(arguments
='shared=ical,foo,x11', stderr
=expect_stderr
, status
=2)
139 scons: *** Invalid value(s) for variable 'shared': 'foo,bar'. Valid values are: gl,ical,qt,x11,all,none
140 """ + test
.python_file_line(SConstruct_path
, 18)
142 test
.run(arguments
='shared=foo,x11,,,bar', stderr
=expect_stderr
, status
=2)
144 test
.write('SConstruct', """
145 from SCons.Variables import ListVariable
147 opts = Variables(args=ARGUMENTS)
152 names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']),
155 DefaultEnvironment(tools=[]) # test speedup
156 env = Environment(variables=opts)
157 Help(opts.GenerateHelpText(env))
160 Default(env.Alias('dummy', None))
163 test
.run(stdout
=test
.wrap_stdout(read_str
="ENET,GPIB\n", build_str
="""\
164 scons: Nothing to be done for `dummy'.
171 # indent-tabs-mode:nil
173 # vim: set expandtab tabstop=4 shiftwidth=4: