[libgxps] regtest: Print test results when the test has finished



commit c5e09a165dd8c0af217ad8931fd07e3e78a389b6
Author: Carlos Garcia Campos <carlosgc gnome org>
Date:   Tue Jun 23 17:37:38 2015 +0200

    regtest: Print test results when the test has finished
    
    To make sure the result corresponds to the test now that we are using
    multiple threads.

 regtest/Printer.py |   25 +++++++++++++++++++------
 regtest/TestRun.py |   18 +++++++++---------
 2 files changed, 28 insertions(+), 15 deletions(-)
---
diff --git a/regtest/Printer.py b/regtest/Printer.py
index 025f697..1d436cd 100644
--- a/regtest/Printer.py
+++ b/regtest/Printer.py
@@ -33,6 +33,8 @@ class Printer:
         self._rewrite = self._stream.isatty() and not self._verbose
         self._current_line = None
 
+        self._tests = {}
+
         self._lock = RLock()
 
         Printer.__single = self
@@ -81,14 +83,25 @@ class Printer:
             self.stderr.write(self._ensure_new_line(msg))
             self.stderr.flush()
 
-    def print_test_start(self, msg):
-        self.printout(msg)
+    def print_test_start(self, doc_path, n_doc, total_docs):
+        with self._lock:
+            self._tests[doc_path] = n_doc, total_docs
+
+    def print_test_result(self, doc_path, msg):
+        if not self._rewrite:
+            self.print_test_result_ln(doc_path, msg)
+            return
 
-    def print_test_result(self, msg):
-        self.printout_update(msg)
+        with self._lock:
+            n_doc, total_docs = self._tests.pop(doc_path)
+            msg = "Tested '%s' using (%d/%d): %s" % (doc_path, n_doc, total_docs, msg)
+        self.printout(msg)
 
-    def print_test_result_ln(self, msg):
-        self.printout_update(self._ensure_new_line(msg))
+    def print_test_result_ln(self, doc_path, msg):
+        with self._lock:
+            n_doc, total_docs = self._tests.pop(doc_path)
+            msg = "Tested '%s' (%d/%d): %s" % (doc_path, n_doc, total_docs, msg)
+        self.printout_ln(msg)
 
     def print_default(self, msg):
         if self._verbose:
diff --git a/regtest/TestRun.py b/regtest/TestRun.py
index dbf61af..e9d5334 100644
--- a/regtest/TestRun.py
+++ b/regtest/TestRun.py
@@ -68,7 +68,7 @@ class TestRun:
         with self._lock:
             self._n_tests += 1
 
-        self.printer.print_test_start("Testing '%s' (%d/%d): " % (doc_path, n_doc, total_docs))
+        self.printer.print_test_start(doc_path, n_doc, total_docs)
         test_has_md5 = self._test.create_refs(doc_path, test_path)
 
         if self._test.has_stderr(test_path):
@@ -78,25 +78,25 @@ class TestRun:
         if ref_has_md5 and test_has_md5:
             if self._test.compare_checksums(refs_path, test_path, not self.config.keep_results, 
self.config.create_diffs, self.config.update_refs):
                 # FIXME: remove dir if it's empty?
-                self.printer.print_test_result("PASS")
+                self.printer.print_test_result(doc_path, "PASS")
                 with self._lock:
                     self._n_passed += 1
             else:
-                self.printer.print_test_result_ln("FAIL")
+                self.printer.print_test_result_ln(doc_path, "FAIL")
                 with self._lock:
                     self._failed.append(doc_path)
             return
         elif test_has_md5:
             if ref_is_crashed:
-                self.printer.print_test_result_ln("DOES NOT CRASH")
+                self.printer.print_test_result_ln(doc_path, "DOES NOT CRASH")
             elif ref_is_failed:
-                self.printer.print_test_result_ln("DOES NOT FAIL")
+                self.printer.print_test_result_ln(doc_path, "DOES NOT FAIL")
 
             return
 
         test_is_crashed = self._test.is_crashed(test_path)
         if ref_is_crashed and test_is_crashed:
-            self.printer.print_test_result("PASS (Expected crash)")
+            self.printer.print_test_result(doc_path, "PASS (Expected crash)")
             with self._lock:
                 self._n_passed += 1
             return
@@ -104,19 +104,19 @@ class TestRun:
         test_is_failed = self._test.is_failed(test_path)
         if ref_is_failed and test_is_failed:
             # FIXME: compare status errors
-            self.printer.print_test_result("PASS (Expected fail with status error %d)" % (test_is_failed))
+            self.printer.print_test_result(doc_path, "PASS (Expected fail with status error %d)" % 
(test_is_failed))
             with self._lock:
                 self._n_passed += 1
             return
 
         if test_is_crashed:
-            self.printer.print_test_result_ln("CRASH")
+            self.printer.print_test_result_ln(doc_path, "CRASH")
             with self._lock:
                 self._crashed.append(doc_path)
             return
 
         if test_is_failed:
-            self.printer.print_test_result_ln("FAIL (status error %d)" % (test_is_failed))
+            self.printer.print_test_result_ln(doc_path, "FAIL (status error %d)" % (test_is_failed))
             with self._lock:
                 self._failed_status_error(doc_path)
             return


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]