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__"
34 import SCons.Scanner.Prog
36 test = TestCmd.TestCmd(workdir = '')
38 test.subdir('d1', ['d1', 'd2'], 'dir', ['dir', 'sub'])
40 libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib',
41 'dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']
46 # define some helpers:
48 class DummyEnvironment:
49 def __init__(self, **kw):
50 self._dict = {'LIBSUFFIXES' : '.lib'}
53 def Dictionary(self, *args):
57 return self._dict[args[0]]
59 return map(lambda x, s=self: s._dict[x], args)
61 def has_key(self, key):
62 return self.Dictionary().has_key(key)
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]
76 def deps_match(deps, libs):
80 return map(os.path.normpath, deps) == \
82 map(test.workpath, libs))
86 class ProgScanTestCase1(unittest.TestCase):
88 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
89 LIBS=[ 'l1', 'l2', 'l3' ])
90 s = SCons.Scanner.Prog.ProgScan()
92 deps = s('dummy', env, path)
93 assert deps_match(deps, ['l1.lib']), map(str, deps)
95 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
97 s = SCons.Scanner.Prog.ProgScan()
99 deps = s('dummy', env, path)
100 assert deps_match(deps, ['l1.lib']), map(str, deps)
102 f1 = SCons.Node.FS.default_fs.File(test.workpath('f1'))
103 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
105 s = SCons.Scanner.Prog.ProgScan()
107 deps = s('dummy', env, path)
108 assert deps[0] is f1, deps
110 f2 = SCons.Node.FS.default_fs.File(test.workpath('f1'))
111 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
113 s = SCons.Scanner.Prog.ProgScan()
115 deps = s('dummy', env, path)
116 assert deps[0] is f2, deps
119 class ProgScanTestCase2(unittest.TestCase):
121 env = DummyEnvironment(LIBPATH=map(test.workpath,
122 ["", "d1", "d1/d2" ]),
123 LIBS=[ 'l1', 'l2', 'l3' ])
124 s = SCons.Scanner.Prog.ProgScan()
126 deps = s('dummy', env, path)
127 assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), map(str, deps)
129 class ProgScanTestCase3(unittest.TestCase):
131 env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
132 test.workpath("d1")],
133 LIBS=string.split('l2 l3'))
134 s = SCons.Scanner.Prog.ProgScan()
136 deps = s('dummy', env, path)
137 assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps)
139 class ProgScanTestCase5(unittest.TestCase):
141 class SubstEnvironment(DummyEnvironment):
142 def subst(self, arg, path=test.workpath("d1")):
144 return test.workpath("d1")
147 env = SubstEnvironment(LIBPATH=[ "blah" ],
148 LIBS=string.split('l2 l3'))
149 s = SCons.Scanner.Prog.ProgScan()
151 deps = s('dummy', env, path)
152 assert deps_match(deps, [ 'd1/l2.lib' ]), map(str, deps)
154 class ProgScanTestCase6(unittest.TestCase):
156 env = DummyEnvironment(LIBPATH=[ test.workpath("dir") ],
157 LIBS=['foo', 'sub/libbar', 'xyz.other'],
160 s = SCons.Scanner.Prog.ProgScan()
162 deps = s('dummy', env, path)
163 assert deps_match(deps, ['dir/libfoo.a', 'dir/sub/libbar.a', 'dir/libxyz.other']), map(str, deps)
166 suite = unittest.TestSuite()
167 suite.addTest(ProgScanTestCase1())
168 suite.addTest(ProgScanTestCase2())
169 suite.addTest(ProgScanTestCase3())
170 suite.addTest(ProgScanTestCase5())
171 suite.addTest(ProgScanTestCase6())
172 if hasattr(types, 'UnicodeType'):
174 class ProgScanTestCase4(unittest.TestCase):
176 env = DummyEnvironment(LIBPATH=[test.workpath("d1/d2"),
177 test.workpath("d1")],
178 LIBS=string.split(u'l2 l3'))
179 s = SCons.Scanner.Prog.ProgScan()
181 deps = s('dummy', env, path)
182 assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps)
183 suite.addTest(ProgScanTestCase4())
188 if __name__ == "__main__":
189 runner = unittest.TextTestRunner()
190 result = runner.run(suite())
191 if not result.wasSuccessful():