Merged revisions 2136-2200,2202-2290,2292-2301 via svnmerge from
[scons.git] / src / engine / SCons / UtilTests.py
index 5f0eaa8c35ef63b17b81f8804379eca2e4b6d3b2..1149f35839a09d7450ae64ee782645a0207a93f4 100644 (file)
@@ -25,16 +25,19 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 
 import os
 import os.path
-import re
 import string
+import StringIO
 import sys
 import types
 import unittest
-import SCons.Node
-import SCons.Node.FS
-from SCons.Util import *
+
+from UserDict import UserDict
+
 import TestCmd
 
+import SCons.Errors
+
+from SCons.Util import *
 
 class OutBuffer:
     def __init__(self):
@@ -43,338 +46,48 @@ class OutBuffer:
     def write(self, str):
         self.buffer = self.buffer + str
 
-class DummyEnv:
-    def __init__(self, dict={}):
-        self.dict = dict
-
-    def Dictionary(self, key = None):
-        if not key:
-            return self.dict
-        return self.dict[key]
-
-    def sig_dict(self):
-        dict = self.dict.copy()
-        dict["TARGETS"] = 'tsig'
-        dict["SOURCES"] = 'ssig'
-        return dict
-
-def CmdGen1(target, source, env):
-    # Nifty trick...since Environment references are interpolated,
-    # instantiate an instance of a callable class with this one,
-    # which will then get evaluated.
-    assert target == 't', target
-    assert source == 's', source
-    return "${CMDGEN2('foo')}"
-
-class CmdGen2:
-    def __init__(self, mystr):
-        self.mystr = mystr
-
-    def __call__(self, target, source, env):
-        assert target == 't', target
-        assert source == 's', source
-        return [ self.mystr, env.Dictionary('BAR') ]
-
 class UtilTestCase(unittest.TestCase):
-    def test_subst(self):
-        """Test the subst function"""
-        loc = {}
-        target = [ "./foo/bar.exe",
-                   "/bar/baz.obj",
-                   "../foo/baz.obj" ]
-        source = [ "./foo/blah.cpp",
-                   "/bar/ack.cpp",
-                   "../foo/ack.c" ]
-        loc['xxx'] = None
-        loc['zero'] = 0
-        loc['one'] = 1
-        loc['BAR'] = 'baz'
-
-        loc['CMDGEN1'] = CmdGen1
-        loc['CMDGEN2'] = CmdGen2
-
-        env = DummyEnv(loc)
-
-        if os.sep == '/':
-            def cvt(str):
-                return str
-        else:
-            def cvt(str):
-                return string.replace(str, '/', os.sep)
-
-        newcom = scons_subst("test $TARGETS $SOURCES", env,
-                             target=target, source=source)
-        assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c")
-
-        newcom = scons_subst("test ${TARGETS[:]} ${SOURCES[0]}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp")
-
-        newcom = scons_subst("test ${TARGETS[1:]}v", env,
-                             target=target, source=source)
-        assert newcom == cvt("test /bar/baz.obj ../foo/baz.objv")
-
-        newcom = scons_subst("test $TARGET", env,
-                             target=target, source=source)
-        assert newcom == cvt("test foo/bar.exe")
-
-        newcom = scons_subst("test $TARGET$FOO[0]", env,
-                             target=target, source=source)
-        assert newcom == cvt("test foo/bar.exe[0]")
-
-        newcom = scons_subst("test ${TARGET.file}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test bar.exe")
-
-        newcom = scons_subst("test ${TARGET.filebase}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test bar")
-
-        newcom = scons_subst("test ${TARGET.suffix}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test .exe")
-
-        newcom = scons_subst("test ${TARGET.base}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test foo/bar")
-
-        newcom = scons_subst("test ${TARGET.dir}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test foo")
-
-        newcom = scons_subst("test ${TARGET.abspath}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test %s/foo/bar.exe"%SCons.Util.updrive(os.getcwd())), newcom
-
-        newcom = scons_subst("test ${SOURCES.abspath}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test %s/foo/blah.cpp %s %s/foo/ack.c"%(SCons.Util.updrive(os.getcwd()),
-                                                                     SCons.Util.updrive(os.path.abspath(os.path.normpath("/bar/ack.cpp"))),
-                                                                     SCons.Util.updrive(os.path.normpath(os.getcwd()+"/..")))), newcom
-
-        newcom = scons_subst("test ${SOURCE.abspath}", env,
-                             target=target, source=source)
-        assert newcom == cvt("test %s/foo/blah.cpp"%SCons.Util.updrive(os.getcwd())), newcom
-
-        # Note that we don't use the cvt() helper function here,
-        # because we're testing that the .posix attribute does its own
-        # conversion of the path name backslashes to slashes.
-        newcom = scons_subst("test ${TARGET.posix} ${SOURCE.posix}", env,
-                             target=target, source=source)
-        assert newcom == "test foo/bar.exe foo/blah.cpp", newcom
-
-        SCons.Node.FS.default_fs.BuildDir("#baz","#foo")
-
-        newcom = scons_subst("test ${SOURCE.srcdir}", env,
-                             target=target, source=['baz/bar.c'])
-
-        assert newcom == cvt("test foo"), newcom
-
-        newcom = scons_subst("test ${SOURCE.srcpath}", env,
-                             target=target, source=['baz/bar.c'])
-
-        assert newcom == cvt("test foo/bar.c"), newcom
-
-        newcom = scons_subst("test $xxx", env)
-        assert newcom == cvt("test"), newcom
-
-        newcom = scons_subst("test $($xxx$)", env)
-        assert newcom == cvt("test $($)"), newcom
-
-        newcom = scons_subst("test $( $xxx $)", env)
-        assert newcom == cvt("test $( $)"), newcom
-
-        newcom = scons_subst("test $($xxx$)", env, re.compile('\$[()]'))
-        assert newcom == cvt("test"), newcom
-
-        newcom = scons_subst("test $( $xxx $)", env, re.compile('\$[()]'))
-        assert newcom == cvt("test"), newcom
-
-        newcom = scons_subst("test $zero", env)
-        assert newcom == cvt("test 0"), newcom
-
-        newcom = scons_subst("test $one", env)
-        assert newcom == cvt("test 1"), newcom
-
-        newcom = scons_subst("test aXbXcXd", env, re.compile('X'))
-        assert newcom == cvt("test abcd"), newcom
-
-        newcom = scons_subst("test $CMDGEN1 $SOURCES $TARGETS",
-                             env, target='t', source='s')
-        assert newcom == cvt("test foo baz s t"), newcom
-
-        # Test against a former bug in scons_subst_list()
-        glob = { "FOO" : "$BAR",
-                 "BAR" : "BAZ",
-                 "BLAT" : "XYX",
-                 "BARXYX" : "BADNEWS" }
-        newcom = scons_subst("$FOO$BLAT", DummyEnv(glob))
-        assert newcom == "BAZXYX", newcom
-
-        # Test for double-dollar-sign behavior
-        glob = { "FOO" : "BAR",
-                 "BAZ" : "BLAT" }
-        newcom = scons_subst("$$FOO$BAZ", DummyEnv(glob))
-        assert newcom == "$FOOBLAT", newcom
-
     def test_splitext(self):
         assert splitext('foo') == ('foo','')
         assert splitext('foo.bar') == ('foo','.bar')
         assert splitext(os.path.join('foo.bar', 'blat')) == (os.path.join('foo.bar', 'blat'),'')
 
