merge current upstream
[scons.git] / test / Variables / ListVariable.py
blobe46384052e9c84f9865011b7a30be453bee8bc8b
1 #!/usr/bin/env python
3 # __COPYRIGHT__
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
27 """
28 Test the ListVariable canned Variable type.
29 """
31 import os
33 import TestSCons
35 test = TestSCons.TestSCons()
37 SConstruct_path = test.workpath('SConstruct')
39 def check(expect):
40 result = test.stdout().split('\n')
41 r = result[1:len(expect)+1]
42 assert r == expect, (r, expect)
46 test.write(SConstruct_path, """\
47 from SCons.Variables.ListVariable import ListVariable
48 LV = ListVariable
50 from SCons.Variables import ListVariable
52 list_of_libs = Split('x11 gl qt ical')
54 optsfile = 'scons.variables'
55 opts = Variables(optsfile, args=ARGUMENTS)
56 opts.AddVariables(
57 ListVariable('shared',
58 'libraries to build as shared libraries',
59 'all',
60 names = list_of_libs,
61 map = {'GL':'gl', 'QT':'qt'}),
62 LV('listvariable', 'listvariable help', 'all', names=['l1', 'l2', 'l3'])
65 env = Environment(variables=opts)
66 opts.Save(optsfile, env)
67 Help(opts.GenerateHelpText(env))
69 print(env['shared'])
71 if 'ical' in env['shared']:
72 print('1')
73 else:
74 print('0')
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))
82 """)
84 test.run()
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',
102 "['ical x11']"])
104 test.run(arguments='shared=x11,,ical,,')
105 check(['ical,x11', '1', 'ical x11', 'ical x11',
106 "['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']"])
115 expect_stderr = """
116 scons: *** Error converting option: shared
117 Invalid value(s) for option: foo
118 """ + test.python_file_line(SConstruct_path, 19)
120 test.run(arguments='shared=foo', stderr=expect_stderr, status=2)
122 # be paranoid in testing some more combinations
124 expect_stderr = """
125 scons: *** Error converting option: shared
126 Invalid value(s) for option: foo
127 """ + test.python_file_line(SConstruct_path, 19)
129 test.run(arguments='shared=foo,ical', stderr=expect_stderr, status=2)
131 expect_stderr = """
132 scons: *** Error converting option: shared
133 Invalid value(s) for option: foo
134 """ + test.python_file_line(SConstruct_path, 19)
136 test.run(arguments='shared=ical,foo', stderr=expect_stderr, status=2)
138 expect_stderr = """
139 scons: *** Error converting option: shared
140 Invalid value(s) for option: foo
141 """ + test.python_file_line(SConstruct_path, 19)
143 test.run(arguments='shared=ical,foo,x11', stderr=expect_stderr, status=2)
145 expect_stderr = """
146 scons: *** Error converting option: shared
147 Invalid value(s) for option: foo,bar
148 """ + test.python_file_line(SConstruct_path, 19)
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)
158 opts.AddVariables(
159 ListVariable('gpib',
160 'comment',
161 ['ENET', 'GPIB'],
162 names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']),
165 env = Environment(variables=opts)
166 Help(opts.GenerateHelpText(env))
168 print(env['gpib'])
169 Default(env.Alias('dummy', None))
170 """)
172 test.run(stdout=test.wrap_stdout(read_str="ENET,GPIB\n", build_str="""\
173 scons: Nothing to be done for `dummy'.
174 """))
178 test.pass_test()
180 # Local Variables:
181 # tab-width:4
182 # indent-tabs-mode:nil
183 # End:
184 # vim: set expandtab tabstop=4 shiftwidth=4: