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__"
33 from SCons.Util import scons_str2nodes, scons_subst, PathList
36 class UtilTestCase(unittest.TestCase):
37 def test_str2nodes(self):
38 """Test the str2nodes function."""
39 nodes = scons_str2nodes("Util.py UtilTests.py")
40 assert len(nodes) == 2
41 assert isinstance(nodes[0], SCons.Node.FS.File)
42 assert isinstance(nodes[1], SCons.Node.FS.File)
43 assert nodes[0].path == "Util.py"
44 assert nodes[1].path == "UtilTests.py"
46 nodes = scons_str2nodes("Util.py UtilTests.py", SCons.Node.FS.FS().File)
47 assert len(nodes) == 2
48 assert isinstance(nodes[0], SCons.Node.FS.File)
49 assert isinstance(nodes[1], SCons.Node.FS.File)
50 assert nodes[0].path == "Util.py"
51 assert nodes[1].path == "UtilTests.py"
53 nodes = scons_str2nodes(["Util.py", "UtilTests.py"])
54 assert len(nodes) == 2
55 assert isinstance(nodes[0], SCons.Node.FS.File)
56 assert isinstance(nodes[1], SCons.Node.FS.File)
57 assert nodes[0].path == "Util.py"
58 assert nodes[1].path == "UtilTests.py"
60 n1 = SCons.Node.FS.default_fs.File("Util.py")
61 nodes = scons_str2nodes([n1, "UtilTests.py"])
62 assert len(nodes) == 2
63 assert isinstance(nodes[0], SCons.Node.FS.File)
64 assert isinstance(nodes[1], SCons.Node.FS.File)
65 assert nodes[0].path == "Util.py"
66 assert nodes[1].path == "UtilTests.py"
68 class SConsNode(SCons.Node.Node):
70 node = scons_str2nodes(SConsNode())
74 node = scons_str2nodes(OtherNode())
78 """Test the subst function."""
80 loc['targets'] = PathList(map(os.path.normpath, [ "./foo/bar.exe",
83 loc['target'] = loc['targets'][0]
84 loc['sources'] = PathList(map(os.path.normpath, [ "./foo/blah.cpp",
93 return string.replace(str, '/', os.sep)
96 newcom = scons_subst("test $targets $sources", loc, {})
97 assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c")
99 newcom = scons_subst("test ${targets[:]} ${sources[0]}", loc, {})
100 assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp")
102 newcom = scons_subst("test ${targets[1:]}v", loc, {})
103 assert newcom == cvt("test /bar/baz.obj ../foo/baz.objv")
105 newcom = scons_subst("test $target", loc, {})
106 assert newcom == cvt("test foo/bar.exe")
108 newcom = scons_subst("test $target$source[0]", loc, {})
109 assert newcom == cvt("test foo/bar.exe[0]")
111 newcom = scons_subst("test ${target.file}", loc, {})
112 assert newcom == cvt("test bar.exe")
114 newcom = scons_subst("test ${target.filebase}", loc, {})
115 assert newcom == cvt("test bar")
117 newcom = scons_subst("test ${target.suffix}", loc, {})
118 assert newcom == cvt("test .exe")
120 newcom = scons_subst("test ${target.base}", loc, {})
121 assert newcom == cvt("test foo/bar")
123 newcom = scons_subst("test ${target.dir}", loc, {})
124 assert newcom == cvt("test foo")
128 if __name__ == "__main__":
129 suite = unittest.makeSuite(UtilTestCase, 'test_')
130 if not unittest.TextTestRunner().run(suite).wasSuccessful():