Fixed ninja binary location logic to use ninja.BIN_DIR. Previous logic no longer...
[scons.git] / SCons / Tool / javacTests.py
blob46f1af12016e5b232a2d372e553a4e06537bbffd
2 # __COPYRIGHT__
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 import os
25 import unittest
27 import SCons.Tool.javac
29 class DummyNode:
30 def __init__(self, val) -> None:
31 self.val = val
33 def __str__(self) -> str:
34 return str(self.val)
36 class pathoptTestCase(unittest.TestCase):
37 def assert_pathopt(self, expect, path) -> None:
38 popt = SCons.Tool.javac.pathopt('-foopath', 'FOOPATH')
39 env = {'FOOPATH': path}
40 actual = popt(None, None, env, None)
41 self.assertEqual(expect, actual)
43 def assert_pathopt_default(self, expect, path, default) -> None:
44 popt = SCons.Tool.javac.pathopt('-foopath', 'FOOPATH', default='DPATH')
45 env = {'FOOPATH': path,
46 'DPATH': default}
47 actual = popt(None, None, env, None)
48 self.assertEqual(expect, actual)
50 def test_unset(self) -> None:
51 self.assert_pathopt([], None)
52 self.assert_pathopt([], '')
54 def test_str(self) -> None:
55 self.assert_pathopt(['-foopath', '/foo/bar'],
56 '/foo/bar')
58 def test_list_str(self) -> None:
59 self.assert_pathopt(['-foopath', '/foo%s/bar' % os.pathsep],
60 ['/foo', '/bar'])
62 def test_uses_pathsep(self) -> None:
63 save = os.pathsep
64 try:
65 os.pathsep = '!'
66 self.assert_pathopt(['-foopath', 'foo!bar'],
67 ['foo', 'bar'])
68 finally:
69 os.pathsep = save
71 def test_node(self) -> None:
72 self.assert_pathopt(['-foopath', '/foo'],
73 DummyNode('/foo'))
75 def test_list_node(self) -> None:
76 self.assert_pathopt(['-foopath', os.pathsep.join(['/foo','/bar'])],
77 ['/foo', DummyNode('/bar')])
79 def test_default_str(self) -> None:
80 self.assert_pathopt_default(
81 ['-foopath', os.pathsep.join(['/foo','/bar','/baz'])],
82 ['/foo', '/bar'],
83 '/baz')
85 def test_default_list(self) -> None:
86 self.assert_pathopt_default(
87 ['-foopath', os.pathsep.join(['/foo','/bar','/baz'])],
88 ['/foo', '/bar'],
89 ['/baz'])
91 def test_default_unset(self) -> None:
92 self.assert_pathopt_default(
93 ['-foopath', '/foo'],
94 '/foo',
95 None)
96 self.assert_pathopt_default(
97 ['-foopath', '/foo'],
98 '/foo',
99 '')
101 def test_list_within_list(self) -> None:
102 self.assert_pathopt(['-foopath', os.pathsep.join(['/foo','/bar'])],
103 ['/foo', ['/bar']])
106 if __name__ == "__main__":
107 unittest.main()