1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
#
# Copyright (c) 2001 - 2016 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
__revision__ = "src/engine/SCons/Scanner/ProgTests.py rel_2.5.1:3735:9dc6cee5c168 2016/11/03 14:02:02 bdbaddog"
import os.path
import sys
import unittest
import TestCmd
import TestUnit
import SCons.Node.FS
import SCons.Scanner.Prog
import SCons.Subst
test = TestCmd.TestCmd(workdir = '')
test.subdir('d1', ['d1', 'd2'], 'dir', ['dir', 'sub'])
libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib',
'dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']
for h in libs:
test.write(h, "\n")
# define some helpers:
class DummyEnvironment(object):
def __init__(self, **kw):
self._dict = {'LIBSUFFIXES' : '.lib'}
self._dict.update(kw)
self.fs = SCons.Node.FS.FS(test.workpath(''))
def Dictionary(self, *args):
if not args:
return self._dict
elif len(args) == 1:
return self._dict[args[0]]
else:
return [self._dict[x] for x in args]
def has_key(self, key):
return key in self.Dictionary()
def __getitem__(self,key):
return self.Dictionary()[key]
def __setitem__(self,key,value):
self.Dictionary()[key] = value
def __delitem__(self,key):
del self.Dictionary()[key]
def subst(self, s, target=None, source=None, conv=None):
return SCons.Subst.scons_subst(s, self, gvars=self._dict, lvars=self._dict)
def subst_path(self, path, target=None, source=None, conv=None):
if not isinstance(path, list):
path = [path]
return list(map(self.subst, path))
def get_factory(self, factory):
return factory or self.fs.File
def Dir(self, filename):
return self.fs.Dir(test.workpath(filename))
def File(self, filename):
return self.fs.File(test.workpath(filename))
class DummyNode(object):
def __init__(self, name):
self.name = name
def rexists(self):
return 1
def __str__(self):
return self.name
def deps_match(deps, libs):
deps=sorted(map(str, deps))
libs.sort()
return list(map(os.path.normpath, deps)) == list(map(os.path.normpath, libs))
# define some tests:
class ProgramScannerTestCase1(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
LIBS=[ 'l1', 'l2', 'l3' ])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['l1.lib']), list(map(str, deps))
env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
LIBS='l1')
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['l1.lib']), list(map(str, deps))
f1 = env.fs.File(test.workpath('f1'))
env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
LIBS=[f1])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps[0] is f1, deps
f2 = env.fs.File(test.workpath('f1'))
env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
LIBS=f2)
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps[0] is f2, deps
class ProgramScannerTestCase2(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=list(map(test.workpath,
["", "d1", "d1/d2" ])),
LIBS=[ 'l1', 'l2', 'l3' ])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), list(map(str, deps))
class ProgramScannerTestCase3(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
test.workpath("d1")],
LIBS='l2 l3'.split())
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), list(map(str, deps))
class ProgramScannerTestCase5(unittest.TestCase):
def runTest(self):
class SubstEnvironment(DummyEnvironment):
def subst(self, arg, target=None, source=None, conv=None, path=test.workpath("d1")):
if arg == "$blah":
return test.workpath("d1")
else:
return arg
env = SubstEnvironment(LIBPATH=[ "$blah" ],
LIBS='l2 l3'.split())
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, [ 'd1/l2.lib' ]), list(map(str, deps))
class ProgramScannerTestCase6(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
LIBS=['foo', 'sub/libbar', 'xyz.other'],
LIBPREFIXES=['lib'],
LIBSUFFIXES=['.a'])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
class ProgramScannerTestCase7(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
LIBS=['foo', '$LIBBAR', '$XYZ'],
LIBPREFIXES=['lib'],
LIBSUFFIXES=['.a'],
LIBBAR='sub/libbar',
XYZ='xyz.other')
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
class ProgramScannerTestCase8(unittest.TestCase):
def runTest(self):
n1 = DummyNode('n1')
env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
LIBS=[n1],
LIBPREFIXES=['p1-', 'p2-'],
LIBSUFFIXES=['.1', '2'])
s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode)
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps == [n1], deps
n2 = DummyNode('n2')
env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
LIBS=[n1, [n2]],
LIBPREFIXES=['p1-', 'p2-'],
LIBSUFFIXES=['.1', '2'])
s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode)
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps == [n1, n2], deps
class ProgramScannerTestCase9(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
LIBS=['foo', '$LIBBAR'],
LIBPREFIXES=['lib'],
LIBSUFFIXES=['.a'],
LIBBAR=['sub/libbar', 'xyz.other'])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
class ProgramScannerTestCase10(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
LIBS=['foo', '$LIBBAR'],
LIBPREFIXES=['lib'],
LIBSUFFIXES=['.a'],
LIBBAR='sub/libbar $LIBBAR2',
LIBBAR2=['xyz.other'])
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
def suite():
suite = unittest.TestSuite()
suite.addTest(ProgramScannerTestCase1())
suite.addTest(ProgramScannerTestCase2())
suite.addTest(ProgramScannerTestCase3())
suite.addTest(ProgramScannerTestCase5())
suite.addTest(ProgramScannerTestCase6())
suite.addTest(ProgramScannerTestCase7())
suite.addTest(ProgramScannerTestCase8())
suite.addTest(ProgramScannerTestCase9())
suite.addTest(ProgramScannerTestCase10())
try: unicode
except NameError: pass
else:
code = """if 1:
class ProgramScannerTestCase4(unittest.TestCase):
def runTest(self):
env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
test.workpath("d1")],
LIBS=u'l2 l3'.split())
s = SCons.Scanner.Prog.ProgramScanner()
path = s.path(env)
deps = s(DummyNode('dummy'), env, path)
assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps)
suite.addTest(ProgramScannerTestCase4())
\n"""
exec code
return suite
if __name__ == "__main__":
TestUnit.run(suite())
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|