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__"
28 Test the PathOption canned option type, with tests for its
29 various canned validators.
37 test = TestSCons.TestSCons()
39 SConstruct_path = test.workpath('SConstruct')
42 result = string.split(test.stdout(), '\n')
43 assert result[1:len(expect)+1] == expect, (result[1:len(expect)+1], expect)
45 #### test PathOption ####
47 test.subdir('lib', 'qt', ['qt', 'lib'], 'nolib' )
48 workpath = test.workpath()
49 libpath = os.path.join(workpath, 'lib')
51 test.write(SConstruct_path, """\
52 from SCons.Options.PathOption import PathOption
55 from SCons.Options import PathOption
59 opts = Options(args=ARGUMENTS)
61 PathOption('qtdir', 'where the root of Qt is installed', qtdir),
62 PO('qt_libraries', 'where the Qt library is installed', r'%s'),
65 env = Environment(options=opts)
66 Help(opts.GenerateHelpText(env))
69 print env['qt_libraries']
70 print env.subst('$qt_libraries')
72 Default(env.Alias('dummy', None))
73 """ % (workpath, os.path.join('$qtdir', 'lib') ))
76 libpath = os.path.join(qtpath, 'lib')
78 check([qtpath, os.path.join('$qtdir', 'lib'), libpath])
80 qtpath = os.path.join(workpath, 'qt')
81 libpath = os.path.join(qtpath, 'lib')
82 test.run(arguments=['qtdir=%s' % qtpath])
83 check([qtpath, os.path.join('$qtdir', 'lib'), libpath])
86 libpath = os.path.join(qtpath, 'nolib')
87 test.run(arguments=['qt_libraries=%s' % libpath])
88 check([qtpath, libpath, libpath])
90 qtpath = os.path.join(workpath, 'qt')
91 libpath = os.path.join(workpath, 'nolib')
92 test.run(arguments=['qtdir=%s' % qtpath, 'qt_libraries=%s' % libpath])
93 check([qtpath, libpath, libpath])
95 qtpath = os.path.join(workpath, 'non', 'existing', 'path')
96 SConstruct_file_line = test.python_file_line(test.workpath('SConstruct'), 14)[:-1]
99 scons: *** Path for option qtdir does not exist: %(qtpath)s
100 %(SConstruct_file_line)s
103 test.run(arguments=['qtdir=%s' % qtpath], stderr=expect_stderr, status=2)
106 scons: *** Path for option qt_libraries does not exist: %(qtpath)s
107 %(SConstruct_file_line)s
110 test.run(arguments=['qt_libraries=%s' % qtpath], stderr=expect_stderr, status=2)
114 default_file = test.workpath('default_file')
115 default_subdir = test.workpath('default_subdir')
117 existing_subdir = test.workpath('existing_subdir')
118 test.subdir(existing_subdir)
120 existing_file = test.workpath('existing_file')
121 test.write(existing_file, "existing_file\n")
123 non_existing_subdir = test.workpath('non_existing_subdir')
124 non_existing_file = test.workpath('non_existing_file')
128 test.write('SConstruct', """\
129 opts = Options(args=ARGUMENTS)
131 PathOption('X', 'X variable', r'%s', validator=PathOption.PathAccept),
134 env = Environment(options=opts)
138 Default(env.Alias('dummy', None))
139 """ % default_subdir)
142 check([default_subdir])
144 test.run(arguments=['X=%s' % existing_file])
145 check([existing_file])
147 test.run(arguments=['X=%s' % non_existing_file])
148 check([non_existing_file])
150 test.run(arguments=['X=%s' % existing_subdir])
151 check([existing_subdir])
153 test.run(arguments=['X=%s' % non_existing_subdir])
154 check([non_existing_subdir])
156 test.must_not_exist(non_existing_file)
157 test.must_not_exist(non_existing_subdir)
161 test.write(SConstruct_path, """\
162 opts = Options(args=ARGUMENTS)
164 PathOption('X', 'X variable', r'%s', validator=PathOption.PathIsFile),
167 env = Environment(options=opts)
171 Default(env.Alias('dummy', None))
174 SConstruct_file_line = test.python_file_line(test.workpath('SConstruct'), 6)[:-1]
177 scons: *** File path for option X does not exist: %(default_file)s
178 %(SConstruct_file_line)s
181 test.run(status=2, stderr=expect_stderr)
183 test.write(default_file, "default_file\n")
186 check([default_file])
189 scons: *** File path for option X is a directory: %(existing_subdir)s
190 %(SConstruct_file_line)s
193 test.run(arguments=['X=%s' % existing_subdir], status=2, stderr=expect_stderr)
195 test.run(arguments=['X=%s' % existing_file])
196 check([existing_file])
199 scons: *** File path for option X does not exist: %(non_existing_file)s
200 %(SConstruct_file_line)s
203 test.run(arguments=['X=%s' % non_existing_file], status=2, stderr=expect_stderr)
207 test.write('SConstruct', """\
208 opts = Options(args=ARGUMENTS)
210 PathOption('X', 'X variable', r'%s', validator=PathOption.PathIsDir),
213 env = Environment(options=opts)
217 Default(env.Alias('dummy', None))
218 """ % default_subdir)
221 scons: *** Directory path for option X does not exist: %(default_subdir)s
222 %(SConstruct_file_line)s
225 test.run(status=2, stderr=expect_stderr)
227 test.subdir(default_subdir)
230 check([default_subdir])
233 scons: *** Directory path for option X is a file: %(existing_file)s
234 %(SConstruct_file_line)s
237 test.run(arguments=['X=%s' % existing_file],
239 stderr=expect_stderr)
241 test.run(arguments=['X=%s' % existing_subdir])
242 check([existing_subdir])
245 scons: *** Directory path for option X does not exist: %(non_existing_subdir)s
246 %(SConstruct_file_line)s
249 test.run(arguments=['X=%s' % non_existing_subdir],
251 stderr=expect_stderr)
255 test.write('SConstruct', """\
256 opts = Options(args=ARGUMENTS)
258 PathOption('X', 'X variable', r'%s', validator=PathOption.PathIsDirCreate),
261 env = Environment(options=opts)
265 Default(env.Alias('dummy', None))
266 """ % default_subdir)
269 check([default_subdir])
272 scons: *** Path for option X is a file, not a directory: %(existing_file)s
273 %(SConstruct_file_line)s
276 test.run(arguments=['X=%s' % existing_file], status=2, stderr=expect_stderr)
278 test.run(arguments=['X=%s' % existing_subdir])
279 check([existing_subdir])
281 test.run(arguments=['X=%s' % non_existing_subdir])
282 check([non_existing_subdir])
284 test.must_exist(non_existing_subdir)