diff options
author | Greg Noel <GregNoel@tigris.org> | 2010-05-26 16:17:09 (GMT) |
---|---|---|
committer | Greg Noel <GregNoel@tigris.org> | 2010-05-26 16:17:09 (GMT) |
commit | 545d2a0a389e9eacdb1d92fbf5f26f2d981029ad (patch) | |
tree | 23f5cda5c621bd7bb657ef9fd1d07e4578d4a934 /QMTest | |
parent | 5c2e07585593ee4994b8e7d79b3d181a56cd7f13 (diff) | |
download | SCons-545d2a0a389e9eacdb1d92fbf5f26f2d981029ad.zip SCons-545d2a0a389e9eacdb1d92fbf5f26f2d981029ad.tar.gz SCons-545d2a0a389e9eacdb1d92fbf5f26f2d981029ad.tar.bz2 |
Start the deprecation cycle for the BuildDir() method and the build_dir
keyword parameter.
Several existing tests were still using BuildDir() or build_dir; they were
converted to use VariantDir() and variant_dir.
New tests were added to validate that the --warn=deprecated-build-dir option
and the SetOption method did the right thing. This led to the discovery that
a commonly-used test pattern provided by the infrastructure gobbled up too
much, causing tests to succeed when they should have failed. Fixing the
pattern led to other tests needing to be fixed.
In the process, it was discovered that the SCONSFLAG environment variable was
not getting correctly reset to its original value. Fixing this also caused
additional tests to misbehave, requiring them to be updated.
And test/Sig.py, which tests the deprecated SCons.Sig module, was moved to
the test/Deprecated directory.
All in all, quite a lot of action for what was supposed to be a simple change.
Diffstat (limited to 'QMTest')
-rw-r--r-- | QMTest/TestCmd.py | 9 | ||||
-rw-r--r-- | QMTest/TestCommon.py | 53 | ||||
-rw-r--r-- | QMTest/TestSCons.py | 139 |
3 files changed, 116 insertions, 85 deletions
diff --git a/QMTest/TestCmd.py b/QMTest/TestCmd.py index 07cf71b..ef41916 100644 --- a/QMTest/TestCmd.py +++ b/QMTest/TestCmd.py @@ -426,12 +426,13 @@ def match_re_dotall(lines = None, res = None): res = "\n".join(res) s = "^" + res + "$" try: + #print 'DEBUG: lines', lines + #print 'DEBUG: dotall', s expr = re.compile(s, re.DOTALL) except re.error, e: msg = "Regular expression error in %s: %s" raise re.error(msg % (repr(s), e[0])) - if expr.match(lines): - return 1 + return expr.match(lines) try: import difflib @@ -1122,8 +1123,10 @@ class TestCmd(object): prepended unless it is enclosed in a [list]. """ cmd = self.command_args(program, interpreter, arguments) - cmd_string = ' '.join(map(self.escape, cmd)) + #print 'DEBUG: SCONSFLAGS:', os.environ.get('SCONSFLAGS') + #print 'DEBUG: command line:', ' '.join(map(self.escape, cmd)) if self.verbose: + cmd_string = ' '.join(map(self.escape, cmd)) sys.stderr.write(cmd_string + "\n") if universal_newlines is None: universal_newlines = self.universal_newlines diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py index 6ee2bd5..1120b55 100644 --- a/QMTest/TestCommon.py +++ b/QMTest/TestCommon.py @@ -206,6 +206,22 @@ elif os.name == 'nt': def _status(self): return self.status +def _options_arguments(options, arguments): + """ + This handles the "options" keyword argument and merges it + with the arguments. + """ + if options: + if arguments is None: + arguments = options + else: + if isinstance(options, str): + options = [options] + if isinstance(arguments, str): + arguments = [arguments] + arguments = ' '.join(options + arguments) + return arguments + class TestCommon(TestCmd): # Additional methods from the Perl Test::Cmd::Common module @@ -477,13 +493,15 @@ class TestCommon(TestCmd): print self.banner('STDERR ') print actual_stderr self.fail_test() - if not expected_stdout is None and not match(actual_stdout, expected_stdout): + if expected_stdout is not None \ + and not match(actual_stdout, expected_stdout): self.diff(expected_stdout, actual_stdout, 'STDOUT ') if actual_stderr: print self.banner('STDERR ') print actual_stderr self.fail_test() - if not expected_stderr is None and not match(actual_stderr, expected_stderr): + if expected_stderr is not None \ + and not match(actual_stderr, expected_stderr): print self.banner('STDOUT ') print actual_stdout self.diff(expected_stderr, actual_stderr, 'STDERR ') @@ -491,28 +509,18 @@ class TestCommon(TestCmd): def start(self, program = None, interpreter = None, + options = None, arguments = None, universal_newlines = None, **kw): """ - Starts a program or script for the test environment. - - This handles the "options" keyword argument and exceptions. + Starts a program or script for the test environment, handling + any exceptions. """ + arguments = _options_arguments(options, arguments) try: - options = kw['options'] - del kw['options'] - except KeyError: - pass - else: - if options: - if arguments is None: - arguments = options - else: - arguments = options + " " + arguments - try: - return TestCmd.start(self, program, interpreter, arguments, universal_newlines, - **kw) + return TestCmd.start(self, program, interpreter, arguments, + universal_newlines, **kw) except KeyboardInterrupt: raise except Exception, e: @@ -557,7 +565,7 @@ class TestCommon(TestCmd): stdout = None, stderr = '', status = 0, **kw): """Runs the program under test, checking that the test succeeded. - The arguments are the same as the base TestCmd.run() method, + The parameters are the same as the base TestCmd.run() method, with the addition of: options Extra options that get appended to the beginning @@ -579,12 +587,7 @@ class TestCommon(TestCmd): not test standard output (stdout = None), and expects that error output is empty (stderr = ""). """ - if options: - if arguments is None: - arguments = options - else: - arguments = options + " " + arguments - kw['arguments'] = arguments + kw['arguments'] = _options_arguments(options, arguments) try: match = kw['match'] del kw['match'] diff --git a/QMTest/TestSCons.py b/QMTest/TestSCons.py index 2122977..c49077b 100644 --- a/QMTest/TestSCons.py +++ b/QMTest/TestSCons.py @@ -133,8 +133,7 @@ else: fortran_lib = gccFortranLibs() - -file_expr = r"""File "[^"]*", line \d+, in .+ +file_expr = r"""File "[^"]*", line \d+, in [^\n]+ """ # re.escape escapes too much. @@ -144,15 +143,6 @@ def re_escape(str): return str - -try: - sys.version_info -except AttributeError: - # Pre-1.6 Python has no sys.version_info - version_string = sys.version.split()[0] - version_ints = list(map(int, version_string.split('.'))) - sys.version_info = tuple(version_ints + ['final', 0]) - def python_version_string(): return sys.version.split()[0] @@ -160,7 +150,7 @@ def python_minor_version_string(): return sys.version[:3] def unsupported_python_version(version=sys.version_info): - return version < (1, 5, 2) + return version < (2, 3, 0) def deprecated_python_version(version=sys.version_info): return version < (2, 4, 0) @@ -177,6 +167,38 @@ else: deprecated_python_expr = "" +def initialize_sconsflags(ignore_python_version): + """ + Add the --warn=no-python-version option to SCONSFLAGS for every + command so test scripts don't have to filter out Python version + deprecation warnings. + Same for --warn=no-visual-c-missing. + """ + save_sconsflags = os.environ.get('SCONSFLAGS') + if save_sconsflags: + sconsflags = [save_sconsflags] + else: + sconsflags = [] + if ignore_python_version and deprecated_python_version(): + sconsflags.append('--warn=no-python-version') + # Provide a way to suppress or provide alternate flags for + # TestSCons purposes by setting TESTSCONS_SCONSFLAGS. + # (The intended use case is to set it to null when running + # timing tests of earlier versions of SCons which don't + # support the --warn=no-visual-c-missing warning.) + visual_c = os.environ.get('TESTSCONS_SCONSFLAGS', + '--warn=no-visual-c-missing') + if visual_c: + sconsflags.append(visual_c) + os.environ['SCONSFLAGS'] = ' '.join(sconsflags) + return save_sconsflags + +def restore_sconsflags(sconsflags): + if sconsflags is None: + del os.environ['SCONSFLAGS'] + else: + os.environ['SCONSFLAGS'] = sconsflags + class TestSCons(TestCommon): """Class for testing SCons. @@ -234,19 +256,10 @@ class TestSCons(TestCommon): # TERM can cause test failures due to control chars in prompts etc. os.environ['TERM'] = 'dumb' - self.ignore_python_version=kw.get('ignore_python_version',1) - if kw.get('ignore_python_version',-1) != -1: + self.ignore_python_version = kw.get('ignore_python_version',1) + if kw.get('ignore_python_version', -1) != -1: del kw['ignore_python_version'] - if self.ignore_python_version and deprecated_python_version(): - sconsflags = os.environ.get('SCONSFLAGS') - if sconsflags: - sconsflags = [sconsflags] - else: - sconsflags = [] - sconsflags = sconsflags + ['--warn=no-python-version'] - os.environ['SCONSFLAGS'] = ' '.join(sconsflags) - TestCommon.__init__(self, **kw) import SCons.Node.FS @@ -336,38 +349,42 @@ class TestSCons(TestCommon): def run(self, *args, **kw): """ - Add the --warn=no-python-version option to SCONSFLAGS every - command so test scripts don't have to filter out Python version - deprecation warnings. - Same for --warn=no-visual-c-missing. + Set up SCONSFLAGS for every command so test scripts don't need + to worry about unexpected warnings in their output. """ - save_sconsflags = os.environ.get('SCONSFLAGS') - if save_sconsflags: - sconsflags = [save_sconsflags] - else: - sconsflags = [] - if self.ignore_python_version and deprecated_python_version(): - sconsflags = sconsflags + ['--warn=no-python-version'] - # Provide a way to suppress or provide alternate flags for - # TestSCons purposes by setting TESTSCONS_SCONSFLAGS. - # (The intended use case is to set it to null when running - # timing tests of earlier versions of SCons which don't - # support the --warn=no-visual-c-missing warning.) - sconsflags = sconsflags + [os.environ.get('TESTSCONS_SCONSFLAGS', - '--warn=no-visual-c-missing')] - os.environ['SCONSFLAGS'] = ' '.join(sconsflags) + sconsflags = initialize_sconsflags(self.ignore_python_version) try: - result = TestCommon.run(self, *args, **kw) + TestCommon.run(self, *args, **kw) finally: - sconsflags = save_sconsflags - return result - - def up_to_date(self, options = None, arguments = None, read_str = "", **kw): + restore_sconsflags(sconsflags) + +# Modifying the options should work and ought to be simpler, but this +# class is used for more than just running 'scons' itself. If there's +# an automated way of determining whether it's running 'scons' or +# something else, this code should be resurected. +# options = kw.get('options') +# if options: +# options = [options] +# else: +# options = [] +# if self.ignore_python_version and deprecated_python_version(): +# options.append('--warn=no-python-version') +# # Provide a way to suppress or provide alternate flags for +# # TestSCons purposes by setting TESTSCONS_SCONSFLAGS. +# # (The intended use case is to set it to null when running +# # timing tests of earlier versions of SCons which don't +# # support the --warn=no-visual-c-missing warning.) +# visual_c = os.environ.get('TESTSCONS_SCONSFLAGS', +# '--warn=no-visual-c-missing') +# if visual_c: +# options.append(visual_c) +# kw['options'] = ' '.join(options) +# TestCommon.run(self, *args, **kw) + + def up_to_date(self, arguments = '.', read_str = "", **kw): s = "" for arg in arguments.split(): s = s + "scons: `%s' is up to date.\n" % arg - if options: - arguments = options + " " + arguments kw['arguments'] = arguments stdout = self.wrap_stdout(read_str = read_str, build_str = s) # Append '.*' so that timing output that comes after the @@ -376,7 +393,7 @@ class TestSCons(TestCommon): kw['match'] = self.match_re_dotall self.run(**kw) - def not_up_to_date(self, options = None, arguments = None, **kw): + def not_up_to_date(self, arguments = '.', **kw): """Asserts that none of the targets listed in arguments is up to date, but does not make any assumptions on other targets. This function is most useful in conjunction with the -n option. @@ -384,8 +401,6 @@ class TestSCons(TestCommon): s = "" for arg in arguments.split(): s = s + "(?!scons: `%s' is up to date.)" % re.escape(arg) - if options: - arguments = options + " " + arguments s = '('+s+'[^\n]*\n)*' kw['arguments'] = arguments stdout = re.escape(self.wrap_stdout(build_str='ARGUMENTSGOHERE')) @@ -419,15 +434,21 @@ class TestSCons(TestCommon): # warning enabled, should get expected output stderr = '\nscons: warning: ' + re_escape(msg) + '\n' + file_expr - self.run(arguments = '--warn=%s .' % warn, stderr=stderr) + self.run(arguments = '--warn=%s .' % warn, + stderr=stderr, + match = match_re_dotall) # no --warn option, should get either nothing or expected output expect = """()|(%s)""" % (stderr) - self.run(arguments = '--warn=no-%s .' % warn, stderr=expect) + self.run(arguments = '--warn=no-%s .' % warn, + stderr=expect, + match = match_re_dotall) # warning disabled, should get either nothing or mandatory message expect = """()|(Can not disable mandataory warning: 'no-%s'\n\n%s)""" % (warn, stderr) - self.run(arguments = '--warn=no-%s .' % warn, stderr=expect) + self.run(arguments = '--warn=no-%s .' % warn, + stderr=expect, + match = match_re_dotall) def diff_substr(self, expect, actual, prelen=20, postlen=40): i = 0 @@ -473,7 +494,6 @@ class TestSCons(TestCommon): s = re.sub(r'/Length \d+ *\n/Filter /FlateDecode\n', r'/Length XXXX\n/Filter /FlateDecode\n', s) - try: import zlib except ImportError: @@ -971,7 +991,12 @@ print py_ver """ if 'stdin' not in kw: kw['stdin'] = True - return TestCommon.start(self, *args, **kw) + sconsflags = initialize_sconsflags(self.ignore_python_version) + try: + p = TestCommon.start(self, *args, **kw) + finally: + restore_sconsflags(sconsflags) + return p def wait_for(self, fname, timeout=10.0, popen=None): """ |