-    def test_subst_list(self):
-        """Testing the scons_subst_list() method..."""
-
-        class Node:
-            def __init__(self, name):
-                self.name = name
-            def __str__(self):
-                return self.name
-            def is_literal(self):
-                return 1
-        
-        loc = {}
-        target = [ "./foo/bar.exe",
-                   "/bar/baz with spaces.obj",
-                   "../foo/baz.obj" ]
-        source = [ "./foo/blah with spaces.cpp",
-                   "/bar/ack.cpp",
-                   "../foo/ack.c" ]
-        loc['xxx'] = None
-        loc['NEWLINE'] = 'before\nafter'
-
-        loc['DO'] = Node('do something')
-        loc['FOO'] = Node('foo.in')
-        loc['BAR'] = Node('bar with spaces.out')
-        loc['CRAZY'] = Node('crazy\nfile.in')
-
-        loc['CMDGEN1'] = CmdGen1
-        loc['CMDGEN2'] = CmdGen2
-
-        env = DummyEnv(loc)
-
-        if os.sep == '/':
-            def cvt(str):
-                return str
-        else:
-            def cvt(str):
-                return string.replace(str, '/', os.sep)
-
-        cmd_list = scons_subst_list("$TARGETS", env,
-                                    target=target,
-                                    source=source)
-        assert cmd_list[0][1] == cvt("/bar/baz with spaces.obj"), cmd_list[0][1]
-
-        cmd_list = scons_subst_list("$SOURCES $NEWLINE $TARGETS", env,
-                                    target=target,
-                                    source=source)
-        assert len(cmd_list) == 2, cmd_list
-        assert cmd_list[0][0] == cvt('foo/blah with spaces.cpp'), cmd_list[0][0]
-        assert cmd_list[1][2] == cvt("/bar/baz with spaces.obj"), cmd_list[1]
-
-        cmd_list = scons_subst_list("$SOURCES$NEWLINE", env,
-                                    target=target,
-                                    source=source)
-        assert len(cmd_list) == 2, cmd_list
-        assert cmd_list[1][0] == 'after', cmd_list[1][0]
-        assert cmd_list[0][2] == cvt('../foo/ack.cbefore'), cmd_list[0][2]
-
-        cmd_list = scons_subst_list("$DO --in=$FOO --out=$BAR", env)
-        assert len(cmd_list) == 1, cmd_list
-        assert len(cmd_list[0]) == 3, cmd_list
-        assert cmd_list[0][0] == 'do something', cmd_list[0][0]
-        assert cmd_list[0][1] == '--in=foo.in', cmd_list[0][1]
-        assert cmd_list[0][2] == '--out=bar with spaces.out', cmd_list[0][2]
-
-        # This test is now fixed, and works like it should.
-        cmd_list = scons_subst_list("$DO --in=$CRAZY --out=$BAR", env)
-        assert len(cmd_list) == 1, map(str, cmd_list[0])
-        assert len(cmd_list[0]) == 3, cmd_list
-        assert cmd_list[0][0] == 'do something', cmd_list[0][0]
-        assert cmd_list[0][1] == '--in=crazy\nfile.in', cmd_list[0][1]
-        assert cmd_list[0][2] == '--out=bar with spaces.out', cmd_list[0][2]
-        
-        # Test inputting a list to scons_subst_list()
-        cmd_list = scons_subst_list([ "$SOURCES$NEWLINE", "$TARGETS",
-                                        "This is a test" ],
-                                    env,
-                                    target=target,
-                                    source=source)
-        assert len(cmd_list) == 2, len(cmd_list)
-        assert cmd_list[0][0] == cvt('foo/blah with spaces.cpp'), cmd_list[0][0]
-        assert cmd_list[1][0] == cvt("after"), cmd_list[1]
-        assert cmd_list[1][4] == "This is a test", cmd_list[1]
-
-        # Test interpolating a callable.
-        cmd_list = scons_subst_list("testing $CMDGEN1 $TARGETS $SOURCES", env,
-                                    target='t', source='s')
-        assert len(cmd_list) == 1, len(cmd_list)
-        assert cmd_list[0][0] == 'testing', cmd_list[0][0]
-        assert cmd_list[0][1] == 'foo', cmd_list[0][1]
-        assert cmd_list[0][2] == 'bar with spaces.out', cmd_list[0][2]
-        assert cmd_list[0][3] == 't', cmd_list[0][3]
-        assert cmd_list[0][4] == 's', cmd_list[0][4]
-
-
-        # Test against a former bug in scons_subst_list()
-        glob = { "FOO" : "$BAR",
-                 "BAR" : "BAZ",
-                 "BLAT" : "XYX",
-                 "BARXYX" : "BADNEWS" }
-        cmd_list = scons_subst_list("$FOO$BLAT", DummyEnv(glob))
-        assert cmd_list[0][0] == "BAZXYX", cmd_list[0][0]
-
-        # Test for double-dollar-sign behavior
-        glob = { "FOO" : "BAR",
-                 "BAZ" : "BLAT" }
-        cmd_list = scons_subst_list("$$FOO$BAZ", DummyEnv(glob))
-        assert cmd_list[0][0] == "$FOOBLAT", cmd_list[0][0]
-
-        # Now test escape functionality
-        def escape_func(foo):
-            return '**' + foo + '**'
-        def quote_func(foo):
-            return foo
-        glob = { "FOO" : PathList([ 'foo\nwith\nnewlines',
-                                    'bar\nwith\nnewlines' ]) }
-        cmd_list = scons_subst_list("$FOO", DummyEnv(glob))
-        assert cmd_list[0][0] == 'foo\nwith\nnewlines', cmd_list[0][0]
-        cmd_list[0][0].escape(escape_func)
-        assert cmd_list[0][0] == '**foo\nwith\nnewlines**', cmd_list[0][0]
-        assert cmd_list[0][1] == 'bar\nwith\nnewlines', cmd_list[0][0]
-        cmd_list[0][1].escape(escape_func)
-        assert cmd_list[0][1] == '**bar\nwith\nnewlines**', cmd_list[0][0]
-
-    def test_quote_spaces(self):
-        """Testing the quote_spaces() method..."""
-       q = quote_spaces('x')
-       assert q == 'x', q
-
-       q = quote_spaces('x x')
-       assert q == '"x x"', q
-
-       q = quote_spaces('x\tx')
-       assert q == '"x\tx"', q
-
-    def test_render_tree(self):
-        class Node:
-            def __init__(self, name, children=[]):
-                self.children = children
-                self.name = name
-            def __str__(self):
-                return self.name
-
-        def get_children(node):
-            return node.children
-
-        windows_h = Node("windows.h")
-        stdlib_h = Node("stdlib.h")
-        stdio_h = Node("stdio.h")
-        bar_c = Node("bar.c", [stdlib_h, windows_h])
-        bar_o = Node("bar.o", [bar_c])
-        foo_c = Node("foo.c", [stdio_h])
-        foo_o = Node("foo.o", [foo_c])
-        foo = Node("foo", [foo_o, bar_o])
+    class Node:
+        def __init__(self, name, children=[]):
+            self.children = children
+            self.name = name
+            self.nocache = None
+        def __str__(self):
+            return self.name
+        def exists(self):
+            return 1
+        def rexists(self):
+            return 1
+        def has_builder(self):
+            return 1
+        def has_explicit_builder(self):
+            return 1
+        def side_effect(self):
+            return 1
+        def precious(self):
+            return 1
+        def always_build(self):
+            return 1
+        def current(self):
+            return 1
+        def noclean(self):
+            return 1
+
+    def tree_case_1(self):
+        """Fixture for the render_tree() and print_tree() tests."""
+        windows_h = self.Node("windows.h")
+        stdlib_h = self.Node("stdlib.h")
+        stdio_h = self.Node("stdio.h")
+        bar_c = self.Node("bar.c", [stdlib_h, windows_h])
+        bar_o = self.Node("bar.o", [bar_c])
+        foo_c = self.Node("foo.c", [stdio_h])
+        foo_o = self.Node("foo.o", [foo_c])
+        foo = self.Node("foo", [foo_o, bar_o])
 
         expect = """\
 +-foo
@@ -387,13 +100,20 @@ class UtilTestCase(unittest.TestCase):
       +-windows.h
 """
 
