diff options
author | Steven Knight <knight@baldmt.com> | 2002-05-07 21:52:15 (GMT) |
---|---|---|
committer | Steven Knight <knight@baldmt.com> | 2002-05-07 21:52:15 (GMT) |
commit | e9512cbcf8dc872b474f9e7990b60bb9db1924f3 (patch) | |
tree | 0ba2d9c0f3368e88cd306a6f988657979dd1cccf | |
parent | a2ceacbe77db1b308f26454477ae3b1f1139eac8 (diff) | |
download | SCons-e9512cbcf8dc872b474f9e7990b60bb9db1924f3.zip SCons-e9512cbcf8dc872b474f9e7990b60bb9db1924f3.tar.gz SCons-e9512cbcf8dc872b474f9e7990b60bb9db1924f3.tar.bz2 |
Add a better PATH search to the tests.
-rw-r--r-- | etc/TestCmd.py | 103 | ||||
-rw-r--r-- | test/DVIPDF.py | 12 | ||||
-rw-r--r-- | test/DVIPDFFLAGS.py | 12 | ||||
-rw-r--r-- | test/DVIPS.py | 12 | ||||
-rw-r--r-- | test/DVIPSFLAGS.py | 12 | ||||
-rw-r--r-- | test/F77.py | 7 | ||||
-rw-r--r-- | test/F77FLAGS.py | 7 | ||||
-rw-r--r-- | test/LATEX.py | 12 | ||||
-rw-r--r-- | test/LATEXFLAGS.py | 12 | ||||
-rw-r--r-- | test/LEX.py | 7 | ||||
-rw-r--r-- | test/LEXFLAGS.py | 7 | ||||
-rw-r--r-- | test/PDFLATEX.py | 12 | ||||
-rw-r--r-- | test/PDFLATEXFLAGS.py | 12 | ||||
-rw-r--r-- | test/PDFTEX.py | 12 | ||||
-rw-r--r-- | test/PDFTEXFLAGS.py | 12 | ||||
-rw-r--r-- | test/RANLIB.py | 9 | ||||
-rw-r--r-- | test/RANLIBFLAGS.py | 9 | ||||
-rw-r--r-- | test/SHF77.py | 7 | ||||
-rw-r--r-- | test/SHF77FLAGS.py | 7 | ||||
-rw-r--r-- | test/TEX.py | 12 | ||||
-rw-r--r-- | test/TEXFLAGS.py | 12 | ||||
-rw-r--r-- | test/YACC.py | 7 | ||||
-rw-r--r-- | test/YACCFLAGS.py | 7 |
23 files changed, 107 insertions, 214 deletions
diff --git a/etc/TestCmd.py b/etc/TestCmd.py index 2d1c932..06e324f 100644 --- a/etc/TestCmd.py +++ b/etc/TestCmd.py @@ -41,23 +41,36 @@ or incorrect permissions). # AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -from string import join, split - __author__ = "Steven Knight <knight@baldmt.com>" __revision__ = "TestCmd.py 0.D002 2001/08/31 14:56:12 software" __version__ = "0.02" -from types import * - import os import os.path import popen2 import re import shutil import stat +import string import sys import tempfile import traceback +import types + +try: + from UserString import UserString +except ImportError: + class UserString: + pass + +if hasattr(types, 'UnicodeType'): + def is_String(e): + return type(e) is types.StringType \ + or type(e) is types.UnicodeType \ + or isinstance(e, UserString) +else: + def is_String(e): + return type(e) is types.StringType or isinstance(e, UserString) tempfile.template = 'testcmd.' @@ -161,10 +174,10 @@ def pass_test(self = None, condition = 1, function = None): def match_exact(lines = None, matches = None): """ """ - if not type(lines) is ListType: - lines = split(lines, "\n") - if not type(matches) is ListType: - matches = split(matches, "\n") + if not type(lines) is types.ListType: + lines = string.split(lines, "\n") + if not type(matches) is types.ListType: + matches = string.split(matches, "\n") if len(lines) != len(matches): return for i in range(len(lines)): @@ -175,10 +188,10 @@ def match_exact(lines = None, matches = None): def match_re(lines = None, res = None): """ """ - if not type(lines) is ListType: - lines = split(lines, "\n") - if not type(res) is ListType: - res = split(res, "\n") + if not type(lines) is types.ListType: + lines = string.split(lines, "\n") + if not type(res) is types.ListType: + res = string.split(res, "\n") if len(lines) != len(res): return for i in range(len(lines)): @@ -190,12 +203,53 @@ def match_re_dotall(lines = None, res = None): """ """ if not type(lines) is type(""): - lines = join(lines, "\n") + lines = string.join(lines, "\n") if not type(res) is type(""): - res = join(res, "\n") + res = string.join(res, "\n") if re.compile("^" + res + "$", re.DOTALL).match(lines): return 1 +if sys.platform == 'win32': + + def where_is(file, path=None, pathext=None): + if path is None: + path = os.environ['PATH'] + if is_String(path): + path = string.split(path, os.pathsep) + if pathext is None: + pathext = os.environ['PATHEXT'] + if is_String(pathext): + pathext = string.split(pathext, os.pathsep) + for ext in pathext: + if string.lower(ext) == string.lower(file[-len(ext):]): + pathext = [''] + break + for dir in path: + f = os.path.join(dir, file) + for ext in pathext: + fext = f + ext + if os.path.isfile(fext): + return fext + return None + +else: + + def where_is(file, path=None, pathext=None): + if path is None: + path = os.environ['PATH'] + if is_String(path): + path = string.split(path, os.pathsep) + for dir in path: + f = os.path.join(dir, file) + if os.path.isfile(f): + try: + st = os.stat(f) + except: + continue + if stat.S_IMODE(st[stat.ST_MODE]) & 0111: + return f + return None + class TestCmd: """Class TestCmd """ @@ -372,7 +426,7 @@ class TestCmd: be specified; it must begin with an 'r'. The default is 'rb' (binary read). """ - if type(file) is ListType: + if type(file) is types.ListType: file = apply(os.path.join, tuple(file)) if not os.path.isabs(file): file = os.path.join(self.workdir, file) @@ -416,7 +470,7 @@ class TestCmd: except AttributeError: (tochild, fromchild, childerr) = os.popen3(cmd) if stdin: - if type(stdin) is ListType: + if type(stdin) is types.ListType: for line in stdin: tochild.write(line) else: @@ -432,7 +486,7 @@ class TestCmd: raise else: if stdin: - if type(stdin) is ListType: + if type(stdin) is types.ListType: for line in stdin: p.tochild.write(line) else: @@ -487,7 +541,7 @@ class TestCmd: for sub in subdirs: if sub is None: continue - if type(sub) is ListType: + if type(sub) is types.ListType: sub = apply(os.path.join, tuple(sub)) new = os.path.join(self.workdir, sub) try: @@ -505,7 +559,7 @@ class TestCmd: assumed to be under the temporary working directory unless it is an absolute path name. """ - if type(file) is ListType: + if type(file) is types.ListType: file = apply(os.path.join, tuple(file)) if not os.path.isabs(file): file = os.path.join(self.workdir, file) @@ -517,6 +571,15 @@ class TestCmd: """ self.verbose = verbose + def where_is(self, file, path=None, pathext=None): + """Find an executable file. + """ + if type(file) is types.ListType: + file = apply(os.path.join, tuple(file)) + if not os.path.isabs(file): + file = where_is(file, path, pathext) + return file + def workdir_set(self, path): """Creates a temporary working directory with the specified path name. If the path is a null string (''), a unique @@ -590,7 +653,7 @@ class TestCmd: exist. The I/O mode for the file may be specified; it must begin with a 'w'. The default is 'wb' (binary write). """ - if type(file) is ListType: + if type(file) is types.ListType: file = apply(os.path.join, tuple(file)) if not os.path.isabs(file): file = os.path.join(self.workdir, file) diff --git a/test/DVIPDF.py b/test/DVIPDF.py index 69108e1..d22cfd8 100644 --- a/test/DVIPDF.py +++ b/test/DVIPDF.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -104,12 +99,7 @@ test.fail_test(test.read('test2.pdf') != "This is a .tex test.\n") -dvipdf = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvipdf' + _exe) - if os.path.exists(l): - dvipdf = l - break +dvipdf = test.where_is('dvipdf') if dvipdf: diff --git a/test/DVIPDFFLAGS.py b/test/DVIPDFFLAGS.py index 6d65318..e6f9146 100644 --- a/test/DVIPDFFLAGS.py +++ b/test/DVIPDFFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -110,12 +105,7 @@ test.fail_test(test.read('test2.pdf') != " -x\nThis is a .tex test.\n") -dvipdf = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvipdf' + _exe) - if os.path.exists(l): - dvipdf = l - break +dvipdf = test.where_is('dvipdf') if dvipdf: diff --git a/test/DVIPS.py b/test/DVIPS.py index 91900be..b3bdebc 100644 --- a/test/DVIPS.py +++ b/test/DVIPS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -119,12 +114,7 @@ test.fail_test(test.read('test4.ps') != "This is a .latex test.\n") -dvips = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvips' + _exe) - if os.path.exists(l): - dvips = l - break +dvips = test.where_is('dvips') if dvips: diff --git a/test/DVIPSFLAGS.py b/test/DVIPSFLAGS.py index e043e75..664b532 100644 --- a/test/DVIPSFLAGS.py +++ b/test/DVIPSFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -126,12 +121,7 @@ test.fail_test(test.read('test4.ps') != " -x\nThis is a .latex test.\n") -dvips = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvips' + _exe) - if os.path.exists(l): - dvips = l - break +dvips = test.where_is('dvips') if dvips: diff --git a/test/F77.py b/test/F77.py index 964682d..6548498 100644 --- a/test/F77.py +++ b/test/F77.py @@ -167,12 +167,7 @@ test.fail_test(test.read('test6' + _exe) != "This is a .FPP file.\n") -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/F77FLAGS.py b/test/F77FLAGS.py index 5241e7b..e4d1f8c 100644 --- a/test/F77FLAGS.py +++ b/test/F77FLAGS.py @@ -179,12 +179,7 @@ test.fail_test(test.read('test6' + _exe) != "%s\nThis is a .FPP file.\n" % o) -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/LATEX.py b/test/LATEX.py index 9ac74f5..440054d 100644 --- a/test/LATEX.py +++ b/test/LATEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -75,12 +70,7 @@ test.fail_test(test.read('test2.dvi') != "This is a .latex test.\n") -latex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'latex' + _exe) - if os.path.exists(l): - latex = l - break +latex = test.where_is('latex') if latex: diff --git a/test/LATEXFLAGS.py b/test/LATEXFLAGS.py index c366c8a..5ad4d95 100644 --- a/test/LATEXFLAGS.py +++ b/test/LATEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -81,12 +76,7 @@ test.fail_test(test.read('test2.dvi') != " -t\nThis is a .latex test.\n") -latex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'latex' + _exe) - if os.path.exists(l): - latex = l - break +latex = test.where_is('latex') if latex: diff --git a/test/LEX.py b/test/LEX.py index 59a887d..88c0a2d 100644 --- a/test/LEX.py +++ b/test/LEX.py @@ -74,12 +74,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = "mylex.py\naaa.l\n") -lex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'lex' + _exe) - if os.path.exists(l): - lex = l - break +lex = test.where_is('lex') if lex: diff --git a/test/LEXFLAGS.py b/test/LEXFLAGS.py index b415495..e807774 100644 --- a/test/LEXFLAGS.py +++ b/test/LEXFLAGS.py @@ -77,12 +77,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = " -x -t\naaa.l\n") -lex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'lex' + _exe) - if os.path.exists(l): - lex = l - break +lex = test.where_is('lex') if lex: diff --git a/test/PDFLATEX.py b/test/PDFLATEX.py index a64f158..f665d0f 100644 --- a/test/PDFLATEX.py +++ b/test/PDFLATEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -75,12 +70,7 @@ test.fail_test(not os.path.exists(test.workpath('test2.pdf'))) -pdflatex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'pdflatex' + _exe) - if os.path.exists(l): - pdflatex = l - break +pdflatex = test.where_is('pdflatex') if pdflatex: diff --git a/test/PDFLATEXFLAGS.py b/test/PDFLATEXFLAGS.py index 1693b56..6ddd41a 100644 --- a/test/PDFLATEXFLAGS.py +++ b/test/PDFLATEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -81,12 +76,7 @@ test.fail_test(not os.path.exists(test.workpath('test2.pdf'))) -pdflatex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'pdflatex' + _exe) - if os.path.exists(l): - pdflatex = l - break +pdflatex = test.where_is('pdflatex') if pdflatex: diff --git a/test/PDFTEX.py b/test/PDFTEX.py index 41024c4..4fe5341 100644 --- a/test/PDFTEX.py +++ b/test/PDFTEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -68,12 +63,7 @@ test.fail_test(not os.path.exists(test.workpath('test.pdf'))) -pdftex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'pdftex' + _exe) - if os.path.exists(t): - pdftex = t - break +pdftex = test.where_is('pdftex') if pdftex: diff --git a/test/PDFTEXFLAGS.py b/test/PDFTEXFLAGS.py index 59d67be..aa5cc9f 100644 --- a/test/PDFTEXFLAGS.py +++ b/test/PDFTEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -74,12 +69,7 @@ test.fail_test(not os.path.exists(test.workpath('test.pdf'))) -pdftex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'pdftex' + _exe) - if os.path.exists(t): - pdftex = t - break +pdftex = test.where_is('pdftex') if pdftex: diff --git a/test/RANLIB.py b/test/RANLIB.py index 12ae212..14708e0 100644 --- a/test/RANLIB.py +++ b/test/RANLIB.py @@ -37,15 +37,10 @@ if sys.platform == 'win32': else: _exe = '' -ranlib = None -for dir in string.split(os.environ['PATH'], os.pathsep): - r = os.path.join(dir, 'ranlib' + _exe) - if os.path.exists(r): - ranlib = r - break - test = TestSCons.TestSCons() +ranlib = test.where_is('ranlib') + test.no_result(not ranlib) test.write("wrapper.py", diff --git a/test/RANLIBFLAGS.py b/test/RANLIBFLAGS.py index 752f685..b3e9451 100644 --- a/test/RANLIBFLAGS.py +++ b/test/RANLIBFLAGS.py @@ -36,15 +36,10 @@ if sys.platform == 'win32': else: _exe = '' -ranlib = None -for dir in string.split(os.environ['PATH'], os.pathsep): - r = os.path.join(dir, 'ranlib' + _exe) - if os.path.exists(r): - ranlib = r - break - test = TestSCons.TestSCons() +ranlib = test.where_is('ranlib') + test.no_result(not ranlib) test.write("wrapper.py", diff --git a/test/SHF77.py b/test/SHF77.py index 43c6485..cffd94d 100644 --- a/test/SHF77.py +++ b/test/SHF77.py @@ -169,12 +169,7 @@ test.fail_test(test.read('test6' + _exe) != "This is a .FPP file.\n") -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/SHF77FLAGS.py b/test/SHF77FLAGS.py index cb1e6f6..231fea2 100644 --- a/test/SHF77FLAGS.py +++ b/test/SHF77FLAGS.py @@ -185,12 +185,7 @@ test.fail_test(test.read('test6' + _exe) != "%s\nThis is a .FPP file.\n" % o) -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/TEX.py b/test/TEX.py index 9b442c9..bcdd62e 100644 --- a/test/TEX.py +++ b/test/TEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -68,12 +63,7 @@ test.fail_test(test.read('test.dvi') != "This is a test.\n") -tex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'tex' + _exe) - if os.path.exists(t): - tex = t - break +tex = test.where_is('tex') if tex: diff --git a/test/TEXFLAGS.py b/test/TEXFLAGS.py index 4cc08d3..1f7121f 100644 --- a/test/TEXFLAGS.py +++ b/test/TEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -74,12 +69,7 @@ test.fail_test(test.read('test.dvi') != " -x\nThis is a test.\n") -tex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'tex' + _exe) - if os.path.exists(t): - tex = t - break +tex = test.where_is('tex') if tex: diff --git a/test/YACC.py b/test/YACC.py index 8fea904..2868085 100644 --- a/test/YACC.py +++ b/test/YACC.py @@ -80,12 +80,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = "myyacc.py\naaa.y\n") -yacc = None -for dir in string.split(os.environ['PATH'], os.pathsep): - y = os.path.join(dir, 'yacc' + _exe) - if os.path.exists(y): - yacc = y - break +yacc = test.where_is('yacc') if yacc: diff --git a/test/YACCFLAGS.py b/test/YACCFLAGS.py index 10c29ca..288696b 100644 --- a/test/YACCFLAGS.py +++ b/test/YACCFLAGS.py @@ -80,12 +80,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = " -x\naaa.y\n") -yacc = None -for dir in string.split(os.environ['PATH'], os.pathsep): - y = os.path.join(dir, 'yacc' + _exe) - if os.path.exists(y): - yacc = y - break +yacc = test.where_is('yacc') if yacc: |