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.
33 class DummyEnvironment
:
34 def __init__(self
) -> None:
36 def Detect(self
, progs
):
37 if not SCons
.Util
.is_List(progs
):
40 def Append(self
, **kw
) -> None:
42 def __getitem__(self
, key
):
44 def __setitem__(self
, key
, val
) -> None:
46 def __contains__(self
, key
) -> bool:
47 return key
in self
.dict
48 def subst(self
, string
, *args
, **kwargs
):
51 PHONY_PATH
= "/usr/phony/bin"
52 def WhereIs(self
, key_program
):
53 # for pathfind test for Issue #3336:
54 # need to fake the case where extra paths are searched, and
55 # if one has a "hit" after some fails, the fails are left in
56 # the environment's PATH. So construct a positive answer if
57 # we see a magic known path component in PATH; answer in
58 # the negative otherwise.
59 paths
= self
['ENV']['PATH']
60 if self
.PHONY_PATH
in paths
:
61 return os
.path
.join(self
.PHONY_PATH
, key_program
)
63 def AppendENVPath(self
, pathvar
, path
) -> None:
64 # signature matches how called from find_program_path()
65 self
['ENV'][pathvar
] = self
['ENV'][pathvar
] + os
.pathsep
+ path
68 class ToolTestCase(unittest
.TestCase
):
69 def test_Tool(self
) -> None:
70 """Test the Tool() function"""
72 env
= DummyEnvironment()
75 env
['PLATFORM'] = 'test'
76 t
= SCons
.Tool
.Tool('g++')
78 assert (env
['CXX'] == 'c++' or env
['CXX'] == 'g++'), env
['CXX']
79 assert env
['INCPREFIX'] == '-I', env
['INCPREFIX']
80 assert env
['TOOLS'] == ['g++'], env
['TOOLS']
87 assert exc_caught
, "did not catch expected UserError"
91 p
= SCons
.Tool
.Tool('_does_not_exist_')
92 except SCons
.Errors
.UserError
as e
:
94 # Old msg was Python-style "No tool named", check for new msg:
95 assert "No tool module" in str(e
), e
96 assert exc_caught
, "did not catch expected UserError"
99 def test_pathfind(self
) -> None:
100 """Test that find_program_path() alters PATH only if add_path is true"""
102 env
= DummyEnvironment()
106 '/usr/local/dummy/bin',
107 env
.PHONY_PATH
, # will be recognized by dummy WhereIs
110 env
['ENV']['PATH'] = '/usr/local/bin:/opt/bin:/bin:/usr/bin'
111 pre_path
= env
['ENV']['PATH']
112 _
= SCons
.Tool
.find_program_path(env
, 'no_tool', default_paths
=PHONY_PATHS
)
113 assert env
['ENV']['PATH'] == pre_path
, env
['ENV']['PATH']
115 _
= SCons
.Tool
.find_program_path(env
, 'no_tool', default_paths
=PHONY_PATHS
, add_path
=True)
116 assert env
.PHONY_PATH
in env
['ENV']['PATH'], env
['ENV']['PATH']
119 if __name__
== "__main__":
120 loader
= unittest
.TestLoader()
121 loader
.testMethodPrefix
= 'test_'
122 suite
= loader
.loadTestsFromTestCase(ToolTestCase
)
127 # indent-tabs-mode:nil
129 # vim: set expandtab tabstop=4 shiftwidth=4: