selftest: Accept 'testing:' to introduce new tests.
[kai/samba-autobuild/.git] / selftest / subunithelper.py
index 8659f984d87052245f1e57e18d5434e99658071e..7d6896ad3cbbd836bb123986123a82a8b5db8123 100644 (file)
@@ -32,7 +32,7 @@ def parse_results(msg_ops, statistics, fh):
         l = fh.readline()
         if l == "":
             break
-        if l.startswith("test: "):
+        if l.startswith("test: ") or l.startswith("testing: "):
             msg_ops.control_msg(l)
             name = l.split(":", 1)[1].strip()
             msg_ops.start_test(name)
@@ -68,18 +68,36 @@ def parse_results(msg_ops, statistics, fh):
             else:
                 reason = None
             if result in ("success", "successful"):
-                open_tests.pop() #FIXME: Check that popped value == $testname 
-                statistics['TESTS_EXPECTED_OK']+=1
-                msg_ops.end_test(testname, "success", False, reason)
+                try:
+                    open_tests.remove(testname)
+                except KeyError:
+                    statistics['TESTS_ERROR']+=1
+                    msg_ops.end_test(testname, "error", True, 
+                            "Test was never started")
+                else:
+                    statistics['TESTS_EXPECTED_OK']+=1
+                    msg_ops.end_test(testname, "success", False, reason)
             elif result in ("xfail", "knownfail"):
-                open_tests.pop() #FIXME: Check that popped value == $testname
-                statistics['TESTS_EXPECTED_FAIL']+=1
-                msg_ops.end_test(testname, "xfail", False, reason)
-                expected_fail+=1
+                try:
+                    open_tests.remove(testname)
+                except KeyError:
+                    statistics['TESTS_ERROR']+=1
+                    msg_ops.end_test(testname, "error", True, 
+                            "Test was never started")
+                else:
+                    statistics['TESTS_EXPECTED_FAIL']+=1
+                    msg_ops.end_test(testname, "xfail", False, reason)
+                    expected_fail+=1
             elif result in ("failure", "fail"):
-                open_tests.pop() #FIXME: Check that popped value == $testname
-                statistics['TESTS_UNEXPECTED_FAIL']+=1
-                msg_ops.end_test(testname, "failure", True, reason)
+                try:
+                    open_tests.remove(testname)
+                except KeyError:
+                    statistics['TESTS_ERROR']+=1
+                    msg_ops.end_test(testname, "error", True, 
+                            "Test was never started")
+                else:
+                    statistics['TESTS_UNEXPECTED_FAIL']+=1
+                    msg_ops.end_test(testname, "failure", True, reason)
             elif result == "skip":
                 statistics['TESTS_SKIP']+=1
                 # Allow tests to be skipped without prior announcement of test
@@ -89,7 +107,10 @@ def parse_results(msg_ops, statistics, fh):
                 msg_ops.end_test(testname, "skip", False, reason)
             elif result == "error":
                 statistics['TESTS_ERROR']+=1
-                open_tests.pop() #FIXME: Check that popped value == $testname
+                try:
+                    open_tests.remove(testname)
+                except KeyError:
+                    pass
                 msg_ops.end_test(testname, "error", True, reason)
             elif result == "skip-testsuite":
                 msg_ops.skip_testsuite(testname)
@@ -190,6 +211,7 @@ class SubunitOps(object):
 
 
 def read_test_regexes(name):
+    ret = {}
     f = open(name, 'r')
     try:
         for l in f:
@@ -198,15 +220,16 @@ def read_test_regexes(name):
                 continue
             if "#" in l:
                 (regex, reason) = l.split("#", 1)
-                yield (regex.strip(), reason.strip())
+                ret[regex.strip()] = reason.strip()
             else:
-                yield l, None
+                ret[l] = None
     finally:
         f.close()
+    return ret
 
 
 def find_in_list(regexes, fullname):
-    for regex, reason in regexes:
+    for regex, reason in regexes.iteritems():
         if re.match(regex, fullname):
             if reason is None:
                 return ""