4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
33 import SCons.Scanner.Prog
35 test = TestCmd.TestCmd(workdir = '')
37 test.subdir('d1', ['d1', 'd2'], 'dir', ['dir', 'sub'])
39 libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib',
40 'dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']
45 # define some helpers:
47 class DummyEnvironment:
48 def __init__(self, **kw):
49 self._dict = {'LIBSUFFIXES' : '.lib'}
51 self.fs = SCons.Node.FS.FS(test.workpath(''))
53 def Dictionary(self, *args):
57 return self._dict[args[0]]
59 return [self._dict[x] for x in args]
61 def has_key(self, key):
62 return key in self.Dictionary()
64 def __getitem__(self,key):
65 return self.Dictionary()[key]
67 def __setitem__(self,key,value):
68 self.Dictionary()[key] = value
70 def __delitem__(self,key):
71 del self.Dictionary()[key]
73 def subst(self, s, target=None, source=None, conv=None):
76 return self._dict[s[1:]]
81 def subst_path(self, path, target=None, source=None, conv=None):
82 if type(path) != type([]):
84 return list(map(self.subst, path))
86 def get_factory(self, factory):
87 return factory or self.fs.File
89 def Dir(self, filename):
90 return self.fs.Dir(test.workpath(filename))
92 def File(self, filename):
93 return self.fs.File(test.workpath(filename))
96 def __init__(self, name):
103 def deps_match(deps, libs):
104 deps=list(map(str, deps))
107 return list(map(os.path.normpath, deps)) == list(map(os.path.normpath, libs))
111 class ProgramScannerTestCase1(unittest.TestCase):
113 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
114 LIBS=[ 'l1', 'l2', 'l3' ])
115 s = SCons.Scanner.Prog.ProgramScanner()
117 deps = s(DummyNode('dummy'), env, path)
118 assert deps_match(deps, ['l1.lib']), list(map(str, deps))
120 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
122 s = SCons.Scanner.Prog.ProgramScanner()
124 deps = s(DummyNode('dummy'), env, path)
125 assert deps_match(deps, ['l1.lib']), list(map(str, deps))
127 f1 = env.fs.File(test.workpath('f1'))
128 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
130 s = SCons.Scanner.Prog.ProgramScanner()
132 deps = s(DummyNode('dummy'), env, path)
133 assert deps[0] is f1, deps
135 f2 = env.fs.File(test.workpath('f1'))
136 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
138 s = SCons.Scanner.Prog.ProgramScanner()
140 deps = s(DummyNode('dummy'), env, path)
141 assert deps[0] is f2, deps
144 class ProgramScannerTestCase2(unittest.TestCase):
146 env = DummyEnvironment(LIBPATH=list(map(test.workpath,
147 ["", "d1", "d1/d2" ])),
148 LIBS=[ 'l1', 'l2', 'l3' ])
149 s = SCons.Scanner.Prog.ProgramScanner()
151 deps = s(DummyNode('dummy'), env, path)
152 assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), list(map(str, deps))
154 class ProgramScannerTestCase3(unittest.TestCase):
156 env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
157 test.workpath("d1")],
158 LIBS='l2 l3'.split())
159 s = SCons.Scanner.Prog.ProgramScanner()
161 deps = s(DummyNode('dummy'), env, path)
162 assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), list(map(str, deps))
164 class ProgramScannerTestCase5(unittest.TestCase):
166 class SubstEnvironment(DummyEnvironment):
167 def subst(self, arg, target=None, source=None, conv=None, path=test.workpath("d1")):
169 return test.workpath("d1")
172 env = SubstEnvironment(LIBPATH=[ "$blah" ],
173 LIBS='l2 l3'.split())
174 s = SCons.Scanner.Prog.ProgramScanner()
176 deps = s(DummyNode('dummy'), env, path)
177 assert deps_match(deps, [ 'd1/l2.lib' ]), list(map(str, deps))
179 class ProgramScannerTestCase6(unittest.TestCase):
181 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
182 LIBS=['foo', 'sub/libbar', 'xyz.other'],
185 s = SCons.Scanner.Prog.ProgramScanner()
187 deps = s(DummyNode('dummy'), env, path)
188 assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
190 class ProgramScannerTestCase7(unittest.TestCase):
192 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
193 LIBS=['foo', '$LIBBAR', '$XYZ'],
198 s = SCons.Scanner.Prog.ProgramScanner()
200 deps = s(DummyNode('dummy'), env, path)
201 assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
203 class ProgramScannerTestCase8(unittest.TestCase):
207 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
209 LIBPREFIXES=['p1-', 'p2-'],
210 LIBSUFFIXES=['.1', '2'])
211 s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode)
213 deps = s(DummyNode('dummy'), env, path)
214 assert deps == [n1], deps
217 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
219 LIBPREFIXES=['p1-', 'p2-'],
220 LIBSUFFIXES=['.1', '2'])
221 s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode)
223 deps = s(DummyNode('dummy'), env, path)
224 assert deps == [n1, n2], deps
227 suite = unittest.TestSuite()
228 suite.addTest(ProgramScannerTestCase1())
229 suite.addTest(ProgramScannerTestCase2())
230 suite.addTest(ProgramScannerTestCase3())
231 suite.addTest(ProgramScannerTestCase5())
232 suite.addTest(ProgramScannerTestCase6())
233 suite.addTest(ProgramScannerTestCase7())
234 suite.addTest(ProgramScannerTestCase8())
235 if hasattr(types, 'UnicodeType'):
237 class ProgramScannerTestCase4(unittest.TestCase):
239 env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
240 test.workpath("d1")],
241 LIBS=u'l2 l3'.split())
242 s = SCons.Scanner.Prog.ProgramScanner()
244 deps = s(DummyNode('dummy'), env, path)
245 assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps)
246 suite.addTest(ProgramScannerTestCase4())
251 if __name__ == "__main__":
252 runner = unittest.TextTestRunner()
253 result = runner.run(suite())
254 if not result.wasSuccessful():
259 # indent-tabs-mode:nil
261 # vim: set expandtab tabstop=4 shiftwidth=4: