changeset 4883:2a01e03ffacd

Merge with crew-stable.
author Patrick Mezard <pmezard@gmail.com>
date Sun, 15 Jul 2007 14:57:20 +0200
parents da8640113b5a (current diff) 25d753efd48e (diff)
children d77accdd236e
files tests/hghave
diffstat 5 files changed, 89 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
new file mode 100755
--- /dev/null
+++ b/tests/hghave
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+"""Test the running system for features availability. Exit with zero
+if all features are there, non-zero otherwise.
+"""
+import optparse
+import os
+import sys
+
+def has_symlink():
+    return hasattr(os, "symlink")
+
+checks = {
+    "symlink": (has_symlink, "symbolic links"),
+}
+
+def list_features():
+    for name, feature in checks.iteritems():
+        desc = feature[1]
+        print name + ':', desc
+
+parser = optparse.OptionParser("%prog [options] [features]")
+parser.add_option("--list-features", action="store_true",
+                  help="list available features")
+parser.add_option("-q", "--quiet", action="store_true",
+                  help="check features silently")
+
+if __name__ == '__main__':
+    options, args = parser.parse_args()
+    if options.list_features:
+        list_features()
+        sys.exit(0)
+        
+    quiet = options.quiet
+
+    failures = 0
+
+    def error(msg):
+        global failures
+        if not quiet:
+            sys.stderr.write(msg + '\n')
+        failures += 1
+    
+    for feature in args:
+        if feature not in checks:
+            error('hghave: unknown feature: ' + feature)
+            continue
+        
+        check, desc = checks[feature]       
+        if not check():
+            error('hghave: missing feature: ' + desc)
+
+    if failures != 0:
+        sys.exit(1)
+
+    
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -19,6 +19,9 @@ import sys
 import tempfile
 import time
 
+# hghave reserved exit code to skip test
+SKIPPED_STATUS = 80
+
 required_tools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
 
 parser = optparse.OptionParser("%prog [options] [tests]")
@@ -68,6 +71,17 @@ def splitnewlines(text):
         lines.append(text[i:n+1])
         i = n + 1
 
+def extract_missing_features(lines):
+    '''Extract missing/unknown features log lines as a list'''
+    missing = []
+    for line in lines:
+        if not line.startswith('hghave: '):
+            continue
+        line = line.splitlines()[0]
+        missing.append(line[8:])
+
+    return missing
+
 def show_diff(expected, output):
     for line in difflib.unified_diff(expected, output,
             "Expected output", "Test output"):
@@ -205,6 +219,8 @@ def run(cmd):
             proc.tochild.close()
             output = proc.fromchild.read()
             ret = proc.wait()
+            if os.WIFEXITED(ret):
+                ret = os.WEXITSTATUS(ret)
         except Timeout:
             vlog('# Process %d timed out - killing it' % proc.pid)
             os.kill(proc.pid, signal.SIGTERM)
@@ -281,6 +297,7 @@ def run_one(test):
     if options.timeout > 0:
         signal.alarm(0)
 
+    skipped = (ret == SKIPPED_STATUS)
     diffret = 0
     # If reference output file exists, check test output against it
     if os.path.exists(ref):
@@ -289,16 +306,22 @@ def run_one(test):
         f.close()
     else:
         ref_out = []
-    if out != ref_out:
+    if not skipped and out != ref_out:
         diffret = 1
         print "\nERROR: %s output changed" % (test)
         show_diff(ref_out, out)
-    if ret:
+    if skipped:
+        missing = extract_missing_features(out)
+        if not missing:
+            missing = ['irrelevant']
+        print '\nSkipping %s: %s' % (test, missing[-1])
+    elif ret:
         print "\nERROR: %s failed with error code %d" % (test, ret)
     elif diffret:
         ret = diffret
 
-    if ret != 0: # Save errors to a file for diagnosis
+    if ret != 0 and not skipped: 
+        # Save errors to a file for diagnosis
         f = open(err, "wb")
         for line in out:
             f.write(line)
@@ -330,6 +353,8 @@ def run_one(test):
 
     os.chdir(TESTDIR)
     shutil.rmtree(tmpd, True)
+    if skipped:
+        return None
     return ret == 0
 
 
--- a/tests/test-symlink-basic
+++ b/tests/test-symlink-basic
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+"$TESTDIR/hghave" symlink || exit 80
+
 cleanpath()
 {
     sed -e "s:/.*\(/test-symlink-basic/.*\):...\1:"
--- a/tests/test-symlink-root
+++ b/tests/test-symlink-root
@@ -1,5 +1,7 @@
 #!/bin/sh
 
+"$TESTDIR/hghave" symlink || exit 80
+
 hg init a
 ln -s a link
 cd a
--- a/tests/test-symlinks
+++ b/tests/test-symlinks
@@ -2,6 +2,8 @@
 #Test bug regarding symlinks that showed up in hg 0.7
 #Author: Matthew Elder <sseses@gmail.com>
 
+"$TESTDIR/hghave" symlink || exit 80
+
 #make and initialize repo
 hg init test; cd test;