Commits

Steven Knight  committed f012a57

Fix Fedora Core 3 test portability.

  • Participants
  • Parent commits 92f85a3

Comments (0)

Files changed (9)

File etc/TestSCons.py

 	    kw['workdir'] = ''
 	apply(TestCommon.__init__, [self], kw)
 
-    def detect(self, var, prog=None):
+    def Environment(self, ENV=None, *args, **kw):
+        """
+        Return a construction Environment that optionally overrides
+        the default external environment with the specified ENV.
+        """
+        import SCons.Environment
+        import SCons.Errors
+        if not ENV is None:
+            kw['ENV'] = ENV
+        try:
+            return apply(SCons.Environment.Environment, args, kw)
+        except (SCons.Errors.UserError, SCons.Errors.InternalError):
+            return None
+
+    def detect(self, var, prog=None, ENV=None):
         """
         Detect a program named 'prog' by first checking the construction
         variable named 'var' and finally searching the path used by
         prog is None, then the value of the environment variable will be
         used as prog.
         """
-
-        import SCons.Environment
-        env = SCons.Environment.Environment()
+        env = self.Environment(ENV)
         try:
             if prog is None:
                 prog = env[var]
         except KeyError:
             return None
 
-    def detect_tool(self, tool, prog=None):
+    def detect_tool(self, tool, prog=None, ENV=None):
         """
         Given a tool (i.e., tool specification that would be passed
-        to the "tools=" parameter of Environment()) and one a program that
+        to the "tools=" parameter of Environment()) and a program that
         corresponds to that tool, return true if and only if we can find
         that tool using Environment.Detect().
 
-        By default, progs is set to the value passed into the tools parameter.
+        By default, prog is set to the value passed into the tools parameter.
         """
 
         if not prog:
             prog = tool
-        import SCons.Environment
-        import SCons.Errors
-        try:
-            env=SCons.Environment.Environment(tools=[tool])
-        except (SCons.Errors.UserError, SCons.Errors.InternalError):
+        env = self.Environment(ENV, tools=[tool])
+        if env is None:
             return None
         return env.Detect([prog])
 
+    def where_is(self, prog, path=None):
+        """
+        Given a program, search for it in the specified external PATH,
+        or in the actual external PATH is none is specified.
+        """
+        import SCons.Environment
+        env = SCons.Environment.Environment()
+        if path is None:
+            path = os.environ['PATH']
+        return env.WhereIs(prog, path)
+
     def wrap_stdout(self, build_str = "", read_str = "", error = 0, cleaning = 0):
         """Wraps standard output string(s) in the normal
         "Reading ... done" and "Building ... done" strings
         kw['match'] = self.match_re_dotall
         apply(self.run, [], kw)
 
+    def java_ENV(self):
+        """
+        Return a default external environment that uses a local Java SDK
+        in preference to whatever's found in the default PATH.
+        """
+        import SCons.Environment
+        env = SCons.Environment.Environment()
+        java_path = [
+            '/usr/local/j2sdk1.4.2/bin',
+            '/usr/local/j2sdk1.4.1/bin',
+            '/usr/local/j2sdk1.3.1/bin',
+            '/usr/local/j2sdk1.3.0/bin',
+            '/usr/local/j2sdk1.2.2/bin',
+            '/usr/local/j2sdk1.2/bin',
+            '/usr/local/j2sdk1.1.8/bin',
+            '/usr/local/j2sdk1.1.7/bin',
+            '/usr/local/j2sdk1.1.6/bin',
+            '/usr/local/j2sdk1.1.5/bin',
+            '/usr/local/j2sdk1.1.4/bin',
+            '/usr/local/j2sdk1.1.3/bin',
+            '/usr/local/j2sdk1.1.2/bin',
+            '/usr/local/j2sdk1.1.1/bin',
+            env['ENV']['PATH'],
+        ]
+        env['ENV']['PATH'] = string.join(java_path, os.pathsep)
+        return env['ENV']
+
 # In some environments, $AR will generate a warning message to stderr
 # if the library doesn't previously exist and is being created.  One
 # way to fix this is to tell AR to be quiet (sometimes the 'c' flag),

File src/engine/SCons/Tool/javac.py

             java_files = filter(lambda n, js=js:
                                 _my_normcase(n[-len(js):]) == js,
                                 names)
+            # The on-disk entries come back in arbitrary order.  Sort them
+            # so our target and source lists are determinate.
+            java_files.sort()
             mydir = dirnode.Dir(dirname)
             java_paths = map(lambda f, d=mydir: d.File(f), java_files)
             arg.extend(java_paths)

File test/Builder-factories.py

 def collect(env, source, target):
     out = open(str(target[0]), 'wb')
     dir = str(source[0])
-    for f in os.listdir(dir):
+    files = os.listdir(dir)
+    files.sort()
+    for f in files:
         f = os.path.join(dir, f)
         out.write(open(f, 'r').read())
     out.close()

File test/Java/JAR.py

 test.must_match('classes.jar',
                 'cvfm classes.jar foo.mf -C testdir bar.class\n')
 
-if test.detect_tool('javac'):
-    where_javac = test.detect('JAVAC', 'javac')
+ENV = test.java_ENV()
+
+if test.detect_tool('javac', ENV=ENV):
+    where_javac = test.detect('JAVAC', 'javac', ENV=ENV)
 else:
-    import SCons.Environment
-    env = SCons.Environment.Environment()
-    where_javac = env.WhereIs('javac', os.environ['PATH'])
-    if not where_javac:
-        where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
-        if not where_javac:
-            print "Could not find Java javac, skipping test(s)."
-            test.pass_test(1)
+    where_javac = test.where_is('javac')
+if not where_javac:
+    print "Could not find Java javac, skipping test(s)."
+    test.pass_test(1)
 
-if test.detect_tool('jar'):
-    where_jar = test.detect('JAR', 'jar')
+if test.detect_tool('jar', ENV=ENV):
+    where_jar = test.detect('JAR', 'jar', ENV=ENV)
 else:
-    import SCons.Environment
-    env = SCons.Environment.Environment()
-    where_jar = env.WhereIs('jar', os.environ['PATH'])
-    if not where_jar:
-        where_jar = env.WhereIs('jar', '/usr/local/j2sdk1.3.1/bin')
-        if not where_jar:
-            print "Could not find Java jar, skipping test(s)."
-            test.pass_test(1)
+    where_jar = test.where_is('jar')
+if not where_jar:
+    print "Could not find Java jar, skipping test(s)."
+    test.pass_test(1)
 
 
 test.write("wrapper.py", """\

File test/Java/JARFLAGS.py

 
 test.subdir('src')
 
-if test.detect_tool('javac'):
-    where_javac = test.detect('JAVAC', 'javac')
+ENV = test.java_ENV()
+
+if test.detect_tool('javac', ENV=ENV):
+    where_javac = test.detect('JAVAC', 'javac', ENV=ENV)
 else:
-    import SCons.Environment
-    env = SCons.Environment.Environment()
-    where_javac = env.WhereIs('javac', os.environ['PATH'])
-    if not where_javac:
-        where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
-        if not where_javac:
-            print "Could not find Java javac, skipping test(s)."
-            test.pass_test(1)
+    where_javac = test.where_is('javac')
+if not where_javac:
+    print "Could not find Java javac, skipping test(s)."
+    test.pass_test(1)
 
-if test.detect_tool('jar'):
-    where_jar = test.detect('JAR', 'jar')
+if test.detect_tool('jar', ENV=ENV):
+    where_jar = test.detect('JAR', 'jar', ENV=ENV)
 else:
