Followon to PR #4348: more bool fixes
[scons.git] / SCons / Scanner / JavaTests.py
blob0a3c7592df95dee842ebcd87d48524fefe769ca6
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 import unittest
25 import collections
26 import os
28 import TestCmd
30 import SCons.Scanner.Java
31 import SCons.Node.FS
32 import SCons.Warnings
35 test = TestCmd.TestCmd(workdir = '')
37 files = [
38 'bootclasspath.jar',
39 'classpath.jar',
40 'Test.class',
43 for fname in files:
44 test.write(fname, "\n")
46 test.subdir('com')
47 test.subdir('java space')
48 subfiles = [
49 'com/Test.class',
50 'java space/Test.class'
53 for fname in subfiles:
54 test.write(fname.split('/'), "\n")
56 class DummyEnvironment(collections.UserDict):
57 def __init__(self, **kw) -> None:
58 super().__init__()
59 self.data.update(kw)
60 self.fs = SCons.Node.FS.FS(test.workpath(''))
61 self['ENV'] = {}
63 def Dictionary(self, *args):
64 return self.data
66 def subst(self, strSubst, target=None, source=None, conv=None):
67 if strSubst[0] == '$':
68 return self.data[strSubst[1:]]
69 return strSubst
71 def subst_path(self, path, target=None, source=None, conv=None):
72 if not isinstance(path, list):
73 path = [path]
74 return list(map(self.subst, path))
76 def has_key(self, key) -> bool:
77 return key in self.Dictionary()
79 def get_calculator(self):
80 return None
82 def get_factory(self, factory):
83 return factory or self.fs.File
85 def Dir(self, filename):
86 return self.fs.Dir(filename)
88 def File(self, filename):
89 return self.fs.File(filename)
91 def Glob(self, path):
92 return self.fs.Glob(path)
95 class DummyNode:
96 def __init__(self, name) -> None:
97 self.name = name
99 def rexists(self) -> bool:
100 return True
102 def __str__(self) -> str:
103 return self.name
106 global my_normpath
107 my_normpath = os.path.normpath
109 if os.path.normcase('foo') == os.path.normcase('FOO'):
110 my_normpath = os.path.normcase
112 def deps_match(self, deps, headers) -> None:
113 scanned = sorted(map(my_normpath, list(map(str, deps))))
114 expect = sorted(map(my_normpath, headers))
115 self.assertTrue(scanned == expect, "expect %s != scanned %s" % (expect, scanned))
118 class JavaScannerEmptyClasspath(unittest.TestCase):
119 def runTest(self) -> None:
120 path = []
121 env = DummyEnvironment(JAVASUFFIXES=['.java'], JAVACLASSPATH=path)
122 s = SCons.Scanner.Java.JavaScanner()
123 deps = s(DummyNode('dummy'), env)
124 expected = []
125 deps_match(self, deps, expected)
128 class JavaScannerClasspath(unittest.TestCase):
129 def runTest(self) -> None:
130 env = DummyEnvironment(JAVASUFFIXES=['.java'],
131 JAVACLASSPATH=[test.workpath('classpath.jar')])
132 s = SCons.Scanner.Java.JavaScanner()
133 deps = s(DummyNode('dummy'), env)
134 expected = ['classpath.jar']
135 deps_match(self, deps, expected)
138 class JavaScannerWildcardClasspath(unittest.TestCase):
139 def runTest(self) -> None:
140 env = DummyEnvironment(JAVASUFFIXES=['.java'],
141 JAVACLASSPATH=[test.workpath('*')])
142 s = SCons.Scanner.Java.JavaScanner()
143 deps = s(DummyNode('dummy'), env)
144 expected = ['bootclasspath.jar', 'classpath.jar', 'Test.class']
145 deps_match(self, deps, expected)
148 class JavaScannerDirClasspath(unittest.TestCase):
149 def runTest(self) -> None:
150 env = DummyEnvironment(JAVASUFFIXES=['.java'],
151 JAVACLASSPATH=[test.workpath()])
152 s = SCons.Scanner.Java.JavaScanner()
153 deps = s(DummyNode('dummy'), env)
154 expected = ['Test.class', 'com/Test.class', 'java space/Test.class']
155 deps_match(self, deps, expected)
158 class JavaScannerNamedDirClasspath(unittest.TestCase):
159 def runTest(self) -> None:
160 env = DummyEnvironment(
161 JAVASUFFIXES=['.java'],
162 JAVACLASSPATH=[test.workpath('com'), test.workpath('java space')],
164 s = SCons.Scanner.Java.JavaScanner()
165 deps = s(DummyNode('dummy'), env)
166 expected = ['com/Test.class', 'java space/Test.class']
167 deps_match(self, deps, expected)
170 class JavaScannerSearchPathClasspath(unittest.TestCase):
171 def runTest(self) -> None:
172 env = DummyEnvironment(
173 JAVASUFFIXES=['.java'],
174 JAVACLASSPATH=os.pathsep.join([test.workpath('com'), test.workpath('java space')]),
176 s = SCons.Scanner.Java.JavaScanner()
177 deps = s(DummyNode('dummy'), env)
178 expected = ['com/Test.class', 'java space/Test.class']
179 deps_match(self, deps, expected)
182 class JavaScannerEmptyProcessorpath(unittest.TestCase):
183 def runTest(self) -> None:
184 path = []
185 env = DummyEnvironment(JAVASUFFIXES=['.java'], JAVAPROCESSORPATH=path)
186 s = SCons.Scanner.Java.JavaScanner()
187 deps = s(DummyNode('dummy'), env)
188 expected = []
189 deps_match(self, deps, expected)
192 class JavaScannerProcessorpath(unittest.TestCase):
193 def runTest(self) -> None:
194 env = DummyEnvironment(JAVASUFFIXES=['.java'],
195 JAVAPROCESSORPATH=[test.workpath('classpath.jar')])
196 s = SCons.Scanner.Java.JavaScanner()
197 deps = s(DummyNode('dummy'), env)
198 expected = ['classpath.jar']
199 deps_match(self, deps, expected)
202 class JavaScannerWildcardProcessorpath(unittest.TestCase):
203 def runTest(self) -> None:
204 env = DummyEnvironment(JAVASUFFIXES=['.java'],
205 JAVAPROCESSORPATH=[test.workpath('*')])
206 s = SCons.Scanner.Java.JavaScanner()
207 deps = s(DummyNode('dummy'), env)
208 expected = ['bootclasspath.jar', 'classpath.jar', 'Test.class']
209 deps_match(self, deps, expected)
212 class JavaScannerDirProcessorpath(unittest.TestCase):
213 def runTest(self) -> None:
214 env = DummyEnvironment(JAVASUFFIXES=['.java'],
215 JAVAPROCESSORPATH=[test.workpath()])
216 s = SCons.Scanner.Java.JavaScanner()
217 deps = s(DummyNode('dummy'), env)
218 expected = ['Test.class', 'com/Test.class', 'java space/Test.class']
219 deps_match(self, deps, expected)
222 class JavaScannerNamedDirProcessorpath(unittest.TestCase):
223 def runTest(self) -> None:
224 env = DummyEnvironment(
225 JAVASUFFIXES=['.java'],
226 JAVAPROCESSORPATH=[test.workpath('com'), test.workpath('java space')],
228 s = SCons.Scanner.Java.JavaScanner()
229 deps = s(DummyNode('dummy'), env)
230 expected = ['com/Test.class', 'java space/Test.class']
231 deps_match(self, deps, expected)
234 class JavaScannerSearchPathProcessorpath(unittest.TestCase):
235 def runTest(self) -> None:
236 env = DummyEnvironment(
237 JAVASUFFIXES=['.java'],
238 JAVAPROCESSORPATH=os.pathsep.join([test.workpath('com'), test.workpath('java space')]),
240 s = SCons.Scanner.Java.JavaScanner()
241 deps = s(DummyNode('dummy'), env)
242 expected = ['com/Test.class', 'java space/Test.class']
243 deps_match(self, deps, expected)
246 if __name__ == "__main__":
247 unittest.main()
249 # Local Variables:
250 # tab-width:4
251 # indent-tabs-mode:nil
252 # End:
253 # vim: set expandtab tabstop=4 shiftwidth=4: