2 # Copyright (c) 2001 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__"
31 from SCons.Util import scons_str2nodes, scons_subst, PathList
34 class UtilTestCase(unittest.TestCase):
35 def test_str2nodes(self):
36 """Test the str2nodes function."""
37 nodes = scons_str2nodes("Util.py UtilTests.py")
38 assert len(nodes) == 2
39 assert isinstance(nodes[0], SCons.Node.FS.File)
40 assert isinstance(nodes[1], SCons.Node.FS.File)
41 assert nodes[0].path == "Util.py"
42 assert nodes[1].path == "UtilTests.py"
44 nodes = scons_str2nodes("Util.py UtilTests.py", SCons.Node.FS.FS().File)
45 assert len(nodes) == 2
46 assert isinstance(nodes[0], SCons.Node.FS.File)
47 assert isinstance(nodes[1], SCons.Node.FS.File)
48 assert nodes[0].path == "Util.py"
49 assert nodes[1].path == "UtilTests.py"
51 nodes = scons_str2nodes(["Util.py", "UtilTests.py"])
52 assert len(nodes) == 2
53 assert isinstance(nodes[0], SCons.Node.FS.File)
54 assert isinstance(nodes[1], SCons.Node.FS.File)
55 assert nodes[0].path == "Util.py"
56 assert nodes[1].path == "UtilTests.py"
58 n1 = SCons.Node.FS.default_fs.File("Util.py")
59 nodes = scons_str2nodes([n1, "UtilTests.py"])
60 assert len(nodes) == 2
61 assert isinstance(nodes[0], SCons.Node.FS.File)
62 assert isinstance(nodes[1], SCons.Node.FS.File)
63 assert nodes[0].path == "Util.py"
64 assert nodes[1].path == "UtilTests.py"
66 class SConsNode(SCons.Node.Node):
68 node = scons_str2nodes(SConsNode())
72 node = scons_str2nodes(OtherNode())
76 """Test the subst function."""
78 loc['targets'] = PathList(map(os.path.normpath, [ "./foo/bar.exe",
81 loc['target'] = loc['targets'][0]
82 loc['sources'] = PathList(map(os.path.normpath, [ "./foo/blah.cpp",
86 newcom = scons_subst("test $targets $sources", loc, {})
87 assert newcom == "test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c"
89 newcom = scons_subst("test ${targets[:]} ${sources[0]}", loc, {})
90 assert newcom == "test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp"
92 newcom = scons_subst("test ${targets[1:]}v", loc, {})
93 assert newcom == "test /bar/baz.obj ../foo/baz.objv"
95 newcom = scons_subst("test $target", loc, {})
96 assert newcom == "test foo/bar.exe"
98 newcom = scons_subst("test $target$source[0]", loc, {})
99 assert newcom == "test foo/bar.exe[0]"
101 newcom = scons_subst("test ${target.file}", loc, {})
102 assert newcom == "test bar.exe"
104 newcom = scons_subst("test ${target.filebase}", loc, {})
105 assert newcom == "test bar"
107 newcom = scons_subst("test ${target.suffix}", loc, {})
108 assert newcom == "test .exe"
110 newcom = scons_subst("test ${target.base}", loc, {})
111 assert newcom == "test foo/bar"
113 newcom = scons_subst("test ${target.dir}", loc, {})
114 assert newcom == "test foo"
118 if __name__ == "__main__":
119 suite = unittest.makeSuite(UtilTestCase, 'test_')
120 if not unittest.TextTestRunner().run(suite).wasSuccessful():