[PATCH 1 of 2] tests: extract feature_fails from hghave and move it to hghave.py

Simon Heimberg simohe at besonet.ch
Mon Nov 5 16:31:10 CST 2012


# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1350334743 -7200
# Branch stable
# Node ID 6048e40535539238a6368bb9e5d4f9aefb79bafe
# Parent  9ed0687df566b27dfcc2af0c5a3aa1f1552b70fd
tests: extract feature_fails from hghave and move it to hghave.py

the new function will be used from more places later

diff -r 9ed0687df566 -r 6048e4053553 tests/hghave
--- a/tests/hghave	Don Okt 25 12:38:34 2012 +0200
+++ b/tests/hghave	Mon Okt 15 22:59:03 2012 +0200
@@ -53,25 +53,9 @@
         failures += 1
 
     for feature in args:
-        negate = feature.startswith('no-')
-        if negate:
-            feature = feature[3:]
-
-        if feature not in checks:
-            error('skipped: unknown feature: ' + feature)
-            continue
-
-        check, desc = checks[feature]
-        try:
-            available = check()
-        except Exception, e:
-            error('hghave check failed: ' + feature)
-            continue
-
-        if not negate and not available:
-            error('skipped: missing feature: ' + desc)
-        elif negate and available:
-            error('skipped: system supports %s' % desc)
+        msg = hghave.feature_fails(feature)
+        if msg:
+            error(msg)
 
     if failures != 0:
         sys.exit(1)
diff -r 9ed0687df566 -r 6048e4053553 tests/hghave.py
--- a/tests/hghave.py	Don Okt 25 12:38:34 2012 +0200
+++ b/tests/hghave.py	Mon Okt 15 22:59:03 2012 +0200
@@ -5,6 +5,27 @@
 
 tempprefix = 'hg-hghave-'
 
+def feature_fails(feature):
+    "returns the reason why a feature fails, None if it passes"
+    negate = feature.startswith('no-')
+    if negate:
+        feature = feature[3:]
+
+    if feature not in checks:
+        return 'skipped: unknown feature: ' + feature
+
+    check, desc = checks[feature]
+    try:
+        available = check()
+    except Exception, e:
+        return 'hghave check failed: ' + feature
+
+    if not negate and not available:
+        return 'skipped: missing feature: ' + desc
+    elif negate and available:
+        return 'skipped: system supports ' + desc
+    return None
+
 def matchoutput(cmd, regexp, ignorestatus=False):
     """Return True if cmd executes successfully and its output
     is matched by the supplied regular expression.


More information about the Mercurial-devel mailing list