-        actual = render_tree(foo, get_children)
-        assert expect == actual, (expect, actual)
-        
-        bar_h = Node('bar.h', [stdlib_h])
-        blat_h = Node('blat.h', [stdlib_h])
-        blat_c = Node('blat.c', [blat_h, bar_h])
-        blat_o = Node('blat.o', [blat_c])
+        lines = string.split(expect, '\n')[:-1]
+        lines = map(lambda l: '[E BSPACN ]'+l, lines)
+        withtags = string.join(lines, '\n') + '\n'
+
+        return foo, expect, withtags
+
+    def tree_case_2(self, prune=1):
+        """Fixture for the render_tree() and print_tree() tests."""
+
+        stdlib_h = self.Node("stdlib.h")
+        bar_h = self.Node('bar.h', [stdlib_h])
+        blat_h = self.Node('blat.h', [stdlib_h])
+        blat_c = self.Node('blat.c', [blat_h, bar_h])
+        blat_o = self.Node('blat.o', [blat_c])
 
         expect = """\
 +-blat.o
@@ -401,16 +121,80 @@ class UtilTestCase(unittest.TestCase):
     +-blat.h
     | +-stdlib.h
     +-bar.h
+      +-[stdlib.h]
 """
 
-        actual = render_tree(blat_o, get_children, 1)
-        assert expect == actual, (expect, actual)        
+        if not prune:
+            expect = string.replace(expect, '[', '')
+            expect = string.replace(expect, ']', '')
+
+        lines = string.split(expect, '\n')[:-1]
+        lines = map(lambda l: '[E BSPACN ]'+l, lines)
+        withtags = string.join(lines, '\n') + '\n'
+
+        return blat_o, expect, withtags
+
+    def test_render_tree(self):
+        """Test the render_tree() function"""
+        def get_children(node):
+            return node.children
+
+        node, expect, withtags = self.tree_case_1()
+        actual = render_tree(node, get_children)
+        assert expect == actual, (expect, actual)
+
+        node, expect, withtags = self.tree_case_2()
+        actual = render_tree(node, get_children, 1)
+        assert expect == actual, (expect, actual)
+
+    def test_print_tree(self):
+        """Test the print_tree() function"""
+        def get_children(node):
+            return node.children
+
+        save_stdout = sys.stdout
+
+        try:
+            node, expect, withtags = self.tree_case_1()
+
+            sys.stdout = StringIO.StringIO()
+            print_tree(node, get_children)
+            actual = sys.stdout.getvalue()
+            assert expect == actual, (expect, actual)
+
+            sys.stdout = StringIO.StringIO()
+            print_tree(node, get_children, showtags=1)
+            actual = sys.stdout.getvalue()
+            assert withtags == actual, (withtags, actual)
+
+            node, expect, withtags = self.tree_case_2(prune=0)
+
+            sys.stdout = StringIO.StringIO()
+            print_tree(node, get_children, 1)
+            actual = sys.stdout.getvalue()
+            assert expect == actual, (expect, actual)
+
+            sys.stdout = StringIO.StringIO()
+            # The following call should work here:
+            #    print_tree(node, get_children, 1, showtags=1)
+            # For some reason I don't understand, though, *this*
+            # time that we call print_tree, the visited dictionary
+            # is still populated with the values from the last call!
+            # I can't see why this would be, short of a bug in Python,
+            # and rather than continue banging my head against the
+            # brick wall for a *test*, we're going to going with
+            # the cheap, easy workaround:
+            print_tree(node, get_children, 1, showtags=1, visited={})
+            actual = sys.stdout.getvalue()
+            assert withtags == actual, (withtags, actual)
+        finally:
+            sys.stdout = save_stdout
 
     def test_is_Dict(self):
         assert is_Dict({})
