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(expect
)+1]
41 assert r
== expect
, (r
, expect
)
45 test
.write(SConstruct_path
, """\
46 from SCons.Variables.ListVariable import ListVariable
49 from SCons.Variables import ListVariable
51 list_of_libs = Split('x11 gl qt ical')
53 optsfile = 'scons.variables'
54 opts = Variables(optsfile, args=ARGUMENTS)
56 ListVariable('shared',
57 'libraries to build as shared libraries',
60 map = {'GL':'gl', 'QT':'qt'}),
61 LV('listvariable', 'listvariable help', 'all', names=['l1', 'l2', 'l3'])
64 DefaultEnvironment(tools=[]) # test speedup
65 env = Environment(variables=opts)
66 opts.Save(optsfile, env)
67 Help(opts.GenerateHelpText(env))
71 if 'ical' in env['shared']:
76 print(" ".join(env['shared']))
78 print(env.subst('$shared'))
79 # Test subst_path() because it's used in $CPPDEFINES expansions.
80 print(env.subst_path('$shared'))
81 Default(env.Alias('dummy', None))
85 check(['all', '1', 'gl ical qt x11', 'gl ical qt x11',
86 "['gl ical qt x11']"])
88 expect
= "shared = 'all'"+os
.linesep
+"listvariable = 'all'"+os
.linesep
89 test
.must_match(test
.workpath('scons.variables'), expect
)
91 check(['all', '1', 'gl ical qt x11', 'gl ical qt x11',
92 "['gl ical qt x11']"])
94 test
.run(arguments
='shared=none')
95 check(['none', '0', '', '', "['']"])
97 test
.run(arguments
='shared=')
98 check(['none', '0', '', '', "['']"])
100 test
.run(arguments
='shared=x11,ical')
101 check(['ical,x11', '1', 'ical x11', 'ical x11',
104 test
.run(arguments
='shared=x11,,ical,,')
105 check(['ical,x11', '1', 'ical x11', 'ical x11',
108 test
.run(arguments
='shared=GL')
109 check(['gl', '0', 'gl', 'gl'])
111 test
.run(arguments
='shared=QT,GL')
112 check(['gl,qt', '0', 'gl qt', 'gl qt', "['gl qt']"])
116 scons: *** Error converting option: shared
117 Invalid value(s) for option: foo
118 """ + test
.python_file_line(SConstruct_path
, 20)
120 test
.run(arguments
='shared=foo', stderr
=expect_stderr
, status
=2)
122 # be paranoid in testing some more combinations
125 scons: *** Error converting option: shared
126 Invalid value(s) for option: foo
127 """ + test
.python_file_line(SConstruct_path
, 20)
129 test
.run(arguments
='shared=foo,ical', stderr
=expect_stderr
, status
=2)
132 scons: *** Error converting option: shared
133 Invalid value(s) for option: foo
134 """ + test
.python_file_line(SConstruct_path
, 20)
136 test
.run(arguments
='shared=ical,foo', stderr
=expect_stderr
, status
=2)
139 scons: *** Error converting option: shared
140 Invalid value(s) for option: foo
141 """ + test
.python_file_line(SConstruct_path
, 20)
143 test
.run(arguments
='shared=ical,foo,x11', stderr
=expect_stderr
, status
=2)
146 scons: *** Error converting option: shared
147 Invalid value(s) for option: foo,bar
148 """ + test
.python_file_line(SConstruct_path
, 20)
150 test
.run(arguments
='shared=foo,x11,,,bar', stderr
=expect_stderr
, status
=2)
154 test
.write('SConstruct', """
155 from SCons.Variables import ListVariable
157 opts = Variables(args=ARGUMENTS)
162 names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']),
165 DefaultEnvironment(tools=[]) # test speedup
166 env = Environment(variables=opts)
167 Help(opts.GenerateHelpText(env))
170 Default(env.Alias('dummy', None))
173 test
.run(stdout
=test
.wrap_stdout(read_str
="ENET,GPIB\n", build_str
="""\
174 scons: Nothing to be done for `dummy'.
183 # indent-tabs-mode:nil
185 # vim: set expandtab tabstop=4 shiftwidth=4: