# HG changeset patch # User Patrick Mezard # Date 1184430846 -7200 # Node ID c51c9bc4579da6eba4c63c9d45fd8bd69fdf1281 # Parent 6403f948bd6b8c123e19a0fdaf458c93c1f41101 Add hghave utility and run-tests.py support. hghave detects system features like symlinks availability at run-time. Tests can be skipped by starting them with: "$TESTDIR/hghave" symlink || exit 80 The 80 exit status triggers hghave output handling by run-tests.py. Also, tests output can be locally patched on the fly to match reference output. diff --git a/tests/hghave b/tests/hghave 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) + + diff --git a/tests/run-tests.py b/tests/run-tests.py --- 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"): @@ -283,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): @@ -291,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) @@ -332,6 +353,8 @@ def run_one(test): os.chdir(TESTDIR) shutil.rmtree(tmpd, True) + if skipped: + return None return ret == 0