-        import UserDict
-        assert is_Dict(UserDict.UserDict())
+        assert is_Dict(UserDict())
         assert not is_Dict([])
+        assert not is_Dict(())
         assert not is_Dict("")
         if hasattr(types, 'UnicodeType'):
             exec "assert not is_Dict(u'')"
@@ -419,16 +203,12 @@ class UtilTestCase(unittest.TestCase):
         assert is_List([])
         import UserList
         assert is_List(UserList.UserList())
+        assert not is_List(())
         assert not is_List({})
         assert not is_List("")
         if hasattr(types, 'UnicodeType'):
             exec "assert not is_List(u'')"
 
-    def test_Split(self):
-        assert Split("foo bar") == ["foo", "bar"]
-        assert Split(["foo", "bar"]) == ["foo", "bar"]
-        assert Split("foo") == ["foo"]
-
     def test_is_String(self):
         assert is_String("")
         if hasattr(types, 'UnicodeType'):
@@ -441,6 +221,15 @@ class UtilTestCase(unittest.TestCase):
             assert is_String(UserString.UserString(''))
         assert not is_String({})
         assert not is_String([])
+        assert not is_String(())
+
+    def test_is_Tuple(self):
+        assert is_Tuple(())
+        assert not is_Tuple([])
+        assert not is_Tuple({})
+        assert not is_Tuple("")
+        if hasattr(types, 'UnicodeType'):
+            exec "assert not is_Tuple(u'')"
 
     def test_to_String(self):
         """Test the to_String() method."""
@@ -499,49 +288,94 @@ class UtilTestCase(unittest.TestCase):
 
         env_path = os.environ['PATH']
 
-        pathdirs_1234 = [ test.workpath('sub1'),
-                          test.workpath('sub2'),
-                          test.workpath('sub3'),
-                          test.workpath('sub4'),
-                        ] + string.split(env_path, os.pathsep)
-
-        pathdirs_1243 = [ test.workpath('sub1'),
-                          test.workpath('sub2'),
-                          test.workpath('sub4'),
-                          test.workpath('sub3'),
-                        ] + string.split(env_path, os.pathsep)
-
-        os.environ['PATH'] = string.join(pathdirs_1234, os.pathsep)
-        wi = WhereIs('xxx.exe')
-        assert wi == test.workpath(sub3_xxx_exe), wi
-        wi = WhereIs('xxx.exe', pathdirs_1243)
-        assert wi == test.workpath(sub4_xxx_exe), wi
-        wi = WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep))
-        assert wi == test.workpath(sub4_xxx_exe), wi
-
-        os.environ['PATH'] = string.join(pathdirs_1243, os.pathsep)
-        wi = WhereIs('xxx.exe')
-        assert wi == test.workpath(sub4_xxx_exe), wi
-        wi = WhereIs('xxx.exe', pathdirs_1234)
-        assert wi == test.workpath(sub3_xxx_exe), wi
-        wi = WhereIs('xxx.exe', string.join(pathdirs_1234, os.pathsep))
-        assert wi == test.workpath(sub3_xxx_exe), wi
-
-        if sys.platform == 'win32':
-            wi = WhereIs('xxx', pathext = '')
-            assert wi is None, wi
+        try:
+            pathdirs_1234 = [ test.workpath('sub1'),
+                              test.workpath('sub2'),
+                              test.workpath('sub3'),
+                              test.workpath('sub4'),
+                            ] + string.split(env_path, os.pathsep)
+
+            pathdirs_1243 = [ test.workpath('sub1'),
+                              test.workpath('sub2'),
+                              test.workpath('sub4'),
+                              test.workpath('sub3'),
+                            ] + string.split(env_path, os.pathsep)
+
+            os.environ['PATH'] = string.join(pathdirs_1234, os.pathsep)
+            wi = WhereIs('xxx.exe')
+            assert wi == test.workpath(sub3_xxx_exe), wi
+            wi = WhereIs('xxx.exe', pathdirs_1243)
+            assert wi == test.workpath(sub4_xxx_exe), wi
+            wi = WhereIs('xxx.exe', string.join(pathdirs_1243, os.pathsep))
+            assert wi == test.workpath(sub4_xxx_exe), wi
+
+            wi = WhereIs('xxx.exe',reject = sub3_xxx_exe)
+            assert wi == test.workpath(sub4_xxx_exe), wi
+            wi = WhereIs('xxx.exe', pathdirs_1243, reject = sub3_xxx_exe)
+            assert wi == test.workpath(sub4_xxx_exe), wi
 
-            wi = WhereIs('xxx', pathext = '.exe')
+            os.environ['PATH'] = string.join(pathdirs_1243, os.pathsep)
+            wi = WhereIs('xxx.exe')
             assert wi == test.workpath(sub4_xxx_exe), wi
+            wi = WhereIs('xxx.exe', pathdirs_1234)
+            assert wi == test.workpath(sub3_xxx_exe), wi
+            wi = WhereIs('xxx.exe', string.join(pathdirs_1234, os.pathsep))
+            assert wi == test.workpath(sub3_xxx_exe), wi
+
+            if sys.platform == 'win32':
+                wi = WhereIs('xxx', pathext = '')
+                assert wi is None, wi
+
+                wi = WhereIs('xxx', pathext = '.exe')
+                assert wi == test.workpath(sub4_xxx_exe), wi
 
-            wi = WhereIs('xxx', path = pathdirs_1234, pathext = '.BAT;.EXE')
-            assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi
+                wi = WhereIs('xxx', path = pathdirs_1234, pathext = '.BAT;.EXE')
+                assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi
+
+                # Test that we return a normalized path even when
+                # the path contains forward slashes.
+                forward_slash = test.workpath('') + '/sub3'
+                wi = WhereIs('xxx', path = forward_slash, pathext = '.EXE')
+                assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi
+
+            del os.environ['PATH']
+            wi = WhereIs('xxx.exe')
+            assert wi is None, wi
 
