[commit: ghc] wip/testsuite-stdout: testsuite: Introduce TestResult (df0c396)

git at git.haskell.org git at git.haskell.org
Thu Jan 24 19:34:30 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/testsuite-stdout
Link       : http://ghc.haskell.org/trac/ghc/changeset/df0c3966f2e16278fd6fc29360a729a199cefd73/ghc

>---------------------------------------------------------------

commit df0c3966f2e16278fd6fc29360a729a199cefd73
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Thu Jan 24 14:20:11 2019 -0500

    testsuite: Introduce TestResult
    
    Previously we were simply passing around tuples, making things the
    implementation rather difficult to follow and harder to extend.


>---------------------------------------------------------------

df0c3966f2e16278fd6fc29360a729a199cefd73
 testsuite/driver/testglobals.py | 14 ++++++++++++++
 testsuite/driver/testlib.py     | 31 +++++++++++++++++--------------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/testsuite/driver/testglobals.py b/testsuite/driver/testglobals.py
index 0e0240d..b5cee1d 100644
--- a/testsuite/driver/testglobals.py
+++ b/testsuite/driver/testglobals.py
@@ -151,6 +151,19 @@ ghc_env = os.environ.copy()
 # -----------------------------------------------------------------------------
 # Information about the current test run
 
+class TestResult:
+    """
+    A result from the execution of a test. These live in the expected_passes,
+    framework_failures, framework_warnings, unexpected_passes,
+    unexpected_failures, unexpected_stat_failures lists of TestRun.
+    """
+    __slots__ = 'directory', 'testname', 'reason', 'way'
+    def __init__(self, directory, testname, reason, way):
+        self.directory = directory
+        self.testname = testname
+        self.reason = reason
+        self.way = way
+
 class TestRun:
    def __init__(self):
        self.start_time = None
@@ -161,6 +174,7 @@ class TestRun:
        self.n_expected_passes = 0
        self.n_expected_failures = 0
 
+       # type: List[TestResult]
        self.missing_libs = []
        self.framework_failures = []
        self.framework_warnings = []
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py
index c09d02a..8f76378 100644
--- a/testsuite/driver/testlib.py
+++ b/testsuite/driver/testlib.py
@@ -18,7 +18,7 @@ from pathlib import PurePath
 import collections
 import subprocess
 
-from testglobals import config, ghc_env, default_testopts, brokens, t
+from testglobals import config, ghc_env, default_testopts, brokens, t, TestResult
 from testutil import strip_quotes, lndir, link_or_copy_file, passed, failBecause, str_fail, str_pass
 import perf_notes as Perf
 from perf_notes import MetricChange
@@ -928,24 +928,24 @@ def do_test(name, way, func, args, files):
 
     if passFail == 'pass':
         if _expect_pass(way):
-            t.expected_passes.append((directory, name, way))
+            t.expected_passes.append(TestResult(directory, name, way))
             t.n_expected_passes += 1
         else:
             if_verbose(1, '*** unexpected pass for %s' % full_name)
-            t.unexpected_passes.append((directory, name, 'unexpected', way))
+            t.unexpected_passes.append(TestResult(directory, name, 'unexpected', way))
     elif passFail == 'fail':
         if _expect_pass(way):
             reason = result['reason']
             tag = result.get('tag')
             if tag == 'stat':
                 if_verbose(1, '*** unexpected stat test failure for %s' % full_name)
-                t.unexpected_stat_failures.append((directory, name, reason, way))
+                t.unexpected_stat_failures.append(TestResult(directory, name, reason, way))
             else:
                 if_verbose(1, '*** unexpected failure for %s' % full_name)
-                t.unexpected_failures.append((directory, name, reason, way))
+                t.unexpected_failures.append(TestResult(directory, name, reason, way))
         else:
             if opts.expect == 'missing-lib':
-                t.missing_libs.append((directory, name, 'missing-lib', way))
+                t.missing_libs.append(TestResult(directory, name, 'missing-lib', way))
             else:
                 t.n_expected_failures += 1
     else:
@@ -968,14 +968,14 @@ def framework_fail(name, way, reason):
     directory = re.sub('^\\.[/\\\\]', '', opts.testdir)
     full_name = name + '(' + way + ')'
     if_verbose(1, '*** framework failure for %s %s ' % (full_name, reason))
-    t.framework_failures.append((directory, name, way, reason))
+    t.framework_failures.append(TestResult(directory, name, way, reason))
 
 def framework_warn(name, way, reason):
     opts = getTestOpts()
     directory = re.sub('^\\.[/\\\\]', '', opts.testdir)
     full_name = name + '(' + way + ')'
     if_verbose(1, '*** framework warning for %s %s ' % (full_name, reason))
-    t.framework_warnings.append((directory, name, way, reason))
+    t.framework_warnings.append(TestResult(directory, name, way, reason))
 
 def badResult(result):
     try:
@@ -2135,9 +2135,10 @@ def summary(t, file, short=False, color=False):
         file.write('WARNING: Testsuite run was terminated early\n')
 
 def printUnexpectedTests(file, testInfoss):
-    unexpected = set(name for testInfos in testInfoss
-                       for (_, name, _, _) in testInfos
-                       if not name.endswith('.T'))
+    unexpected = set(result.name
+                     for testInfos in testInfoss
+                     for result in testInfos
+                     if not result.name.endswith('.T'))
     if unexpected:
         file.write('Unexpected results from:\n')
         file.write('TEST="' + ' '.join(sorted(unexpected)) + '"\n')
@@ -2145,9 +2146,11 @@ def printUnexpectedTests(file, testInfoss):
 
 def printTestInfosSummary(file, testInfos):
     maxDirLen = max(len(directory) for (directory, _, _, _) in testInfos)
-    for (directory, name, reason, way) in testInfos:
-        directory = directory.ljust(maxDirLen)
-        file.write('   {directory}  {name} [{reason}] ({way})\n'.format(**locals()))
+    for result in testInfos:
+        directory = result.directory.ljust(maxDirLen)
+        file.write('   {directory}  {r.name} [{r.reason}] ({r.way})\n'.format(
+            r = result,
+            directory = directory))
     file.write('\n')
 
 def modify_lines(s, f):



More information about the ghc-commits mailing list