summaryrefslogtreecommitdiff
path: root/tools/test_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test_util.py')
-rw-r--r--tools/test_util.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/tools/test_util.py b/tools/test_util.py
index cec181ac0..6540f37aa 100644
--- a/tools/test_util.py
+++ b/tools/test_util.py
@@ -3,12 +3,13 @@
# Runs the full test suite.
# Usage: ./tools/test.py out/Debug
import argparse
+import contextlib
import os
import sys
import unittest
from util import (enable_ansi_colors, build_path, RESET, FG_RED, FG_GREEN,
- executable_suffix, run, run_output, rmtree, tests_path)
+ executable_suffix, rmtree, tests_path)
class DenoTestCase(unittest.TestCase):
@@ -22,6 +23,14 @@ class DenoTestCase(unittest.TestCase):
# overload the test result class
class ColorTextTestResult(unittest.TextTestResult):
+ @contextlib.contextmanager
+ def color(self, code):
+ self.stream.write(code)
+ try:
+ yield
+ finally:
+ self.stream.write(RESET)
+
def getDescription(self, test):
name = str(test)
if name.startswith("test_"):
@@ -29,25 +38,16 @@ class ColorTextTestResult(unittest.TextTestResult):
return name
def addSuccess(self, test):
- if self.showAll:
- self.stream.write(FG_GREEN)
- super(ColorTextTestResult, self).addSuccess(test)
- if self.showAll:
- self.stream.write(RESET)
+ with self.color(FG_GREEN):
+ super(ColorTextTestResult, self).addSuccess(test)
def addError(self, test, err):
- if self.showAll:
- self.stream.write(FG_RED)
- super(ColorTextTestResult, self).addError(test, err)
- if self.showAll:
- self.stream.write(RESET)
+ with self.color(FG_RED):
+ super(ColorTextTestResult, self).addError(test, err)
def addFailure(self, test, err):
- if self.showAll:
- self.stream.write(FG_RED)
- super(ColorTextTestResult, self).addFailure(test, err)
- if self.showAll:
- self.stream.write(RESET)
+ with self.color(FG_RED):
+ super(ColorTextTestResult, self).addFailure(test, err)
class ColorTextTestRunner(unittest.TextTestRunner):
@@ -133,7 +133,7 @@ def run_tests(test_cases=None):
suite = unittest.TestSuite(filtered_tests)
runner = ColorTextTestRunner(
- verbosity=args.verbose + 1, failfast=args.failfast)
+ verbosity=args.verbose + 2, failfast=args.failfast)
result = runner.run(suite)
if not result.wasSuccessful():