[PATCH 2 of 2] run-tests: detect when hghave fails to check for a feature and fail test

Nicolas Dumazet nicdumz at gmail.com
Tue Apr 7 12:35:29 CDT 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1239125644 -32400
# Node ID bfb45f16f9c8302ca1817d4b2af1e63971902c95
# Parent  70061f224d7920b2db2600d418d977f2364fdc22
run-tests: detect when hghave fails to check for a feature and fail test

hghave exitcode != 0 might mean that hghave failed to check for feature
avaibility. Detect those cases, and fail the test, instead of skipping it.

diff --git a/tests/hghave b/tests/hghave
--- a/tests/hghave
+++ b/tests/hghave
@@ -238,6 +238,12 @@
             continue
 
         check, desc = checks[feature]
+        try:
+            available = check()
+        except Exception, e:
+            error('hghave check failed: ' + feature)
+            continue
+
         if not negate and not check():
             error('skipped: missing feature: ' + desc)
         elif negate and check():
diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -36,6 +36,7 @@
 # reserved exit code to skip test (used by hghave)
 SKIPPED_STATUS = 80
 SKIPPED_PREFIX = 'skipped: '
+FAILED_PREFIX  = 'hghave check failed: '
 
 required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
 
@@ -129,16 +130,22 @@
         lines.append(text[i:n+1])
         i = n + 1
 
-def extract_missing_features(lines):
-    '''Extract missing/unknown features log lines as a list'''
+def parse_hghave_output(lines):
+    '''Parse hghave log lines.
+    Return tuple of lists (missing, failed):
+      * the missing/unknown features
+      * the features for which existence check failed'''
     missing = []
+    failed = []
     for line in lines:
-        if not line.startswith(SKIPPED_PREFIX):
-            continue
-        line = line.splitlines()[0]
-        missing.append(line[len(SKIPPED_PREFIX):])
+        if line.startswith(SKIPPED_PREFIX):
+            line = line.splitlines()[0]
+            missing.append(line[len(SKIPPED_PREFIX):])
+        elif line.startswith(FAILED_PREFIX):
+            line = line.splitlines()[0]
+            failed.append(line[len(FAILED_PREFIX):])
 
-    return missing
+    return missing, failed
 
 def show_diff(expected, output):
     for line in difflib.unified_diff(expected, output,
@@ -408,10 +415,14 @@
         ref_out = []
     if skipped:
         mark = 's'
-        missing = extract_missing_features(out)
+        missing, failed = parse_hghave_output(out)
         if not missing:
             missing = ['irrelevant']
-        skip(missing[-1])
+        if failed:
+            fail("hghave failed checking for %s" % failed[-1])
+            skipped = False
+        else:
+            skip(missing[-1])
     elif out != ref_out:
         mark = '!'
         if ret:


More information about the Mercurial-devel mailing list