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 PackageVariable canned Variable type.
30 from __future__
import annotations
36 test
= TestSCons
.TestSCons()
38 SConstruct_path
= test
.workpath('SConstruct')
40 def check(expect
: list[str]) -> None:
41 result
= test
.stdout().split('\n')
42 # skip first line and any lines beyond the length of expect
43 assert result
[1:len(expect
)+1] == expect
, (result
[1:len(expect
)+1], expect
)
45 test
.write(SConstruct_path
, """\
46 from SCons.Variables.PackageVariable import PackageVariable as PV
47 from SCons.Variables import PackageVariable
49 opts = Variables(args=ARGUMENTS)
51 PackageVariable('x11', 'use X11 installed here (yes = search some places', 'yes'),
52 PV('package', 'help for package', 'yes'),
55 _ = DefaultEnvironment(tools=[])
56 env = Environment(variables=opts, tools=[])
57 Help(opts.GenerateHelpText(env))
60 Default(env.Alias('dummy', None))
66 test
.run(arguments
='x11=no')
69 test
.run(arguments
='x11=0')
72 test
.run(arguments
=['x11=%s' % test
.workpath()])
73 check([test
.workpath()])
75 space_subdir
= test
.workpath('space subdir')
76 test
.subdir(space_subdir
)
77 test
.run(arguments
=[f
'x11={space_subdir}'])
81 scons: *** Path does not exist for variable 'x11': '/non/existing/path/'
82 """ + test
.python_file_line(SConstruct_path
, 11)
84 test
.run(arguments
='x11=/non/existing/path/', stderr
=expect_stderr
, status
=2)
86 # test that an enabling value produces the default value
87 # as long as that's a path string
88 tinycbor_path
= test
.workpath('path', 'to', 'tinycbor')
89 test
.subdir(tinycbor_path
)
90 SConstruct_pathstr
= test
.workpath('SConstruct.path')
91 test
.write(SConstruct_pathstr
, f
"""\
92 from SCons.Variables import PackageVariable
94 vars = Variables(args=ARGUMENTS)
98 help="use 'tinycbor' at <path>",
99 default=r'{tinycbor_path}'
103 _ = DefaultEnvironment(tools=[])
104 env = Environment(variables=vars, tools=[])
106 print(env['tinycbor'])
107 Default(env.Alias('dummy', None))
110 test
.run(arguments
=['-f', 'SConstruct.path', 'tinycbor=yes'])
111 check([tinycbor_path
])
117 # indent-tabs-mode:nil
119 # vim: set expandtab tabstop=4 shiftwidth=4: