tests/run-tests.py
author Ry4an Brase <ry4an-hg@ry4an.org>
Wed, 14 Apr 2010 00:24:47 -0500
branchstable
changeset 725 212432db2043
parent 724 211fa4b9803d
child 726 f7050b041b5f
permissions -rwxr-xr-x
Fix --blacklist when --jobs > 1 in run_tests.py. The options parsing logic replaces the options.blacklist initial value, a list of filenames, with a dict of test names to filenames. When runchildren rebuilds the command line to launch child processes the dict is flattened and provided as a malformed argument when a filename is expected. Fix is to remove the blacklist option from child invocations since the filtering is handled in the parent anyway. [ original upstream message ]
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
674
0efa9d6ac11f Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 670
diff changeset
     8
# GNU General Public License version 2 or any later version.
562
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:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
    19
#
562
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
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
    34
#  8) parallel, coverage, local install:
562
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)
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
    36
#  9) parallel, custom tmp dir:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
    37
#      ./run-tests.py -j2 --tmpdir /tmp/myhgtests
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    38
#
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    39
# (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
    40
# 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
    41
# 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
    42
# 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
    43
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
    44
from distutils import version
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    45
import difflib
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    46
import errno
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    47
import optparse
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    48
import os
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
    49
import signal
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    50
import subprocess
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    51
import shutil
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    52
import signal
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    53
import sys
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    54
import tempfile
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    55
import time
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    56
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    57
closefds = os.name == 'posix'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    58
def Popen4(cmd, bufsize=-1):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    59
    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
    60
                         close_fds=closefds,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    61
                         stdin=subprocess.PIPE, stdout=subprocess.PIPE,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    62
                         stderr=subprocess.STDOUT)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    63
    p.fromchild = p.stdout
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    64
    p.tochild = p.stdin
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    65
    p.childerr = p.stderr
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    66
    return p
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    67
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    68
# 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
    69
SKIPPED_STATUS = 80
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    70
SKIPPED_PREFIX = 'skipped: '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    71
FAILED_PREFIX  = 'hghave check failed: '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    72
PYTHON = sys.executable
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
    73
IMPL_PATH = 'PYTHONPATH'
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
    74
if 'java' in sys.platform:
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
    75
    IMPL_PATH = 'JYTHONPATH'
562
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
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
    78
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    79
defaults = {
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    80
    'jobs': ('HGTEST_JOBS', 1),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    81
    'timeout': ('HGTEST_TIMEOUT', 180),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    82
    'port': ('HGTEST_PORT', 20059),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    83
}
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    84
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    85
def parseargs():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    86
    parser = optparse.OptionParser("%prog [options] [tests]")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    87
    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
    88
        help="output files annotated with coverage")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    89
    parser.add_option("--child", type="int",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    90
        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
    91
    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
    92
        help="print a test coverage report")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    93
    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
    94
        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
    95
    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
    96
        help="prompt to accept changed output")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    97
    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
    98
        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
    99
             " (default: $%s or %d)" % defaults['jobs'])
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   100
    parser.add_option("-k", "--keywords",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   101
        help="run tests matching keywords")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   102
    parser.add_option("--keep-tmpdir", action="store_true",
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   103
        help="keep temporary directory after running tests")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   104
    parser.add_option("--tmpdir", type="string",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   105
        help="run tests in the given temporary directory"
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   106
             " (implies --keep-tmpdir)")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   107
    parser.add_option("-d", "--debug", action="store_true",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   108
        help="debug mode: write output of test scripts to console"
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   109
             " rather than capturing and diff'ing it (disables timeout)")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   110
    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
   111
        help="restart at last error")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   112
    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
   113
        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
   114
             " (default: $%s or %d)" % defaults['port'])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   115
    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
   116
        help="retest failed tests")
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   117
    parser.add_option("-S", "--noskips", action="store_true",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   118
        help="don't report skip tests verbosely")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   119
    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
   120
        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
   121
             " (default: $%s or %d)" % defaults['timeout'])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   122
    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
   123
        help="output verbose messages")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   124
    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
   125
        help="skip showing test changes")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   126
    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
   127
        metavar="HG",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   128
        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
   129
             "temporary installation")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   130
    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
   131
        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
   132
    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
   133
        help="use pure Python code instead of C extensions")
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   134
    parser.add_option("-3", "--py3k-warnings", action="store_true",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   135
        help="enable Py3k warnings on Python 2.6+")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   136
    parser.add_option("--inotify", action="store_true",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   137
        help="enable inotify extension when running tests")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   138
    parser.add_option("--blacklist", action="append",
681
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   139
        help="skip tests listed in the specified blacklist file")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   140
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   141
    for option, default in defaults.items():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   142
        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
   143
    parser.set_defaults(**defaults)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   144
    (options, args) = parser.parse_args()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   145
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   146
    # jython is always pure
