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 PathVariable canned variable type, with tests for its
28 various canned validators.
35 test
= TestSCons
.TestSCons()
37 SConstruct_path
= test
.workpath('SConstruct')
40 result
= test
.stdout().split('\n')
41 assert result
[1:len(expect
)+1] == expect
, (result
[1:len(expect
)+1], expect
)
44 test
.subdir('lib', 'qt', ['qt', 'lib'], 'nolib')
45 workpath
= test
.workpath()
47 test
.write(SConstruct_path
, """\
48 from SCons.Variables.PathVariable import PathVariable as PV
49 from SCons.Variables import PathVariable
53 opts = Variables(args=ARGUMENTS)
55 PathVariable('qtdir', 'where the root of Qt is installed', qtdir),
56 PV('qt_libraries', 'where the Qt library is installed', r'%s'),
59 _ = DefaultEnvironment(tools=[]) # test speedup
60 env = Environment(variables=opts, tools=[])
61 Help(opts.GenerateHelpText(env))
64 print(env['qt_libraries'])
65 print(env.subst('$qt_libraries'))
67 Default(env.Alias('dummy', None))
68 """ % (workpath
, os
.path
.join('$qtdir', 'lib')))
71 libpath
= os
.path
.join(qtpath
, 'lib')
73 check([qtpath
, os
.path
.join('$qtdir', 'lib'), libpath
])
75 qtpath
= os
.path
.join(workpath
, 'qt')
76 libpath
= os
.path
.join(qtpath
, 'lib')
77 test
.run(arguments
=['qtdir=%s' % qtpath
])
78 check([qtpath
, os
.path
.join('$qtdir', 'lib'), libpath
])
81 libpath
= os
.path
.join(qtpath
, 'nolib')
82 test
.run(arguments
=['qt_libraries=%s' % libpath
])
83 check([qtpath
, libpath
, libpath
])
85 qtpath
= os
.path
.join(workpath
, 'qt')
86 libpath
= os
.path
.join(workpath
, 'nolib')
87 test
.run(arguments
=['qtdir=%s' % qtpath
, 'qt_libraries=%s' % libpath
])
88 check([qtpath
, libpath
, libpath
])
90 qtpath
= os
.path
.join(workpath
, 'non', 'existing', 'path')
91 SConstruct_file_line
= test
.python_file_line(test
.workpath('SConstruct'), 13)[:-1]
94 scons: *** Path for variable 'qtdir' does not exist: %(qtpath)s
95 %(SConstruct_file_line)s
98 test
.run(arguments
=['qtdir=%s' % qtpath
], stderr
=expect_stderr
, status
=2)
101 scons: *** Path for variable 'qt_libraries' does not exist: %(qtpath)s
102 %(SConstruct_file_line)s
105 test
.run(arguments
=['qt_libraries=%s' % qtpath
], stderr
=expect_stderr
, status
=2)
107 default_file
= test
.workpath('default_file')
108 default_subdir
= test
.workpath('default_subdir')
109 existing_subdir
= test
.workpath('existing_subdir')
110 test
.subdir(existing_subdir
)
112 existing_file
= test
.workpath('existing_file')
113 test
.write(existing_file
, "existing_file\n")
115 non_existing_subdir
= test
.workpath('non_existing_subdir')
116 non_existing_file
= test
.workpath('non_existing_file')
118 test
.write('SConstruct', """\
119 opts = Variables(args=ARGUMENTS)
121 PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathAccept),
124 DefaultEnvironment(tools=[]) # test speedup
125 env = Environment(variables=opts)
129 Default(env.Alias('dummy', None))
130 """ % default_subdir
)
133 check([default_subdir
])
135 test
.run(arguments
=['X=%s' % existing_file
])
136 check([existing_file
])
138 test
.run(arguments
=['X=%s' % non_existing_file
])
139 check([non_existing_file
])
141 test
.run(arguments
=['X=%s' % existing_subdir
])
142 check([existing_subdir
])
144 test
.run(arguments
=['X=%s' % non_existing_subdir
])
145 check([non_existing_subdir
])
147 test
.must_not_exist(non_existing_file
)
148 test
.must_not_exist(non_existing_subdir
)
150 test
.write(SConstruct_path
, """\
151 opts = Variables(args=ARGUMENTS)
153 PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathIsFile),
156 DefaultEnvironment(tools=[]) # test speedup
157 env = Environment(variables=opts)
161 Default(env.Alias('dummy', None))
164 SConstruct_file_line
= test
.python_file_line(test
.workpath('SConstruct'), 7)[:-1]
167 scons: *** File path for variable 'X' does not exist: %(default_file)s
168 %(SConstruct_file_line)s
171 test
.run(status
=2, stderr
=expect_stderr
)
173 test
.write(default_file
, "default_file\n")
175 check([default_file
])
178 scons: *** File path for variable 'X' is a directory: %(existing_subdir)s
179 %(SConstruct_file_line)s
182 test
.run(arguments
=['X=%s' % existing_subdir
], status
=2, stderr
=expect_stderr
)
184 test
.run(arguments
=['X=%s' % existing_file
])
185 check([existing_file
])
188 scons: *** File path for variable 'X' does not exist: %(non_existing_file)s
189 %(SConstruct_file_line)s
192 test
.run(arguments
=['X=%s' % non_existing_file
], status
=2, stderr
=expect_stderr
)
194 test
.write('SConstruct', """\
195 opts = Variables(args=ARGUMENTS)
197 PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathIsDir),
200 DefaultEnvironment(tools=[]) # test speedup
201 env = Environment(variables=opts)
205 Default(env.Alias('dummy', None))
206 """ % default_subdir
)
209 scons: *** Directory path for variable 'X' does not exist: %(default_subdir)s
210 %(SConstruct_file_line)s
213 test
.run(status
=2, stderr
=expect_stderr
)
215 test
.subdir(default_subdir
)
217 check([default_subdir
])
220 scons: *** Directory path for variable 'X' is a file: %(existing_file)s
221 %(SConstruct_file_line)s
224 test
.run(arguments
=['X=%s' % existing_file
],
226 stderr
=expect_stderr
)
228 test
.run(arguments
=['X=%s' % existing_subdir
])
229 check([existing_subdir
])
232 scons: *** Directory path for variable 'X' does not exist: %(non_existing_subdir)s
233 %(SConstruct_file_line)s
236 test
.run(arguments
=['X=%s' % non_existing_subdir
],
238 stderr
=expect_stderr
)
240 test
.write('SConstruct', """\
241 opts = Variables(args=ARGUMENTS)
243 PathVariable('X', 'X variable', r'%s', validator=PathVariable.PathIsDirCreate),
246 DefaultEnvironment(tools=[]) # test speedup
247 env = Environment(variables=opts)
251 Default(env.Alias('dummy', None))
252 """ % default_subdir
)
255 check([default_subdir
])
258 scons: *** Path for variable 'X' is a file, not a directory: %(existing_file)s
259 %(SConstruct_file_line)s
262 test
.run(arguments
=['X=%s' % existing_file
], status
=2, stderr
=expect_stderr
)
264 test
.run(arguments
=['X=%s' % existing_subdir
])
265 check([existing_subdir
])
267 test
.run(arguments
=['X=%s' % non_existing_subdir
])
268 check([non_existing_subdir
])
270 test
.must_exist(non_existing_subdir
)
276 # indent-tabs-mode:nil
278 # vim: set expandtab tabstop=4 shiftwidth=4: