tests/run-tests.py
author Christian Ebert <blacktrash@gmx.net>
Fri, 10 Jul 2009 01:33:01 +0200
branchstable
changeset 612 0d75562ef3b0
parent 562 b1aa7b64890b
child 670 80d0ed025a02
permissions -rwxr-xr-x
(stable) merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     1
#!/usr/bin/env python
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     2
#
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     3
# run-tests.py - Run a set of tests on Mercurial
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     4
#
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     5
# Copyright 2006 Matt Mackall <mpm@selenic.com>
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     6
#
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms of the
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     8
# GNU General Public License version 2, incorporated herein by reference.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     9
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    10
# Modifying this script is tricky because it has many modes:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    11
#   - serial (default) vs parallel (-jN, N > 1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    12
#   - no coverage (default) vs coverage (-c, -C, -s)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    13
#   - temp install (default) vs specific hg script (--with-hg, --local)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    14
#   - tests are a mix of shell scripts and Python scripts
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    15
#
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    16
# If you change this script, it is recommended that you ensure you
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    17
# haven't broken it by running it in various modes with a representative
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    18
# sample of test scripts.  For example:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    19
# 
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    20
#  1) serial, no coverage, temp install:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    21
#      ./run-tests.py test-s*
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    22
#  2) serial, no coverage, local hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    23
#      ./run-tests.py --local test-s*
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    24
#  3) serial, coverage, temp install:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    25
#      ./run-tests.py -c test-s*
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    26
#  4) serial, coverage, local hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    27
#      ./run-tests.py -c --local test-s*      # unsupported
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    28
#  5) parallel, no coverage, temp install:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    29
#      ./run-tests.py -j2 test-s*
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    30
#  6) parallel, no coverage, local hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    31
#      ./run-tests.py -j2 --local test-s*
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    32
#  7) parallel, coverage, temp install:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    33
#      ./run-tests.py -j2 -c test-s*          # currently broken
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    34
#  8) parallel, coverage, local install
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    35
#      ./run-tests.py -j2 -c --local test-s*  # unsupported (and broken)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    36
#
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    37
# (You could use any subset of the tests: test-s* happens to match
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    38
# enough that it's worth doing parallel runs, few enough that it
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    39
# completes fairly quickly, includes both shell and Python scripts, and
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    40
# includes some scripts that run daemon processes.)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    41
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    42
import difflib
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    43
import errno
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    44
import optparse
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    45
import os
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    46
import subprocess
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    47
import shutil
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    48
import signal
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    49
import sys
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    50
import tempfile
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    51
import time
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    52
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    53
closefds = os.name == 'posix'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    54
def Popen4(cmd, bufsize=-1):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    55
    p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    56
                         close_fds=closefds,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    57
                         stdin=subprocess.PIPE, stdout=subprocess.PIPE,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    58
                         stderr=subprocess.STDOUT)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    59
    p.fromchild = p.stdout
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    60
    p.tochild = p.stdin
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    61
    p.childerr = p.stderr
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    62
    return p
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    63
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    64
# reserved exit code to skip test (used by hghave)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    65
SKIPPED_STATUS = 80
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    66
SKIPPED_PREFIX = 'skipped: '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    67
FAILED_PREFIX  = 'hghave check failed: '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    68
PYTHON = sys.executable
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    69
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    70
requiredtools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    71
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    72
defaults = {
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    73
    'jobs': ('HGTEST_JOBS', 1),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    74
    'timeout': ('HGTEST_TIMEOUT', 180),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    75
    'port': ('HGTEST_PORT', 20059),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    76
}
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    77
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    78
def parseargs():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    79
    parser = optparse.OptionParser("%prog [options] [tests]")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    80
    parser.add_option("-C", "--annotate", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    81
        help="output files annotated with coverage")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    82
    parser.add_option("--child", type="int",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    83
        help="run as child process, summary to given fd")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    84
    parser.add_option("-c", "--cover", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    85
        help="print a test coverage report")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    86
    parser.add_option("-f", "--first", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    87
        help="exit on the first test failure")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    88
    parser.add_option("-i", "--interactive", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    89
        help="prompt to accept changed output")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    90
    parser.add_option("-j", "--jobs", type="int",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    91
        help="number of jobs to run in parallel"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    92
             " (default: $%s or %d)" % defaults['jobs'])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    93
    parser.add_option("--keep-tmpdir", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    94
        help="keep temporary directory after running tests"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    95
             " (best used with --tmpdir)")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    96
    parser.add_option("-R", "--restart", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    97
        help="restart at last error")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    98
    parser.add_option("-p", "--port", type="int",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    99
        help="port on which servers should listen"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   100
             " (default: $%s or %d)" % defaults['port'])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   101
    parser.add_option("-r", "--retest", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   102
        help="retest failed tests")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   103
    parser.add_option("-s", "--cover_stdlib", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   104
        help="print a test coverage report inc. standard libraries")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   105
    parser.add_option("-t", "--timeout", type="int",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   106
        help="kill errant tests after TIMEOUT seconds"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   107
             " (default: $%s or %d)" % defaults['timeout'])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   108
    parser.add_option("--tmpdir", type="string",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   109
        help="run tests in the given temporary directory")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   110
    parser.add_option("-v", "--verbose", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   111
        help="output verbose messages")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   112
    parser.add_option("-n", "--nodiff", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   113
        help="skip showing test changes")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   114
    parser.add_option("--with-hg", type="string",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   115
        metavar="HG",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   116
        help="test using specified hg script rather than a "
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   117
             "temporary installation")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   118
    parser.add_option("--local", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   119
        help="shortcut for --with-hg=<testdir>/../hg")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   120
    parser.add_option("--pure", action="store_true",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   121
        help="use pure Python code instead of C extensions")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   122
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   123
    for option, default in defaults.items():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   124
        defaults[option] = int(os.environ.get(*default))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   125
    parser.set_defaults(**defaults)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   126
    (options, args) = parser.parse_args()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   127
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   128
    if options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   129
        if not (os.path.isfile(options.with_hg) and
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   130
                os.access(options.with_hg, os.X_OK)):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   131
            parser.error('--with-hg must specify an executable hg script')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   132
        if not os.path.basename(options.with_hg) == 'hg':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   133
            sys.stderr.write('warning: --with-hg should specify an hg script')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   134
    if options.local:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   135
        testdir = os.path.dirname(os.path.realpath(sys.argv[0]))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   136
        hgbin = os.path.join(os.path.dirname(testdir), 'hg')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   137
        if not os.access(hgbin, os.X_OK):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   138
            parser.error('--local specified, but %r not found or not executable'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   139
                         % hgbin)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   140
        options.with_hg = hgbin
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   141
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   142
    options.anycoverage = (options.cover or
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   143
                           options.cover_stdlib or
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   144
                           options.annotate)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   145
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   146
    if options.anycoverage and options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   147
        # I'm not sure if this is a fundamental limitation or just a
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   148
        # bug.  But I don't want to waste people's time and energy doing
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   149
        # test runs that don't give the results they want.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   150
        parser.error("sorry, coverage options do not work when --with-hg "
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   151
                     "or --local specified")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   152
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   153
    global vlog
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   154
    if options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   155
        if options.jobs > 1 or options.child is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   156
            pid = "[%d]" % os.getpid()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   157
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   158
            pid = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   159
        def vlog(*msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   160
            if pid:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   161
                print pid,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   162
            for m in msg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   163
                print m,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   164
            print
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   165
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   166
        vlog = lambda *msg: None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   167
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   168
    if options.jobs < 1:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   169
        print >> sys.stderr, 'ERROR: -j/--jobs must be positive'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   170
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   171
    if options.interactive and options.jobs > 1:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   172
        print '(--interactive overrides --jobs)'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   173
        options.jobs = 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   174
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   175
    return (options, args)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   176
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   177
def rename(src, dst):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   178
    """Like os.rename(), trade atomicity and opened files friendliness
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   179
    for existing destination support.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   180
    """
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   181
    shutil.copy(src, dst)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   182
    os.remove(src)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   183
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   184
def splitnewlines(text):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   185
    '''like str.splitlines, but only split on newlines.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   186
    keep line endings.'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   187
    i = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   188
    lines = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   189
    while True:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   190
        n = text.find('\n', i)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   191
        if n == -1:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   192
            last = text[i:]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   193
            if last:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   194
                lines.append(last)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   195
            return lines
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   196
        lines.append(text[i:n+1])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   197
        i = n + 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   198
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   199
def parsehghaveoutput(lines):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   200
    '''Parse hghave log lines.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   201
    Return tuple of lists (missing, failed):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   202
      * the missing/unknown features
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   203
      * the features for which existence check failed'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   204
    missing = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   205
    failed = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   206
    for line in lines:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   207
        if line.startswith(SKIPPED_PREFIX):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   208
            line = line.splitlines()[0]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   209
            missing.append(line[len(SKIPPED_PREFIX):])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   210
        elif line.startswith(FAILED_PREFIX):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   211
            line = line.splitlines()[0]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   212
            failed.append(line[len(FAILED_PREFIX):])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   213
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   214
    return missing, failed
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   215
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   216
def showdiff(expected, output):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   217
    for line in difflib.unified_diff(expected, output,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   218
            "Expected output", "Test output"):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   219
        sys.stdout.write(line)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   220
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   221
def findprogram(program):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   222
    """Search PATH for a executable program"""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   223
    for p in os.environ.get('PATH', os.defpath).split(os.pathsep):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   224
        name = os.path.join(p, program)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   225
        if os.access(name, os.X_OK):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   226
            return name
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   227
    return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   228
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   229
def checktools():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   230
    # Before we go any further, check for pre-requisite tools
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   231
    # stuff from coreutils (cat, rm, etc) are not tested
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   232
    for p in requiredtools:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   233
        if os.name == 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   234
            p += '.exe'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   235
        found = findprogram(p)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   236
        if found:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   237
            vlog("# Found prerequisite", p, "at", found)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   238
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   239
            print "WARNING: Did not find prerequisite tool: "+p
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   240
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   241
def cleanup(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   242
    if not options.keep_tmpdir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   243
        vlog("# Cleaning up HGTMP", HGTMP)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   244
        shutil.rmtree(HGTMP, True)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   245
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   246
def usecorrectpython():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   247
    # some tests run python interpreter. they must use same
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   248
    # interpreter we use or bad things will happen.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   249
    exedir, exename = os.path.split(sys.executable)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   250
    if exename == 'python':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   251
        path = findprogram('python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   252
        if os.path.dirname(path) == exedir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   253
            return
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   254
    vlog('# Making python executable in test path use correct Python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   255
    mypython = os.path.join(BINDIR, 'python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   256
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   257
        os.symlink(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   258
    except AttributeError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   259
        # windows fallback
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   260
        shutil.copyfile(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   261
        shutil.copymode(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   262
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   263
def installhg(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   264
    vlog("# Performing temporary installation of HG")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   265
    installerrs = os.path.join("tests", "install.err")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   266
    pure = options.pure and "--pure" or ""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   267
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   268
    # Run installer in hg root
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   269
    os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '..'))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   270
    cmd = ('%s setup.py %s clean --all'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   271
           ' install --force --prefix="%s" --install-lib="%s"'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   272
           ' --install-scripts="%s" >%s 2>&1'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   273
           % (sys.executable, pure, INST, PYTHONDIR, BINDIR, installerrs))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   274
    vlog("# Running", cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   275
    if os.system(cmd) == 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   276
        if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   277
            os.remove(installerrs)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   278
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   279
        f = open(installerrs)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   280
        for line in f:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   281
            print line,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   282
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   283
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   284
    os.chdir(TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   285
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   286
    usecorrectpython()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   287
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   288
    vlog("# Installing dummy diffstat")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   289
    f = open(os.path.join(BINDIR, 'diffstat'), 'w')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   290
    f.write('#!' + sys.executable + '\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   291
            'import sys\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   292
            'files = 0\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   293
            'for line in sys.stdin:\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   294
            '    if line.startswith("diff "):\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   295
            '        files += 1\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   296
            'sys.stdout.write("files patched: %d\\n" % files)\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   297
    f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   298
    os.chmod(os.path.join(BINDIR, 'diffstat'), 0700)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   299
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   300
    if options.anycoverage:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   301
        vlog("# Installing coverage wrapper")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   302
        os.environ['COVERAGE_FILE'] = COVERAGE_FILE
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   303
        if os.path.exists(COVERAGE_FILE):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   304
            os.unlink(COVERAGE_FILE)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   305
        # Create a wrapper script to invoke hg via coverage.py
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   306
        os.rename(os.path.join(BINDIR, "hg"), os.path.join(BINDIR, "_hg.py"))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   307
        f = open(os.path.join(BINDIR, 'hg'), 'w')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   308
        f.write('#!' + sys.executable + '\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   309
        f.write('import sys, os; os.execv(sys.executable, [sys.executable, '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   310
                '"%s", "-x", "-p", "%s"] + sys.argv[1:])\n' %
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   311
                (os.path.join(TESTDIR, 'coverage.py'),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   312
                 os.path.join(BINDIR, '_hg.py')))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   313
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   314
        os.chmod(os.path.join(BINDIR, 'hg'), 0700)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   315
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   316
def outputcoverage(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   317
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   318
    vlog('# Producing coverage report')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   319
    os.chdir(PYTHONDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   320
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   321
    def covrun(*args):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   322
        start = sys.executable, os.path.join(TESTDIR, 'coverage.py')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   323
        cmd = '"%s" "%s" %s' % (start[0], start[1], ' '.join(args))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   324
        vlog('# Running: %s' % cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   325
        os.system(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   326
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   327
    omit = [BINDIR, TESTDIR, PYTHONDIR]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   328
    if not options.cover_stdlib:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   329
        # Exclude as system paths (ignoring empty strings seen on win)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   330
        omit += [x for x in sys.path if x != '']
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   331
    omit = ','.join(omit)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   332
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   333
    covrun('-c') # combine from parallel processes
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   334
    for fn in os.listdir(TESTDIR):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   335
        if fn.startswith('.coverage.'):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   336
            os.unlink(os.path.join(TESTDIR, fn))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   337
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   338
    covrun('-i', '-r', '"--omit=%s"' % omit) # report
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   339
    if options.annotate:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   340
        adir = os.path.join(TESTDIR, 'annotated')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   341
        if not os.path.isdir(adir):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   342
            os.mkdir(adir)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   343
        covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   344
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   345
class Timeout(Exception):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   346
    pass
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   347
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   348
def alarmed(signum, frame):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   349
    raise Timeout
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   350
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   351
def run(cmd, options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   352
    """Run command in a sub-process, capturing the output (stdout and stderr).
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   353
    Return the exist code, and output."""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   354
    # TODO: Use subprocess.Popen if we're running on Python 2.4
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   355
    if os.name == 'nt' or sys.platform.startswith('java'):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   356
        tochild, fromchild = os.popen4(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   357
        tochild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   358
        output = fromchild.read()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   359
        ret = fromchild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   360
        if ret == None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   361
            ret = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   362
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   363
        proc = Popen4(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   364
        try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   365
            output = ''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   366
            proc.tochild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   367
            output = proc.fromchild.read()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   368
            ret = proc.wait()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   369
            if os.WIFEXITED(ret):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   370
                ret = os.WEXITSTATUS(ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   371
        except Timeout:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   372
            vlog('# Process %d timed out - killing it' % proc.pid)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   373
            os.kill(proc.pid, signal.SIGTERM)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   374
            ret = proc.wait()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   375
            if ret == 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   376
                ret = signal.SIGTERM << 8
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   377
            output += ("\n### Abort: timeout after %d seconds.\n"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   378
                       % options.timeout)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   379
    return ret, splitnewlines(output)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   380
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   381
def runone(options, test, skips, fails):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   382
    '''tristate output:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   383
    None -> skipped
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   384
    True -> passed
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   385
    False -> failed'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   386
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   387
    def skip(msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   388
        if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   389
            skips.append((test, msg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   390
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   391
            print "\nSkipping %s: %s" % (test, msg)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   392
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   393
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   394
    def fail(msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   395
        fails.append((test, msg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   396
        if not options.nodiff:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   397
            print "\nERROR: %s %s" % (test, msg)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   398
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   399
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   400
    vlog("# Test", test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   401
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   402
    # create a fresh hgrc
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   403
    hgrc = file(HGRCPATH, 'w+')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   404
    hgrc.write('[ui]\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   405
    hgrc.write('slash = True\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   406
    hgrc.write('[defaults]\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   407
    hgrc.write('backout = -d "0 0"\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   408
    hgrc.write('commit = -d "0 0"\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   409
    hgrc.write('tag = -d "0 0"\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   410
    hgrc.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   411
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   412
    err = os.path.join(TESTDIR, test+".err")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   413
    ref = os.path.join(TESTDIR, test+".out")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   414
    testpath = os.path.join(TESTDIR, test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   415
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   416
    if os.path.exists(err):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   417
        os.remove(err)       # Remove any previous output files
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   418
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   419
    # Make a tmp subdirectory to work in
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   420
    tmpd = os.path.join(HGTMP, test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   421
    os.mkdir(tmpd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   422
    os.chdir(tmpd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   423
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   424
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   425
        tf = open(testpath)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   426
        firstline = tf.readline().rstrip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   427
        tf.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   428
    except:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   429
        firstline = ''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   430
    lctest = test.lower()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   431
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   432
    if lctest.endswith('.py') or firstline == '#!/usr/bin/env python':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   433
        cmd = '%s "%s"' % (PYTHON, testpath)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   434
    elif lctest.endswith('.bat'):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   435
        # do not run batch scripts on non-windows
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   436
        if os.name != 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   437
            return skip("batch script")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   438
        # To reliably get the error code from batch files on WinXP,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   439
        # the "cmd /c call" prefix is needed. Grrr
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   440
        cmd = 'cmd /c call "%s"' % testpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   441
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   442
        # do not run shell scripts on windows
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   443
        if os.name == 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   444
            return skip("shell script")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   445
        # do not try to run non-executable programs
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   446
        if not os.path.exists(testpath):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   447
            return fail("does not exist")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   448
        elif not os.access(testpath, os.X_OK):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   449
            return skip("not executable")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   450
        cmd = '"%s"' % testpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   451
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   452
    if options.timeout > 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   453
        signal.alarm(options.timeout)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   454
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   455
    vlog("# Running", cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   456
    ret, out = run(cmd, options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   457
    vlog("# Ret was:", ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   458
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   459
    if options.timeout > 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   460
        signal.alarm(0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   461
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   462
    mark = '.'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   463
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   464
    skipped = (ret == SKIPPED_STATUS)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   465
    # If reference output file exists, check test output against it
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   466
    if os.path.exists(ref):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   467
        f = open(ref, "r")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   468
        refout = splitnewlines(f.read())
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   469
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   470
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   471
        refout = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   472
    if skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   473
        mark = 's'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   474
        missing, failed = parsehghaveoutput(out)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   475
        if not missing:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   476
            missing = ['irrelevant']
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   477
        if failed:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   478
            fail("hghave failed checking for %s" % failed[-1])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   479
            skipped = False
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   480
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   481
            skip(missing[-1])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   482
    elif out != refout:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   483
        mark = '!'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   484
        if ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   485
            fail("output changed and returned error code %d" % ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   486
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   487
            fail("output changed")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   488
        if not options.nodiff:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   489
            showdiff(refout, out)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   490
        ret = 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   491
    elif ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   492
        mark = '!'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   493
        fail("returned error code %d" % ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   494
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   495
    if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   496
        sys.stdout.write(mark)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   497
        sys.stdout.flush()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   498
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   499
    if ret != 0 and not skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   500
        # Save errors to a file for diagnosis
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   501
        f = open(err, "wb")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   502
        for line in out:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   503
            f.write(line)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   504
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   505
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   506
    # Kill off any leftover daemon processes
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   507
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   508
        fp = file(DAEMON_PIDS)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   509
        for line in fp:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   510
            try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   511
                pid = int(line)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   512
            except ValueError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   513
                continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   514
            try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   515
                os.kill(pid, 0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   516
                vlog('# Killing daemon process %d' % pid)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   517
                os.kill(pid, signal.SIGTERM)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   518
                time.sleep(0.25)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   519
                os.kill(pid, 0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   520
                vlog('# Daemon process %d is stuck - really killing it' % pid)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   521
                os.kill(pid, signal.SIGKILL)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   522
            except OSError, err:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   523
                if err.errno != errno.ESRCH:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   524
                    raise
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   525
        fp.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   526
        os.unlink(DAEMON_PIDS)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   527
    except IOError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   528
        pass
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   529
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   530
    os.chdir(TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   531
    if not options.keep_tmpdir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   532
        shutil.rmtree(tmpd, True)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   533
    if skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   534
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   535
    return ret == 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   536
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   537
_hgpath = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   538
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   539
def _gethgpath():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   540
    """Return the path to the mercurial package that is actually found by
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   541
    the current Python interpreter."""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   542
    global _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   543
    if _hgpath is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   544
        return _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   545
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   546
    cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   547
    pipe = os.popen(cmd % PYTHON)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   548
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   549
        _hgpath = pipe.read().strip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   550
    finally:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   551
        pipe.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   552
    return _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   553
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   554
def _checkhglib(verb):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   555
    """Ensure that the 'mercurial' package imported by python is
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   556
    the one we expect it to be.  If not, print a warning to stderr."""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   557
    expecthg = os.path.join(PYTHONDIR, 'mercurial')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   558
    actualhg = _gethgpath()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   559
    if actualhg != expecthg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   560
        sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   561
                         '         (expected %s)\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   562
                         % (verb, actualhg, expecthg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   563
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   564
def runchildren(options, tests):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   565
    if INST:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   566
        installhg(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   567
        _checkhglib("Testing")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   568
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   569
    optcopy = dict(options.__dict__)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   570
    optcopy['jobs'] = 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   571
    if optcopy['with_hg'] is None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   572
        optcopy['with_hg'] = os.path.join(BINDIR, "hg")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   573
    opts = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   574
    for opt, value in optcopy.iteritems():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   575
        name = '--' + opt.replace('_', '-')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   576
        if value is True:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   577
            opts.append(name)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   578
        elif value is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   579
            opts.append(name + '=' + str(value))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   580
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   581
    tests.reverse()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   582
    jobs = [[] for j in xrange(options.jobs)]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   583
    while tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   584
        for job in jobs:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   585
            if not tests: break
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   586
            job.append(tests.pop())
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   587
    fps = {}
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   588
    for j, job in enumerate(jobs):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   589
        if not job:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   590
            continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   591
        rfd, wfd = os.pipe()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   592
        childopts = ['--child=%d' % wfd, '--port=%d' % (options.port + j * 3)]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   593
        cmdline = [PYTHON, sys.argv[0]] + opts + childopts + job
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   594
        vlog(' '.join(cmdline))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   595
        fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'r')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   596
        os.close(wfd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   597
    failures = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   598
    tested, skipped, failed = 0, 0, 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   599
    skips = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   600
    fails = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   601
    while fps:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   602
        pid, status = os.wait()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   603
        fp = fps.pop(pid)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   604
        l = fp.read().splitlines()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   605
        test, skip, fail = map(int, l[:3])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   606
        split = -fail or len(l)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   607
        for s in l[3:split]:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   608
            skips.append(s.split(" ", 1))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   609
        for s in l[split:]:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   610
            fails.append(s.split(" ", 1))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   611
        tested += test
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   612
        skipped += skip
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   613
        failed += fail
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   614
        vlog('pid %d exited, status %d' % (pid, status))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   615
        failures |= status
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   616
    print
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   617
    for s in skips:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   618
        print "Skipped %s: %s" % (s[0], s[1])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   619
    for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   620
        print "Failed %s: %s" % (s[0], s[1])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   621
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   622
    _checkhglib("Tested")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   623
    print "# Ran %d tests, %d skipped, %d failed." % (
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   624
        tested, skipped, failed)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   625
    sys.exit(failures != 0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   626
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   627
def runtests(options, tests):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   628
    global DAEMON_PIDS, HGRCPATH
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   629
    DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   630
    HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   631
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   632
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   633
        if INST:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   634
            installhg(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   635
            _checkhglib("Testing")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   636
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   637
        if options.timeout > 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   638
            try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   639
                signal.signal(signal.SIGALRM, alarmed)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   640
                vlog('# Running each test with %d second timeout' %
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   641
                     options.timeout)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   642
            except AttributeError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   643
                print 'WARNING: cannot run tests with timeouts'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   644
                options.timeout = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   645
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   646
        tested = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   647
        failed = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   648
        skipped = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   649
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   650
        if options.restart:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   651
            orig = list(tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   652
            while tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   653
                if os.path.exists(tests[0] + ".err"):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   654
                    break
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   655
                tests.pop(0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   656
            if not tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   657
                print "running all tests"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   658
                tests = orig
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   659
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   660
        skips = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   661
        fails = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   662
        for test in tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   663
            if options.retest and not os.path.exists(test + ".err"):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   664
                skipped += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   665
                continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   666
            ret = runone(options, test, skips, fails)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   667
            if ret is None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   668
                skipped += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   669
            elif not ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   670
                if options.interactive:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   671
                    print "Accept this change? [n] ",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   672
                    answer = sys.stdin.readline().strip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   673
                    if answer.lower() in "y yes".split():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   674
                        rename(test + ".err", test + ".out")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   675
                        tested += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   676
                        fails.pop()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   677
                        continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   678
                failed += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   679
                if options.first:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   680
                    break
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   681
            tested += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   682
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   683
        if options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   684
            fp = os.fdopen(options.child, 'w')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   685
            fp.write('%d\n%d\n%d\n' % (tested, skipped, failed))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   686
            for s in skips:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   687
                fp.write("%s %s\n" % s)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   688
            for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   689
                fp.write("%s %s\n" % s)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   690
            fp.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   691
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   692
            print
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   693
            for s in skips:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   694
                print "Skipped %s: %s" % s
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   695
            for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   696
                print "Failed %s: %s" % s
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   697
            _checkhglib("Tested")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   698
            print "# Ran %d tests, %d skipped, %d failed." % (
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   699
                tested, skipped, failed)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   700
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   701
        if options.anycoverage:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   702
            outputcoverage(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   703
    except KeyboardInterrupt:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   704
        failed = True
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   705
        print "\ninterrupted!"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   706
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   707
    if failed:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   708
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   709
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   710
def main():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   711
    (options, args) = parseargs()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   712
    if not options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   713
        os.umask(022)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   714
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   715
        checktools()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   716
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   717
    # Reset some environment variables to well-known values so that
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   718
    # the tests produce repeatable output.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   719
    os.environ['LANG'] = os.environ['LC_ALL'] = 'C'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   720
    os.environ['TZ'] = 'GMT'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   721
    os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   722
    os.environ['CDPATH'] = ''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   723
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   724
    global TESTDIR, HGTMP, INST, BINDIR, PYTHONDIR, COVERAGE_FILE
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   725
    TESTDIR = os.environ["TESTDIR"] = os.getcwd()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   726
    HGTMP = os.environ['HGTMP'] = os.path.realpath(tempfile.mkdtemp('', 'hgtests.',
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   727
                                                   options.tmpdir))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   728
    DAEMON_PIDS = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   729
    HGRCPATH = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   730
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   731
    os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   732
    os.environ["HGMERGE"] = "internal:merge"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   733
    os.environ["HGUSER"]   = "test"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   734
    os.environ["HGENCODING"] = "ascii"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   735
    os.environ["HGENCODINGMODE"] = "strict"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   736
    os.environ["HGPORT"] = str(options.port)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   737
    os.environ["HGPORT1"] = str(options.port + 1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   738
    os.environ["HGPORT2"] = str(options.port + 2)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   739
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   740
    if options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   741
        INST = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   742
        BINDIR = os.path.dirname(os.path.realpath(options.with_hg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   743
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   744
        # This looks redundant with how Python initializes sys.path from
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   745
        # the location of the script being executed.  Needed because the
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   746
        # "hg" specified by --with-hg is not the only Python script
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   747
        # executed in the test suite that needs to import 'mercurial'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   748
        # ... which means it's not really redundant at all.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   749
        PYTHONDIR = BINDIR
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   750
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   751
        INST = os.path.join(HGTMP, "install")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   752
        BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   753
        PYTHONDIR = os.path.join(INST, "lib", "python")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   754
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   755
    os.environ["BINDIR"] = BINDIR
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   756
    os.environ["PYTHON"] = PYTHON
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   757
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   758
    if not options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   759
        path = [BINDIR] + os.environ["PATH"].split(os.pathsep)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   760
        os.environ["PATH"] = os.pathsep.join(path)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   761
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   762
        # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   763
        # can run .../tests/run-tests.py test-foo where test-foo
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   764
        # adds an extension to HGRC
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   765
        pypath = [PYTHONDIR, TESTDIR]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   766
        # We have to augment PYTHONPATH, rather than simply replacing
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   767
        # it, in case external libraries are only available via current
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   768
        # PYTHONPATH.  (In particular, the Subversion bindings on OS X
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   769
        # are in /opt/subversion.)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   770
        oldpypath = os.environ.get('PYTHONPATH')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   771
        if oldpypath:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   772
            pypath.append(oldpypath)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   773
        os.environ['PYTHONPATH'] = os.pathsep.join(pypath)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   774
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   775
    COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   776
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   777
    if len(args) == 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   778
        args = os.listdir(".")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   779
        args.sort()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   780
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   781
    tests = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   782
    for test in args:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   783
        if (test.startswith("test-") and '~' not in test and
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   784
            ('.' not in test or test.endswith('.py') or
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   785
             test.endswith('.bat'))):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   786
            tests.append(test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   787
    if not tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   788
        print "# Ran 0 tests, 0 skipped, 0 failed."
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   789
        return
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   790
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   791
    vlog("# Using TESTDIR", TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   792
    vlog("# Using HGTMP", HGTMP)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   793
    vlog("# Using PATH", os.environ["PATH"])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   794
    vlog("# Using PYTHONPATH", os.environ["PYTHONPATH"])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   795
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   796
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   797
        if len(tests) > 1 and options.jobs > 1:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   798
            runchildren(options, tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   799
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   800
            runtests(options, tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   801
    finally:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   802
        cleanup(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   803
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   804
main()