added release.txt blurb. Fixed spelling typo in Defaults.xml
[scons.git] / test / Variables / ListVariable.py
bloba322f9b8a03a1684486dfc6052e8dfcd2a9f85f7
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 ListVariable canned Variable type.
28 """
30 import os
32 import TestSCons
34 test = TestSCons.TestSCons()
36 SConstruct_path = test.workpath('SConstruct')
38 def check(expected):
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)
52 opts.AddVariables(
53 ListVariable('shared',
54 'libraries to build as shared libraries',
55 'all',
56 names = list_of_libs,
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))
66 print(env['shared'])
68 if 'ical' in env['shared']:
69 print('1')
70 else:
71 print('0')
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))
79 """)
81 test.run()
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',
99 "['ical x11']"])
101 test.run(arguments='shared=x11,,ical,,')
102 check(['ical,x11', '1', 'ical x11', 'ical x11',
103 "['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']"])
112 expect_stderr = """
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
120 expect_stderr = """
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)
126 expect_stderr = """
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)
132 expect_stderr = """
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)
138 expect_stderr = """
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)
148 opts.AddVariables(
149 ListVariable('gpib',
150 'comment',
151 ['ENET', 'GPIB'],
152 names = ['ENET', 'GPIB', 'LINUX_GPIB', 'NO_GPIB']),
155 DefaultEnvironment(tools=[]) # test speedup
156 env = Environment(variables=opts)
157 Help(opts.GenerateHelpText(env))
159 print(env['gpib'])
160 Default(env.Alias('dummy', None))
161 """)
163 test.run(stdout=test.wrap_stdout(read_str="ENET,GPIB\n", build_str="""\
164 scons: Nothing to be done for `dummy'.
165 """))
167 test.pass_test()
169 # Local Variables:
170 # tab-width:4
171 # indent-tabs-mode:nil
172 # End:
173 # vim: set expandtab tabstop=4 shiftwidth=4: