2 # Copyright (c) 2001, 2002 Steven Knight
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__"
27 import SCons.Scanner.Prog
32 test = TestCmd.TestCmd(workdir = '')
34 test.subdir('d1', ['d1', 'd2'])
36 libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]
41 # define some helpers:
43 class DummyEnvironment:
44 def __init__(self, **kw):
46 self._dict['LIBSUFFIX'] = '.lib'
48 def Dictionary(self, *args):
52 return self._dict[args[0]]
54 return map(lambda x, s=self: s._dict[x], args)
56 def deps_match(deps, libs):
60 return map(os.path.normpath, deps) == \
62 map(test.workpath, libs))
66 class ProgScanTestCase1(unittest.TestCase):
68 env = DummyEnvironment(LIBPATH=[ test.workpath("") ],
69 LIBS=[ 'l1', 'l2', 'l3' ])
70 s = SCons.Scanner.Prog.ProgScan()
71 deps = s.scan('dummy', env)
72 assert deps_match(deps, ['l1.lib']), map(str, deps)
74 class ProgScanTestCase2(unittest.TestCase):
76 env = DummyEnvironment(LIBPATH=map(test.workpath,
77 ["", "d1", "d1/d2" ]),
78 LIBS=[ 'l1', 'l2', 'l3' ])
79 s = SCons.Scanner.Prog.ProgScan()
80 deps = s.scan('dummy', env)
81 assert deps_match(deps, ['l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]), map(str, deps)
83 class ProgScanTestCase3(unittest.TestCase):
85 env = DummyEnvironment(LIBPATH=test.workpath("d1/d2") + ' ' +\
88 s = SCons.Scanner.Prog.ProgScan()
89 deps = s.scan('dummy', env)
90 assert deps_match(deps, ['d1/l2.lib', 'd1/d2/l3.lib']), map(str, deps)
93 suite = unittest.TestSuite()
94 suite.addTest(ProgScanTestCase1())
95 suite.addTest(ProgScanTestCase2())
96 suite.addTest(ProgScanTestCase3())
99 if __name__ == "__main__":
100 runner = unittest.TextTestRunner()
101 result = runner.run(suite())
102 if not result.wasSuccessful():