722
85da4926cf39 run-tests: force to test pure on pypy as well
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 721
diff changeset
   147
    if 'java' in sys.platform or '__pypy__' in sys.modules:
721
1dbc96b10ebd Fix run-tests.py -jX after 2ed667a9dfcb
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 720
diff changeset
   148
        options.pure = True
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   149
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   150
    if options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   151
        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
   152
                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
   153
            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
   154
        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
   155
            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
   156
    if options.local:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   157
        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
   158
        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
   159
        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
   160
            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
   161
                         % hgbin)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   162
        options.with_hg = hgbin
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   163
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   164
    options.anycoverage = options.cover or options.annotate
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   165
    if options.anycoverage:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   166
        try:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   167
            import coverage
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   168
            covver = version.StrictVersion(coverage.__version__).version
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   169
            if covver < (3, 3):
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   170
                parser.error('coverage options require coverage 3.3 or later')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   171
        except ImportError:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   172
            parser.error('coverage options now require the coverage package')
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   173
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   174
    if options.anycoverage and options.local:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   175
        # this needs some path mangling somewhere, I guess
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   176
        parser.error("sorry, coverage options do not work when --local "
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   177
                     "is specified")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   178
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   179
    global vlog
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   180
    if options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   181
        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
   182
            pid = "[%d]" % os.getpid()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   183
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   184
            pid = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   185
        def vlog(*msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   186
            if pid:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   187
                print pid,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   188
            for m in msg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   189
                print m,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   190
            print
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   191
            sys.stdout.flush()
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   192
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   193
        vlog = lambda *msg: None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   194
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   195
    if options.tmpdir:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   196
        options.tmpdir = os.path.expanduser(options.tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   197
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   198
    if options.jobs < 1:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   199
        parser.error('--jobs must be positive')
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   200
    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
   201
        print '(--interactive overrides --jobs)'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   202
        options.jobs = 1
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   203
    if options.interactive and options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   204
        parser.error("-i/--interactive and -d/--debug are incompatible")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   205
    if options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   206
        if options.timeout != defaults['timeout']:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   207
            sys.stderr.write(
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   208
                'warning: --timeout option ignored with --debug\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   209
        options.timeout = 0
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   210
    if options.py3k_warnings:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   211
        if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0):
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   212
            parser.error('--py3k-warnings can only be used on Python 2.6+')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   213
    if options.blacklist:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   214
        blacklist = dict()
681
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   215
        for filename in options.blacklist:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   216
            try:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   217
                path = os.path.expanduser(os.path.expandvars(filename))
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   218
                f = open(path, "r")
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   219
            except IOError, err:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   220
                if err.errno != errno.ENOENT:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   221
                    raise
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   222
                print "warning: no such blacklist file: %s" % filename
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   223
                continue
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   224
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   225
            for line in f.readlines():
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   226
                line = line.strip()
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   227
                if line and not line.startswith('#'):
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   228
                    blacklist[line] = filename
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   229
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   230
        options.blacklist = blacklist
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   231
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   232
    return (options, args)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   233
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   234
def rename(src, dst):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   235
    """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
   236
    for existing destination support.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   237
    """
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   238
    shutil.copy(src, dst)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   239
    os.remove(src)
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 splitnewlines(text):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   242
    '''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
   243
    keep line endings.'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   244
    i = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   245
    lines = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   246
    while True:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   247
        n = text.find('\n', i)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   248
        if n == -1:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   249
            last = text[i:]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   250
            if last:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   251
                lines.append(last)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   252
            return lines
680
f10a5301d082 many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 674
diff changeset
   253
        lines.append(text[i:n + 1])
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   254
        i = n + 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   255
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   256
def parsehghaveoutput(lines):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   257
    '''Parse hghave log lines.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   258
    Return tuple of lists (missing, failed):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   259
      * the missing/unknown features
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   260
      * 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
   261
    missing = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   262
    failed = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   263
    for line in lines:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   264
        if line.startswith(SKIPPED_PREFIX):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   265
            line = line.splitlines()[0]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   266
            missing.append(line[len(SKIPPED_PREFIX):])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   267
        elif line.startswith(FAILED_PREFIX):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   268
            line = line.splitlines()[0]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   269
            failed.append(line[len(FAILED_PREFIX):])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   270
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   271
    return missing, failed
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   272
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   273
def showdiff(expected, output, ref, err):
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   274
    for line in difflib.unified_diff(expected, output, ref, err):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   275
        sys.stdout.write(line)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   276
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   277
def findprogram(program):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   278
    """Search PATH for a executable program"""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   279
    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
   280
        name = os.path.join(p, program)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   281
        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
   282
            return name
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   283
    return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   284
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   285
def checktools():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   286
    # 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
   287
    # 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
   288
    for p in requiredtools:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   289
        if os.name == 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   290
            p += '.exe'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   291
        found = findprogram(p)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   292
        if found:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   293
            vlog("# Found prerequisite", p, "at", found)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   294
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   295
            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
   296
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   297
def killdaemons():
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   298
    # Kill off any leftover daemon processes
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   299
    try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   300
        fp = open(DAEMON_PIDS)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   301
        for line in fp:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   302
            try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   303
                pid = int(line)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   304
            except ValueError:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   305
                continue
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   306
            try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   307
                os.kill(pid, 0)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   308
                vlog('# Killing daemon process %d' % pid)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   309
                os.kill(pid, signal.SIGTERM)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   310
                time.sleep(0.25)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   311
                os.kill(pid, 0)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   312
                vlog('# Daemon process %d is stuck - really killing it' % pid)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   313
                os.kill(pid, signal.SIGKILL)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   314
            except OSError, err:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   315
                if err.errno != errno.ESRCH:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   316
                    raise
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   317
        fp.close()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   318
        os.unlink(DAEMON_PIDS)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   319
    except IOError:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   320
        pass
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   321
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   322
def cleanup(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   323
    if not options.keep_tmpdir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   324
        vlog("# Cleaning up HGTMP", HGTMP)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   325
        shutil.rmtree(HGTMP, True)
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
def usecorrectpython():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   328
    # 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
   329
    # 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
   330
    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
   331
    if exename == 'python':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   332
        path = findprogram('python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   333
        if os.path.dirname(path) == exedir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   334
            return
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   335
    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
   336
    mypython = os.path.join(BINDIR, 'python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   337
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   338
        os.symlink(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   339
    except AttributeError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   340
        # windows fallback
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   341
        shutil.copyfile(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   342
        shutil.copymode(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   343
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   344
def installhg(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   345
    vlog("# Performing temporary installation of HG")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   346
    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
   347
    pure = options.pure and "--pure" or ""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   348
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   349
    # Run installer in hg root
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   350
    script = os.path.realpath(sys.argv[0])
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   351
    hgroot = os.path.dirname(os.path.dirname(script))
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   352
    os.chdir(hgroot)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   353
    nohome = '--home=""'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   354
    if os.name == 'nt':
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   355
        # The --home="" trick works only on OS where os.sep == '/'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   356
        # because of a distutils convert_path() fast-path. Avoid it at
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   357
        # least on Windows for now, deal with .pydistutils.cfg bugs
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   358
        # when they happen.
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   359
        nohome = ''
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   360
    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
   361
           ' install --force --prefix="%s" --install-lib="%s"'
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   362
           ' --install-scripts="%s" %s >%s 2>&1'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   363
           % (sys.executable, pure, INST, PYTHONDIR, BINDIR, nohome,
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   364
              installerrs))
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   365
    vlog("# Running", cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   366
    if os.system(cmd) == 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   367
        if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   368
            os.remove(installerrs)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   369
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   370
        f = open(installerrs)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   371
        for line in f:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   372
            print line,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   373
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   374
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   375
    os.chdir(TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   376
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   377
    usecorrectpython()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   378
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   379
    vlog("# Installing dummy diffstat")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   380
    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
   381
    f.write('#!' + sys.executable + '\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   382
            'import sys\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   383
            'files = 0\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   384
            'for line in sys.stdin:\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   385
            '    if line.startswith("diff "):\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   386
            '        files += 1\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   387
            '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
   388
    f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   389
    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
   390
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   391
    if options.py3k_warnings and not options.anycoverage:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   392
        vlog("# Updating hg command to enable Py3k Warnings switch")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   393
        f = open(os.path.join(BINDIR, 'hg'), 'r')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   394
        lines = [line.rstrip() for line in f]
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   395
        lines[0] += ' -3'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   396
        f.close()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   397
        f = open(os.path.join(BINDIR, 'hg'), 'w')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   398
        for line in lines:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   399
            f.write(line + '\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   400
        f.close()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   401
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   402
    if options.anycoverage:
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   403
        custom = os.path.join(TESTDIR, 'sitecustomize.py')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   404
        target = os.path.join(PYTHONDIR, 'sitecustomize.py')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   405
        vlog('# Installing coverage trigger to %s' % target)
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   406
        shutil.copyfile(custom, target)
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   407
        rc = os.path.join(TESTDIR, '.coveragerc')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   408
        vlog('# Installing coverage rc to %s' % rc)
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   409
        os.environ['COVERAGE_PROCESS_START'] = rc
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   410
        fn = os.path.join(INST, '..', '.coverage')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   411
        os.environ['COVERAGE_FILE'] = fn
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   412
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   413
def outputcoverage(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   414
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   415
    vlog('# Producing coverage report')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   416
    os.chdir(PYTHONDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   417
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   418
    def covrun(*args):
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   419
        cmd = 'coverage %s' % ' '.join(args)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   420
        vlog('# Running: %s' % cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   421
        os.system(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   422
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   423
    if options.child:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   424
        return
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   425
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   426
    covrun('-c')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   427
    omit = ','.join([BINDIR, TESTDIR])
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   428
    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
   429
    if options.annotate:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   430
        adir = os.path.join(TESTDIR, 'annotated')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   431
        if not os.path.isdir(adir):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   432
            os.mkdir(adir)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   433
        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
   434
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   435
class Timeout(Exception):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   436
    pass
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   437
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   438
def alarmed(signum, frame):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   439
    raise Timeout
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   440
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   441
def run(cmd, options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   442
    """Run command in a sub-process, capturing the output (stdout and stderr).
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   443
    Return a tuple (exitcode, output).  output is None in debug mode."""
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   444
    # TODO: Use subprocess.Popen if we're running on Python 2.4
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   445
    if options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   446
        proc = subprocess.Popen(cmd, shell=True)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   447
        ret = proc.wait()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   448
        return (ret, None)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   449
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   450
    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
   451
        tochild, fromchild = os.popen4(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   452
        tochild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   453
        output = fromchild.read()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   454
        ret = fromchild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   455
        if ret == None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   456
            ret = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   457
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   458
        proc = Popen4(cmd)
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   459
        def cleanup():
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   460
            os.kill(proc.pid, signal.SIGTERM)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   461
            ret = proc.wait()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   462
            if ret == 0:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   463
                ret = signal.SIGTERM << 8
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   464
            killdaemons()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   465
            return ret
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   466
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   467
        try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   468
            output = ''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   469
            proc.tochild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   470
            output = proc.fromchild.read()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   471
            ret = proc.wait()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   472
            if os.WIFEXITED(ret):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   473
                ret = os.WEXITSTATUS(ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   474
        except Timeout:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   475
            vlog('# Process %d timed out - killing it' % proc.pid)
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   476
            ret = cleanup()
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   477
            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
   478
                       % options.timeout)
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   479
        except KeyboardInterrupt:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   480
            vlog('# Handling keyboard interrupt')
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   481
            cleanup()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   482
            raise
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   483
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   484
    return ret, splitnewlines(output)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   485
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   486
def runone(options, test, skips, fails):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   487
    '''tristate output:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   488
    None -> skipped
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   489
    True -> passed
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   490
    False -> failed'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   491
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   492
    def skip(msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   493
        if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   494
            skips.append((test, msg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   495
        else:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   496
            print "\nSkipping %s: %s" % (testpath, msg)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   497
        return None
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
    def fail(msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   500
        fails.append((test, msg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   501
        if not options.nodiff:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   502
            print "\nERROR: %s %s" % (testpath, msg)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   503
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   504
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   505
    vlog("# Test", test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   506
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   507
    # create a fresh hgrc
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   508
    hgrc = open(HGRCPATH, 'w+')
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   509
    hgrc.write('[ui]\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   510
    hgrc.write('slash = True\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   511
    hgrc.write('[defaults]\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   512
    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
   513
    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
   514
    hgrc.write('tag = -d "0 0"\n')
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   515
    if options.inotify:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   516
        hgrc.write('[extensions]\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   517
        hgrc.write('inotify=\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   518
        hgrc.write('[inotify]\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   519
        hgrc.write('pidfile=%s\n' % DAEMON_PIDS)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   520
        hgrc.write('appendpid=True\n')
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   521
    hgrc.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   522
693
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   523
    testpath = os.path.join(TESTDIR, test)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   524
    ref = os.path.join(TESTDIR, test+".out")
693
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   525
    err = os.path.join(TESTDIR, test+".err")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   526
    if os.path.exists(err):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   527
        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
   528
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   529
        tf = open(testpath)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   530
        firstline = tf.readline().rstrip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   531
        tf.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   532
    except:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   533
        firstline = ''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   534
    lctest = test.lower()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   535
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   536
    if lctest.endswith('.py') or firstline == '#!/usr/bin/env python':
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   537
        py3kswitch = options.py3k_warnings and ' -3' or ''
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   538
        cmd = '%s%s "%s"' % (PYTHON, py3kswitch, testpath)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   539
    elif lctest.endswith('.bat'):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   540
        # 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
   541
        if os.name != 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   542
            return skip("batch script")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   543
        # 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
   544
        # 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
   545
        cmd = 'cmd /c call "%s"' % testpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   546
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   547
        # 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
   548
        if os.name == 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   549
            return skip("shell script")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   550
        # 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
   551
        if not os.path.exists(testpath):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   552
            return fail("does not exist")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   553
        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
   554
            return skip("not executable")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   555
        cmd = '"%s"' % testpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   556
693
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   557
    # Make a tmp subdirectory to work in
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   558
    tmpd = os.path.join(HGTMP, test)
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   559
    os.mkdir(tmpd)
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   560
    os.chdir(tmpd)
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   561
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   562
    if options.timeout > 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   563
        signal.alarm(options.timeout)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   564
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   565
    vlog("# Running", cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   566
    ret, out = run(cmd, options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   567
    vlog("# Ret was:", ret)
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
    if options.timeout > 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   570
        signal.alarm(0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   571
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   572
    mark = '.'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   573
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   574
    skipped = (ret == SKIPPED_STATUS)
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   575
    # If we're not in --debug mode and reference output file exists,
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   576
    # check test output against it.
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   577
    if options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   578
        refout = None                   # to match out == None
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   579
    elif os.path.exists(ref):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   580
        f = open(ref, "r")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   581
        refout = splitnewlines(f.read())
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   582
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   583
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   584
        refout = []
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   585
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   586
    if skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   587
        mark = 's'
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   588
        if out is None:                 # debug mode: nothing to parse
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   589
            missing = ['unknown']
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   590
            failed = None
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   591
        else:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   592
            missing, failed = parsehghaveoutput(out)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   593
        if not missing:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   594
            missing = ['irrelevant']
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   595
        if failed:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   596
            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
   597
            skipped = False
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   598
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   599
            skip(missing[-1])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   600
    elif out != refout:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   601
        mark = '!'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   602
        if ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   603
            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
   604
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   605
            fail("output changed")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   606
        if not options.nodiff:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   607
            showdiff(refout, out, ref, err)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   608
        ret = 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   609
    elif ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   610
        mark = '!'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   611
        fail("returned error code %d" % ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   612
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   613
    if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   614
        sys.stdout.write(mark)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   615
        sys.stdout.flush()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   616
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   617
    if ret != 0 and not skipped and not options.debug:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   618
        # 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
   619
        f = open(err, "wb")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   620
        for line in out:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   621
            f.write(line)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   622
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   623
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   624
    killdaemons()
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   625
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   626
    os.chdir(TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   627
    if not options.keep_tmpdir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   628
        shutil.rmtree(tmpd, True)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   629
    if skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   630
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   631
    return ret == 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   632
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   633
_hgpath = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   634
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   635
def _gethgpath():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   636
    """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
   637
    the current Python interpreter."""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   638
    global _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   639
    if _hgpath is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   640
        return _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   641
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   642
    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
   643
    pipe = os.popen(cmd % PYTHON)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   644
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   645
        _hgpath = pipe.read().strip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   646
    finally:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   647
        pipe.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   648
    return _hgpath
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
def _checkhglib(verb):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   651
    """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
   652
    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
   653
    expecthg = os.path.join(PYTHONDIR, 'mercurial')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   654
    actualhg = _gethgpath()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   655
    if actualhg != expecthg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   656
        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
   657
                         '         (expected %s)\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   658
                         % (verb, actualhg, expecthg))
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
def runchildren(options, tests):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   661
    if INST:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   662
        installhg(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   663
        _checkhglib("Testing")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   664
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   665
    optcopy = dict(options.__dict__)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   666
    optcopy['jobs'] = 1
725
212432db2043 Fix --blacklist when --jobs > 1 in run_tests.py.
Ry4an Brase <ry4an-hg@ry4an.org>
parents: 724
diff changeset
   667
    del optcopy['blacklist']
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   668
    if optcopy['with_hg'] is None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   669
        optcopy['with_hg'] = os.path.join(BINDIR, "hg")
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   670
    optcopy.pop('anycoverage', None)
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   671
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   672
    opts = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   673
    for opt, value in optcopy.iteritems():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   674
        name = '--' + opt.replace('_', '-')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   675
        if value is True:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   676
            opts.append(name)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   677
        elif value is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   678
            opts.append(name + '=' + str(value))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   679
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   680
    tests.reverse()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   681
    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
   682
    while tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   683
        for job in jobs:
680
f10a5301d082 many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 674
diff changeset
   684
            if not tests:
f10a5301d082 many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 674
diff changeset
   685
                break
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   686
            job.append(tests.pop())
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   687
    fps = {}
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   688
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   689
    for j, job in enumerate(jobs):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   690
        if not job:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   691
            continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   692
        rfd, wfd = os.pipe()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   693
        childopts = ['--child=%d' % wfd, '--port=%d' % (options.port + j * 3)]
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   694
        childtmp = os.path.join(HGTMP, 'child%d' % j)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   695
        childopts += ['--tmpdir', childtmp]
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   696
        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
   697
        vlog(' '.join(cmdline))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   698
        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
   699
        os.close(wfd)
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   700
    signal.signal(signal.SIGINT, signal.SIG_IGN)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   701
    failures = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   702
    tested, skipped, failed = 0, 0, 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   703
    skips = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   704
    fails = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   705
    while fps:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   706
        pid, status = os.wait()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   707
        fp = fps.pop(pid)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   708
        l = fp.read().splitlines()
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   709
        try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   710
            test, skip, fail = map(int, l[:3])
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   711
        except ValueError:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   712
            test, skip, fail = 0, 0, 0
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   713
        split = -fail or len(l)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   714
        for s in l[3:split]:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   715
            skips.append(s.split(" ", 1))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   716
        for s in l[split:]:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   717
            fails.append(s.split(" ", 1))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   718
        tested += test
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   719
        skipped += skip
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   720
        failed += fail
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   721
        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
   722
        failures |= status
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   723
    print
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   724
    if not options.noskips:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   725
        for s in skips:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   726
            print "Skipped %s: %s" % (s[0], s[1])
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   727
    for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   728
        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
   729
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   730
    _checkhglib("Tested")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   731
    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
   732
        tested, skipped, failed)
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   733
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   734
    if options.anycoverage:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   735
        outputcoverage(options)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   736
    sys.exit(failures != 0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   737
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   738
def runtests(options, tests):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   739
    global DAEMON_PIDS, HGRCPATH
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   740
    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
   741
    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
   742
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   743
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   744
        if INST:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   745
            installhg(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   746
            _checkhglib("Testing")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   747
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   748
        if options.timeout > 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   749
            try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   750
                signal.signal(signal.SIGALRM, alarmed)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   751
                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
   752
                     options.timeout)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   753
            except AttributeError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   754
                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
   755
                options.timeout = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   756
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   757
        tested = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   758
        failed = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   759
        skipped = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   760
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   761
        if options.restart:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   762
            orig = list(tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   763
            while tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   764
                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
   765
                    break
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   766
                tests.pop(0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   767
            if not tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   768
                print "running all tests"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   769
                tests = orig
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   770
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   771
        skips = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   772
        fails = []
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   773
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   774
        for test in tests:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   775
            if options.blacklist:
681
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   776
                filename = options.blacklist.get(test)
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   777
                if filename is not None:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   778
                    skips.append((test, "blacklisted (%s)" % filename))
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   779
                    skipped += 1
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   780
                    continue
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   781
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   782
            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
   783
                skipped += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   784
                continue
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   785
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   786
            if options.keywords:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   787
                t = open(test).read().lower() + test.lower()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   788
                for k in options.keywords.lower().split():
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   789
                    if k in t:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   790
                        break
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   791
                else:
683
26ca426a04e1 fix up a bunch of check-code warnings
Matt Mackall <mpm@selenic.com>
parents: 682
diff changeset
   792
                    skipped += 1
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   793
                    continue
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   794
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   795
            ret = runone(options, test, skips, fails)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   796
            if ret is None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   797
                skipped += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   798
            elif not ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   799
                if options.interactive:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   800
                    print "Accept this change? [n] ",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   801
                    answer = sys.stdin.readline().strip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   802
                    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
   803
                        rename(test + ".err", test + ".out")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   804
                        tested += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   805
                        fails.pop()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   806
                        continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   807
                failed += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   808
                if options.first:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   809
                    break
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   810
            tested += 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   811
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   812
        if options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   813
            fp = os.fdopen(options.child, 'w')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   814
            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
   815
            for s in skips:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   816
                fp.write("%s %s\n" % s)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   817
            for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   818
                fp.write("%s %s\n" % s)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   819
            fp.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   820
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   821
            print
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   822
            for s in skips:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   823
                print "Skipped %s: %s" % s
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   824
            for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   825
                print "Failed %s: %s" % s
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   826
            _checkhglib("Tested")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   827
            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
   828
                tested, skipped, failed)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   829
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   830
        if options.anycoverage:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   831
            outputcoverage(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   832
    except KeyboardInterrupt:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   833
        failed = True
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   834
        print "\ninterrupted!"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   835
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   836
    if failed:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   837
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   838
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   839
def main():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   840
    (options, args) = parseargs()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   841
    if not options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   842
        os.umask(022)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   843
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   844
        checktools()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   845
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   846
    # 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
   847
    # the tests produce repeatable output.
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   848
    os.environ['LANG'] = os.environ['LC_ALL'] = os.environ['LANGUAGE'] = 'C'
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   849
    os.environ['TZ'] = 'GMT'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   850
    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
   851
    os.environ['CDPATH'] = ''
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   852
    os.environ['COLUMNS'] = '80'
719
ad3048630bd8 run-tests: make sure GREP_OPTIONS isn't set
Brodie Rao <brodie@bitheap.org>
parents: 718
diff changeset
   853
    os.environ['GREP_OPTIONS'] = ''
692
5ac40b193130 run-tests.py: clears http_proxy for all tests
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 683
diff changeset
   854
    os.environ['http_proxy'] = ''
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   855
724
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
   856
    # unset env related to hooks
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
   857
    for k in os.environ.keys():
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
   858
        if k.startswith('HG_'):
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
   859
            del os.environ[k]
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
   860
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   861
    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
   862
    TESTDIR = os.environ["TESTDIR"] = os.getcwd()
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   863
    if options.tmpdir:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   864
        options.keep_tmpdir = True
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   865
        tmpdir = options.tmpdir
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   866
        if os.path.exists(tmpdir):
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   867
            # Meaning of tmpdir has changed since 1.3: we used to create
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   868
            # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   869
            # tmpdir already exists.
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   870
            sys.exit("error: temp dir %r already exists" % tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   871
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   872
            # Automatically removing tmpdir sounds convenient, but could
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   873
            # really annoy anyone in the habit of using "--tmpdir=/tmp"
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   874
            # or "--tmpdir=$HOME".
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   875
            #vlog("# Removing temp dir", tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   876
            #shutil.rmtree(tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   877
        os.makedirs(tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   878
    else:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   879
        tmpdir = tempfile.mkdtemp('', 'hgtests.')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   880
    HGTMP = os.environ['HGTMP'] = os.path.realpath(tmpdir)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   881
    DAEMON_PIDS = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   882
    HGRCPATH = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   883
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   884
    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
   885
    os.environ["HGMERGE"] = "internal:merge"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   886
    os.environ["HGUSER"]   = "test"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   887
    os.environ["HGENCODING"] = "ascii"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   888
    os.environ["HGENCODINGMODE"] = "strict"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   889
    os.environ["HGPORT"] = str(options.port)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   890
    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
   891
    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
   892
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   893
    if options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   894
        INST = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   895
        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
   896
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   897
        # 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
   898
        # 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
   899
        # "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
   900
        # 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
   901
        # ... 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
   902
        PYTHONDIR = BINDIR
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   903
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   904
        INST = os.path.join(HGTMP, "install")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   905
        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
   906
        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
   907
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   908
    os.environ["BINDIR"] = BINDIR
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   909
    os.environ["PYTHON"] = PYTHON
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   910
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   911
    if not options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   912
        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
   913
        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
   914
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   915
        # 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
   916
        # 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
   917
        # adds an extension to HGRC
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   918
        pypath = [PYTHONDIR, TESTDIR]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   919
        # 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
   920
        # 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
   921
        # 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
   922
        # are in /opt/subversion.)
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   923
        oldpypath = os.environ.get(IMPL_PATH)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   924
        if oldpypath:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   925
            pypath.append(oldpypath)
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   926
        os.environ[IMPL_PATH] = os.pathsep.join(pypath)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   927
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   928
    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
   929
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   930
    if len(args) == 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   931
        args = os.listdir(".")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   932
        args.sort()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   933
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   934
    tests = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   935
    for test in args:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   936
        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
   937
            ('.' 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
   938
             test.endswith('.bat'))):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   939
            tests.append(test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   940
    if not tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   941
        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
   942
        return
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   943
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   944
    vlog("# Using TESTDIR", TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   945
    vlog("# Using HGTMP", HGTMP)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   946
    vlog("# Using PATH", os.environ["PATH"])
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   947
    vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   948
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   949
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   950
        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
   951
            runchildren(options, tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   952
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   953
            runtests(options, tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   954
    finally:
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   955
        time.sleep(1)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   956
        cleanup(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   957
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   958
main()