-            # Test that we return a normalized path even when
-            # the path contains forward slashes.
-            forward_slash = test.workpath('') + '/sub3'
-            wi = WhereIs('xxx', path = forward_slash, pathext = '.EXE')
-            assert string.lower(wi) == string.lower(test.workpath(sub3_xxx_exe)), wi
+        finally:
+            os.environ['PATH'] = env_path
+            
+
+    def test_is_valid_construction_var(self):
+        """Testing is_valid_construction_var()"""
+        r = is_valid_construction_var("_a")
+        assert not r is None, r
+        r = is_valid_construction_var("z_")
+        assert not r is None, r
+        r = is_valid_construction_var("X_")
+        assert not r is None, r
+        r = is_valid_construction_var("2a")
+        assert r is None, r
+        r = is_valid_construction_var("a2_")
+        assert not r is None, r
+        r = is_valid_construction_var("/")
+        assert r is None, r
+        r = is_valid_construction_var("_/")
+        assert r is None, r
+        r = is_valid_construction_var("a/")
+        assert r is None, r
+        r = is_valid_construction_var(".b")
+        assert r is None, r
+        r = is_valid_construction_var("_.b")
+        assert r is None, r
+        r = is_valid_construction_var("b1._")
+        assert r is None, r
+        r = is_valid_construction_var("-b")
+        assert r is None, r
+        r = is_valid_construction_var("_-b")
+        assert r is None, r
+        r = is_valid_construction_var("b1-_")
+        assert r is None, r
 
     def test_get_env_var(self):
         """Testing get_environment_var()."""
@@ -580,80 +414,22 @@ class UtilTestCase(unittest.TestCase):
         s.baz = 6
 
         assert p.baz == 5, p.baz
-
-    def test_Literal(self):
-        """Test the Literal() function."""
-        cmd_list = [ '$FOO', Literal('$BAR') ]
-        cmd_list = scons_subst_list(cmd_list,
-                                    DummyEnv({ 'FOO' : 'BAZ',
-                                               'BAR' : 'BLAT' }))
-        def escape_func(cmd):
-            return '**' + cmd + '**'
-
-        map(lambda x, e=escape_func: x.escape(e), cmd_list[0])
-        cmd_list = map(str, cmd_list[0])
-        assert cmd_list[0] == 'BAZ', cmd_list[0]
-        assert cmd_list[1] == '**$BAR**', cmd_list[1]
-
-    def test_mapPaths(self):
-        """Test the mapPaths function"""
-        fs = SCons.Node.FS.FS()
-        dir=fs.Dir('foo')
-        file=fs.File('bar/file')
-        
-        class DummyEnv:
-            def subst(self, arg):
-                return 'bar'
-
-        res = mapPaths([ file, 'baz', 'blat/boo', '#test' ], dir)
-        assert res[0] == file, res[0]
-        assert res[1] == os.path.join('foo', 'baz'), res[1]
-        assert res[2] == os.path.join('foo', 'blat/boo'), res[2]
-        assert res[3] == '#test', res[3]
-
-        env=DummyEnv()
-        res=mapPaths('bleh', dir, env)
-        assert res[0] == os.path.normpath('foo/bar'), res[1]
+        assert p.get() == s, p.get()
 
     def test_display(self):
         old_stdout = sys.stdout
         sys.stdout = OutBuffer()
-        SCons.Util.display("line1")
+        display("line1")
         display.set_mode(0)
-        SCons.Util.display("line2")
+        display("line2")
         display.set_mode(1)
-        SCons.Util.display("line3")
-
-        assert sys.stdout.buffer == "line1\nline3\n"
-        sys.stdout = old_stdout
-
-    def test_fs_delete(self):
-        test = TestCmd.TestCmd(workdir = '')
-        base = test.workpath('')
-        xxx = test.workpath('xxx.xxx')
-        sub1_yyy = test.workpath('sub1', 'yyy.yyy')
-        test.subdir('sub1')
-        test.write(xxx, "\n")
-        test.write(sub1_yyy, "\n")
-
-        old_stdout = sys.stdout
-        sys.stdout = OutBuffer()
-
-        exp = "Removed " + os.path.join(base, sub1_yyy) + '\n' + \
-              "Removed directory " + os.path.join(base, 'sub1') + '\n' + \
-              "Removed " + os.path.join(base, xxx) + '\n' + \
-              "Removed directory " + base + '\n'
-
-        SCons.Util.fs_delete(base, remove=0)
-        assert sys.stdout.buffer == exp
-        assert os.path.exists(sub1_yyy)
-
-        sys.stdout.buffer = ""
-        SCons.Util.fs_delete(base, remove=1)
-        assert sys.stdout.buffer == exp
-        assert not os.path.exists(base)
-
-        test._dirlist = None
+        display("line3")
+        display("line4\n", append_newline=0)
+        display.set_mode(0)
+        display("dont print1")
+        display("dont print2\n", append_newline=0)
+        display.set_mode(1)
+        assert sys.stdout.buffer == "line1\nline3\nline4\n"
         sys.stdout = old_stdout
 
     def test_get_native_path(self):
