diff options
Diffstat (limited to 'Tools/Scripts/webkitpy/test/main.py')
-rw-r--r-- | Tools/Scripts/webkitpy/test/main.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Tools/Scripts/webkitpy/test/main.py b/Tools/Scripts/webkitpy/test/main.py index af3123a01..c5dc39433 100644 --- a/Tools/Scripts/webkitpy/test/main.py +++ b/Tools/Scripts/webkitpy/test/main.py @@ -25,12 +25,14 @@ import logging import optparse +import os import StringIO import sys import traceback import unittest from webkitpy.common.system.filesystem import FileSystem +from webkitpy.common.system import outputcapture from webkitpy.test.test_finder import TestFinder from webkitpy.test.runner import TestRunner @@ -59,6 +61,8 @@ class Tester(object): help='verbose output (specify once for individual test results, twice for debug messages)') parser.add_option('--skip-integrationtests', action='store_true', default=False, help='do not run the integration tests') + parser.add_option('-p', '--pass-through', action='store_true', default=False, + help='be debugger friendly by passing captured output through to the system') parser.epilog = ('[args...] is an optional list of modules, test_classes, or individual tests. ' 'If no args are given, all the tests will be run.') @@ -135,6 +139,10 @@ class Tester(object): self.finder.clean_trees() names = self.finder.find_names(args, self._options.skip_integrationtests, self._options.all) + if not names: + _log.error('No tests to run') + return False + return self._run_tests(names) def _run_tests(self, names): @@ -172,6 +180,8 @@ class Tester(object): test_runner = TestRunner(self.stream, self._options, loader) _log.debug("Running the tests.") + if self._options.pass_through: + outputcapture.OutputCapture.stream_wrapper = _CaptureAndPassThroughStream result = test_runner.run(test_suite) if self._options.coverage: cov.stop() @@ -184,3 +194,32 @@ class Tester(object): traceback.print_exc(file=s) for l in s.buflist: _log.error(' ' + l.rstrip()) + + +class _CaptureAndPassThroughStream(object): + def __init__(self, stream): + self._buffer = StringIO.StringIO() + self._stream = stream + + def write(self, msg): + self._stream.write(msg) + + # Note that we don't want to capture any output generated by the debugger + # because that could cause the results of capture_output() to be invalid. + if not self._message_is_from_pdb(): + self._buffer.write(msg) + + def _message_is_from_pdb(self): + # We will assume that if the pdb module is in the stack then the output + # is being generated by the python debugger (or the user calling something + # from inside the debugger). + import inspect + import pdb + stack = inspect.stack() + return any(frame[1] == pdb.__file__.replace('.pyc', '.py') for frame in stack) + + def flush(self): + self._stream.flush() + + def getvalue(self): + return self._buffer.getvalue() |