-    import SCons.Environment
-    env = SCons.Environment.Environment()
-    where_jar = env.WhereIs('jar', os.environ['PATH'])
-    if not where_jar:
-        where_jar = env.WhereIs('jar', '/usr/local/j2sdk1.3.1/bin')
-        if not where_jar:
-            print "Could not find Java jar, skipping test(s)."
-            test.pass_test(1)
+    where_javac = test.where_is('jar')
+if not where_jar:
+    print "Could not find Java jar, skipping test(s)."
+    test.pass_test(1)
 
 test.write('SConstruct', """
 env = Environment(tools = ['javac', 'jar'],

File test/Java/JAVAC.py

     test.must_match('test2.class', "test2.JAVA\nline 3\n")
 
 
-if test.detect_tool('javac'):
-    where_javac = test.detect('JAVAC', 'javac')
+
+ENV = test.java_ENV()
+
+if test.detect_tool('javac', ENV=ENV):
+    where_javac = test.detect('JAVAC', 'javac', ENV=ENV)
 else:
-    import SCons.Environment
-    env = SCons.Environment.Environment()
-    where_javac = env.WhereIs('javac', os.environ['PATH'])
-    if not where_javac:
-        where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
-        if not where_javac:
-            print "Could not find Java, skipping test(s)."
-            test.pass_test(1)
-        
+    where_javac = test.where_is('javac')
+if not where_javac:
+    print "Could not find Java javac, skipping test(s)."
+    test.pass_test(1)
+
 
 
 test.write("wrapper.py", """\

File test/Java/JAVACFLAGS.py

 
 test = TestSCons.TestSCons()
 
-if test.detect_tool('javac'):
-    where_javac = test.detect('JAVAC', 'javac')
+ENV = test.java_ENV()
+
+if test.detect_tool('javac', ENV=ENV):
+    where_javac = test.detect('JAVAC', 'javac', ENV=ENV)
 else:
-    import SCons.Environment
-    env = SCons.Environment.Environment()
-    where_javac = env.WhereIs('javac', os.environ['PATH'])
-    if not where_javac:
-        where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin')
-        if not where_javac:
-            print "Could not find Java javac, skipping test(s)."
-            test.pass_test(1)
+    where_javac = test.where_is('javac')
+if not where_javac:
+    print "Could not find Java javac, skipping test(s)."
+    test.pass_test(1)
 
 test.subdir('src')
 

File test/SWIG/SWIG.py

     version = sys.version[:3] # see also sys.prefix documentation
 
     # handle testing on other platforms:
+    ldmodule_prefix = '_'
+
     frameworks = ''
-    ldmodule_prefix = ''
     platform_sys_prefix = sys.prefix
     if sys.platform == 'darwin':
         # OS X has a built-in Python but no static libpython
         # so you should link to it using apple's 'framework' scheme.
         # (see top of file for further explanation)
         frameworks = '-framework Python'
-        ldmodule_prefix = '_'
         platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%s/' % version
     
     test.write("wrapper.py",
 
     test.run(arguments = ldmodule_prefix+'foo' + _dll)
 
-    test.fail_test(os.path.exists(test.workpath('wrapper.out')))
+    test.must_not_exist(test.workpath('wrapper.out'))
 
     test.run(program = python, stdin = """\
 import foo
 
     test.run(arguments = ldmodule_prefix+'bar' + _dll)
 
-    test.fail_test(test.read('wrapper.out') != "wrapper.py\n")
+    test.must_match('wrapper.out', "wrapper.py\n")
 
     test.run(program = python, stdin = """\
 import foo

File test/TAR/TARFLAGS.py

     else: opt_string = opt_string + ' ' + opt
 def process(outfile, name):
     if os.path.isdir(name):
-        for entry in os.listdir(name):
+        entries = os.listdir(name)
+        entries.sort()
+        for entry in entries:
 	    process(outfile, os.path.join(name, entry))
     else:
         outfile.write(open(name, 'rb').read())