Update Copyright lines for the new year.
[scons.git] / src / engine / SCons / Scanner / ProgTests.py
1 #
2 # Copyright (c) 2001, 2002 Steven Knight
3 #
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:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
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.
22 #
23
24 __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
25
26 import TestCmd
27 import SCons.Scanner.Prog
28 import unittest
29 import sys
30 import os.path
31
32 test = TestCmd.TestCmd(workdir = '')
33
34 test.subdir('d1', ['d1', 'd2'])
35
36 libs = [ 'l1.lib', 'd1/l2.lib', 'd1/d2/l3.lib' ]
37
38 for h in libs:
39     test.write(h, " ")
40
41 # define some helpers:
42
43 class DummyEnvironment:
44     def __init__(self, **kw):
45         self._dict = kw
46         self._dict['LIBSUFFIX'] = '.lib'
47         
48     def Dictionary(self, *args):
49         if not args:
50             return self._dict
51         elif len(args) == 1:
52             return self._dict[args[0]]
53         else:
54             return map(lambda x, s=self: s._dict[x], args)
55
56 def deps_match(deps, libs):
57     deps=map(str, deps)
58     deps.sort()
59     libs.sort()
60     return map(os.path.normpath, deps) == \
61            map(os.path.normpath,
62                map(test.workpath, libs))
63
64 # define some tests:
65
66 class ProgScanTestCase1(unittest.TestCase):
67     def runTest(self):
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)
73
74 class ProgScanTestCase2(unittest.TestCase):
75     def runTest(self):
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)
82
83 class ProgScanTestCase3(unittest.TestCase):
84     def runTest(self):
85         env = DummyEnvironment(LIBPATH=test.workpath("d1/d2") + ' ' +\
86                                test.workpath("d1"),
87                                LIBS='l2 l3')
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)
91
92 def suite():
93     suite = unittest.TestSuite()
94     suite.addTest(ProgScanTestCase1())
95     suite.addTest(ProgScanTestCase2())
96     suite.addTest(ProgScanTestCase3())
97     return suite
98
99 if __name__ == "__main__":
100     runner = unittest.TextTestRunner()
101     result = runner.run(suite())
102     if not result.wasSuccessful():
103         sys.exit(1)