view tests/hghave @ 5149:ad6b97132b81

merge: fix a copy detection bug (issue672) When merging rev1 and rev2, we want to search for copies that happened in rev1 but not in rev2 and vice-versa. We were starting the search at rev1/rev2 and then going back, stopping as soon as we reached the revno of the ancestor, but that can miss some cases (see the new test-issue672). Now we calculate the revisions that are ancestors of rev1 or rev2 (but not both) and make sure the search doesn't stop too early. Simplified test provided by mpm, based on a test case provided by Edward Lee.
author Alexis S. L. Carvalho <alexis@cecm.usp.br>
date Sun, 12 Aug 2007 12:15:10 -0300
parents 6e040f6c2c9c
children 105d4cf7ec24
line wrap: on
line source

#!/usr/bin/env python
"""Test the running system for features availability. Exit with zero
if all features are there, non-zero otherwise. If a feature name is
prefixed with "no-", the absence of feature is tested.
"""
import optparse
import os
import sys
import tempfile

tempprefix = 'hg-hghave-'

def has_symlink():
    return hasattr(os, "symlink")

def has_fifo():
    return hasattr(os, "mkfifo")

def has_executablebit():
    fd, path = tempfile.mkstemp(prefix=tempprefix)
    os.close(fd)
    try:
        s = os.lstat(path).st_mode
        os.chmod(path, s | 0100)
        return (os.lstat(path).st_mode & 0100 != 0)
    finally:
        os.remove(path)

def has_eol_in_paths():
    try:
        fd, path = tempfile.mkstemp(prefix=tempprefix, suffix='\n\r')
        os.close(fd)
        os.remove(path)
        return True
    except:
        return False

checks = {
    "symlink": (has_symlink, "symbolic links"),
    "fifo": (has_fifo, "named pipes"),
    "execbit": (has_executablebit, "executable bit"),
    "eol-in-paths": (has_eol_in_paths, "end-of-lines in paths"),
}

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:
        negate = feature.startswith('no-')
        if negate:
            feature = feature[3:]

        if feature not in checks:
            error('hghave: unknown feature: ' + feature)
            continue

        check, desc = checks[feature]
        if not negate and not check():
            error('hghave: missing feature: ' + desc)
        elif negate and check():
            error('hghave: system supports %s' % desc)

    if failures != 0:
        sys.exit(1)