@@ -661,54 +437,257 @@ class UtilTestCase(unittest.TestCase):
         import tempfile
         filename = tempfile.mktemp()
         str = '1234567890 ' + filename
-        open(filename, 'w').write(str)
-        assert open(SCons.Util.get_native_path(filename)).read() == str
-
-    def test_subst_dict(self):
-        """Test substituting dictionary values in an Action
-        """
-        d = subst_dict([], [], DummyEnv({'a' : 'A', 'b' : 'B'}))
-        assert d['a'] == 'A', d
-        assert d['b'] == 'B', d
-
-        d = subst_dict(target = 't', source = 's', env=DummyEnv())
-        assert str(d['TARGETS']) == 't', d['TARGETS']
-        assert str(d['TARGET']) == 't', d['TARGET']
-        assert str(d['SOURCES']) == 's', d['SOURCES']
-        assert str(d['SOURCE']) == 's', d['SOURCE']
-
-        d = subst_dict(target = ['t1', 't2'],
-                       source = ['s1', 's2'],
-                       env = DummyEnv())
-        TARGETS = map(lambda x: str(x), d['TARGETS'])
-        TARGETS.sort()
-        assert TARGETS == ['t1', 't2'], d['TARGETS']
-        assert str(d['TARGET']) == 't1', d['TARGET']
-        SOURCES = map(lambda x: str(x), d['SOURCES'])
-        SOURCES.sort()
-        assert SOURCES == ['s1', 's2'], d['SOURCES']
-        assert str(d['SOURCE']) == 's1', d['SOURCE']
-
-        class N:
-            def __init__(self, name):
-                self.name = name
-            def __str__(self):
-                return self.name
-            def rstr(self):
-                return 'rstr-' + self.name
-
-        d = subst_dict(target = [N('t3'), 't4'],
-                       source = ['s3', N('s4')],
-                       env = DummyEnv())
-        TARGETS = map(lambda x: str(x), d['TARGETS'])
-        TARGETS.sort()
-        assert TARGETS == ['t3', 't4'], d['TARGETS']
-        SOURCES = map(lambda x: str(x), d['SOURCES'])
-        SOURCES.sort()
-        assert SOURCES == ['rstr-s4', 's3'], d['SOURCES']
+        try:
+            open(filename, 'w').write(str)
+            assert open(get_native_path(filename)).read() == str
+        finally:
+            try:
+                os.unlink(filename)
+            except OSError:
+                pass
 
+    def test_PrependPath(self):
+        """Test prepending to a path"""
+        p1 = r'C:\dir\num\one;C:\dir\num\two'
+        p2 = r'C:\mydir\num\one;C:\mydir\num\two'
+        # have to include the pathsep here so that the test will work on UNIX too.
+        p1 = PrependPath(p1,r'C:\dir\num\two',sep = ';')
+        p1 = PrependPath(p1,r'C:\dir\num\three',sep = ';')
+        p2 = PrependPath(p2,r'C:\mydir\num\three',sep = ';')
+        p2 = PrependPath(p2,r'C:\mydir\num\one',sep = ';')
+        assert(p1 == r'C:\dir\num\three;C:\dir\num\two;C:\dir\num\one')
+        assert(p2 == r'C:\mydir\num\one;C:\mydir\num\three;C:\mydir\num\two')
+
+    def test_AppendPath(self):
+        """Test appending to a path."""
+        p1 = r'C:\dir\num\one;C:\dir\num\two'
+        p2 = r'C:\mydir\num\one;C:\mydir\num\two'
+        # have to include the pathsep here so that the test will work on UNIX too.
+        p1 = AppendPath(p1,r'C:\dir\num\two',sep = ';')
+        p1 = AppendPath(p1,r'C:\dir\num\three',sep = ';')
+        p2 = AppendPath(p2,r'C:\mydir\num\three',sep = ';')
+        p2 = AppendPath(p2,r'C:\mydir\num\one',sep = ';')
+        assert(p1 == r'C:\dir\num\one;C:\dir\num\two;C:\dir\num\three')
+        assert(p2 == r'C:\mydir\num\two;C:\mydir\num\three;C:\mydir\num\one')
+
+    def test_NodeList(self):
+        """Test NodeList class"""
+        class TestClass:
+            def __init__(self, name, child=None):
+                self.child = child
+                self.bar = name
+            def foo(self):
+                return self.bar + "foo"
+            def getself(self):
+                return self
+
+        t1 = TestClass('t1', TestClass('t1child'))
+        t2 = TestClass('t2', TestClass('t2child'))
+        t3 = TestClass('t3')
+
+        nl = NodeList([t1, t2, t3])
+        assert nl.foo() == [ 't1foo', 't2foo', 't3foo' ], nl.foo()
+        assert nl.bar == [ 't1', 't2', 't3' ], nl.bar
+        assert nl.getself().bar == [ 't1', 't2', 't3' ], nl.getself().bar
+        assert nl[0:2].child.foo() == [ 't1childfoo', 't2childfoo' ], \
+               nl[0:2].child.foo()
+        assert nl[0:2].child.bar == [ 't1child', 't2child' ], \
+               nl[0:2].child.bar
+
+    def test_CLVar(self):
+        """Test the command-line construction variable class"""
+        f = SCons.Util.CLVar('a b')
+
+        r = f + 'c d'
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + ' c d'
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + ['c d']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c d'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + [' c d']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', ' c d'], r.data
+        assert str(r) == 'a b  c d', str(r)
+
+        r = f + ['c', 'd']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + [' c', 'd']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', ' c', 'd'], r.data
+        assert str(r) == 'a b  c d', str(r)
+
+        f = SCons.Util.CLVar(['a b'])
+
+        r = f + 'c d'
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + ' c d'
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + ['c d']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a b', 'c d'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + [' c d']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a b', ' c d'], r.data
+        assert str(r) == 'a b  c d', str(r)
+
+        r = f + ['c', 'd']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + [' c', 'd']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a b', ' c', 'd'], r.data
+        assert str(r) == 'a b  c d', str(r)
+
+        f = SCons.Util.CLVar(['a', 'b'])
+
+        r = f + 'c d'
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + ' c d'
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + ['c d']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c d'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + [' c d']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', ' c d'], r.data
+        assert str(r) == 'a b  c d', str(r)
+
+        r = f + ['c', 'd']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', 'c', 'd'], r.data
+        assert str(r) == 'a b c d', str(r)
+
+        r = f + [' c', 'd']
+        assert isinstance(r, SCons.Util.CLVar), type(r)
+        assert r.data == ['a', 'b', ' c', 'd'], r.data
+        assert str(r) == 'a b  c d', str(r)
+
+    def test_Selector(self):
+        """Test the Selector class"""
+
+        s = Selector({'a' : 'AAA', 'b' : 'BBB'})
+        assert s['a'] == 'AAA', s['a']
+        assert s['b'] == 'BBB', s['b']
+        exc_caught = None
+        try:
+            x = s['c']
+        except KeyError:
+            exc_caught = 1
+        assert exc_caught, "should have caught a KeyError"
+        s['c'] = 'CCC'
+        assert s['c'] == 'CCC', s['c']
+
+        class DummyEnv(UserDict):
+            def subst(self, key):
+                if key[0] == '$':
+                    return self[key[1:]]
+                return key
+
+        env = DummyEnv()
+
+        s = Selector({'.d' : 'DDD', '.e' : 'EEE'})
+        ret = s(env, [])
+        assert ret == None, ret
+        ret = s(env, ['foo.d'])
+        assert ret == 'DDD', ret
+        ret = s(env, ['bar.e'])
+        assert ret == 'EEE', ret
+        ret = s(env, ['bar.x'])
+        assert ret == None, ret
+        s[None] = 'XXX'
+        ret = s(env, ['bar.x'])
+        assert ret == 'XXX', ret
+
+        env = DummyEnv({'FSUFF' : '.f', 'GSUFF' : '.g'})
+
+        s = Selector({'$FSUFF' : 'FFF', '$GSUFF' : 'GGG'})
+        ret = s(env, ['foo.f'])
+        assert ret == 'FFF', ret
+        ret = s(env, ['bar.g'])
+        assert ret == 'GGG', ret
+
+    def test_adjustixes(self):
+        """Test the adjustixes() function"""
+        r = adjustixes('file', 'pre-', '-suf')
+        assert r == 'pre-file-suf', r
+        r = adjustixes('pre-file', 'pre-', '-suf')
+        assert r == 'pre-file-suf', r
+        r = adjustixes('file-suf', 'pre-', '-suf')
+        assert r == 'pre-file-suf', r
+        r = adjustixes('pre-file-suf', 'pre-', '-suf')
+        assert r == 'pre-file-suf', r
+        r = adjustixes('pre-file.xxx', 'pre-', '-suf')
+        assert r == 'pre-file.xxx', r
+        r = adjustixes('dir/file', 'pre-', '-suf')
+        assert r == os.path.join('dir', 'pre-file-suf'), r
+
+    def test_containsAny(self):
+        """Test the containsAny() function"""
+        assert containsAny('*.py', '*?[]')
+        assert not containsAny('file.txt', '*?[]')
+
+    def test_containsAll(self):
+        """Test the containsAll() function"""
+        assert containsAll('43221', '123')
+        assert not containsAll('134', '123')
+
+    def test_containsOnly(self):
+        """Test the containsOnly() function"""
+        assert containsOnly('.83', '0123456789.')
+        assert not containsOnly('43221', '123')
+
+    def test_LogicalLines(self):
+        """Test the LogicalLines class"""
+        fobj = StringIO.StringIO(r"""
+foo \
+bar \
+baz
+foo
+bling \
+bling \ bling
+bling
+""")
+
+        lines = LogicalLines(fobj).readlines()
+        assert lines == [
+            '\n',
+            'foo bar baz\n',
+            'foo\n',
+            'bling bling \\ bling\n',
+            'bling\n',
+        ], lines
 
 if __name__ == "__main__":
     suite = unittest.makeSuite(UtilTestCase, 'test_')
     if not unittest.TextTestRunner().run(suite).wasSuccessful():
-       sys.exit(1)
+        sys.exit(1)