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__"
32 import SCons.Scanner.Prog
34 test = TestCmd.TestCmd(workdir = '')
36 test.subdir('d1', ['d1', 'd2'], 'dir', ['dir', 'sub'])
38 libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib',
39 'dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']
44 # define some helpers:
46 class DummyEnvironment:
47 def __init__(self, **kw):
48 self._dict = {'LIBSUFFIXES' : '.lib'}
50 self.fs = SCons.Node.FS.FS(test.workpath(''))
52 def Dictionary(self, *args):
56 return self._dict[args[0]]
58 return [self._dict[x] for x in args]
60 def has_key(self, key):
61 return key in self.Dictionary()
63 def __getitem__(self,key):
64 return self.Dictionary()[key]
66 def __setitem__(self,key,value):
67 self.Dictionary()[key] = value
69 def __delitem__(self,key):
70 del self.Dictionary()[key]
72 def subst(self, s, target=None, source=None, conv=None):
75 return self._dict[s[1:]]
80 def subst_path(self, path, target=None, source=None, conv=None):
81 if not isinstance(path, list):
83 return list(map(self.subst, path))
85 def get_factory(self, factory):
86 return factory or self.fs.File
88 def Dir(self, filename):
89 return self.fs.Dir(test.workpath(filename))
91 def File(self, filename):
92 return self.fs.File(test.workpath(filename))
95 def __init__(self, name):
102 def deps_match(deps, libs):
103 deps=sorted(map(str, deps))
105 return list(map(os.path.normpath, deps)) == list(map(os.path.normpath, libs))
109 class ProgramScannerTestCase1(unittest.TestCase):
111 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
112 LIBS=[ 'l1', 'l2', 'l3' ])
113 s = SCons.Scanner.Prog.ProgramScanner()
115 deps = s(DummyNode('dummy'), env, path)
116 assert deps_match(deps, ['l1.lib']), list(map(str, deps))
118 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
120 s = SCons.Scanner.Prog.ProgramScanner()
122 deps = s(DummyNode('dummy'), env, path)
123 assert deps_match(deps, ['l1.lib']), list(map(str, deps))
125 f1 = env.fs.File(test.workpath('f1'))
126 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
128 s = SCons.Scanner.Prog.ProgramScanner()
130 deps = s(DummyNode('dummy'), env, path)
131 assert deps[0] is f1, deps
133 f2 = env.fs.File(test.workpath('f1'))
134 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
136 s = SCons.Scanner.Prog.ProgramScanner()
138 deps = s(DummyNode('dummy'), env, path)
139 assert deps[0] is f2, deps
142 class ProgramScannerTestCase2(unittest.TestCase):
144 env = DummyEnvironment(LIBPATH=list(map(test.workpath,
145 ["", "d1", "d1/d2" ])),
146 LIBS=[ 'l1', 'l2', 'l3' ])
147 s = SCons.Scanner.Prog.ProgramScanner()
149 deps = s(DummyNode('dummy'), env, path)
150 assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), list(map(str, deps))
152 class ProgramScannerTestCase3(unittest.TestCase):
154 env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
155 test.workpath("d1")],
156 LIBS='l2 l3'.split())
157 s = SCons.Scanner.Prog.ProgramScanner()
159 deps = s(DummyNode('dummy'), env, path)
160 assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), list(map(str, deps))
162 class ProgramScannerTestCase5(unittest.TestCase):
164 class SubstEnvironment(DummyEnvironment):
165 def subst(self, arg, target=None, source=None, conv=None, path=test.workpath("d1")):
167 return test.workpath("d1")
170 env = SubstEnvironment(LIBPATH=[ "$blah" ],
171 LIBS='l2 l3'.split())
172 s = SCons.Scanner.Prog.ProgramScanner()
174 deps = s(DummyNode('dummy'), env, path)
175 assert deps_match(deps, [ 'd1/l2.lib' ]), list(map(str, deps))
177 class ProgramScannerTestCase6(unittest.TestCase):
179 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
180 LIBS=['foo', 'sub/libbar', 'xyz.other'],
183 s = SCons.Scanner.Prog.ProgramScanner()
185 deps = s(DummyNode('dummy'), env, path)
186 assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
188 class ProgramScannerTestCase7(unittest.TestCase):
190 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
191 LIBS=['foo', '$LIBBAR', '$XYZ'],
196 s = SCons.Scanner.Prog.ProgramScanner()
198 deps = s(DummyNode('dummy'), env, path)
199 assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), list(map(str, deps))
201 class ProgramScannerTestCase8(unittest.TestCase):
205 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
207 LIBPREFIXES=['p1-', 'p2-'],
208 LIBSUFFIXES=['.1', '2'])
209 s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode)
211 deps = s(DummyNode('dummy'), env, path)
212 assert deps == [n1], deps
215 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
217 LIBPREFIXES=['p1-', 'p2-'],
218 LIBSUFFIXES=['.1', '2'])
219 s = SCons.Scanner.Prog.ProgramScanner(node_class = DummyNode)
221 deps = s(DummyNode('dummy'), env, path)
222 assert deps == [n1, n2], deps
225 suite = unittest.TestSuite()
226 suite.addTest(ProgramScannerTestCase1())
227 suite.addTest(ProgramScannerTestCase2())
228 suite.addTest(ProgramScannerTestCase3())
229 suite.addTest(ProgramScannerTestCase5())
230 suite.addTest(ProgramScannerTestCase6())
231 suite.addTest(ProgramScannerTestCase7())
232 suite.addTest(ProgramScannerTestCase8())
234 except NameError: pass
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: