tests/run-tests.py
author Matt Mackall <mpm@selenic.com>
Sun, 24 Apr 2011 16:42:15 -0500
branchstable
changeset 913 ee01b53f9ac9
parent 912 17e4691cc491
child 914 3c57e9963070
permissions -rwxr-xr-x
run-tests: switch timeout handling from alarm to helper thread This should be slightly more portable than signals and be compatible with threaded dispatch. [ 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
726
f7050b041b5f pylint, pyflakes: remove unused or duplicate imports
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 725
diff changeset
    49
import shutil
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 signal
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    52
import sys
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    53
import tempfile
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    54
import time
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
    55
import re
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
    56
import threading
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    57
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    58
closefds = os.name == 'posix'
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    59
def Popen4(cmd, timeout):
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    60
    p = subprocess.Popen(cmd, shell=True, bufsize=-1,
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    61
                         close_fds=closefds,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    62
                         stdin=subprocess.PIPE, stdout=subprocess.PIPE,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    63
                         stderr=subprocess.STDOUT)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    64
    p.fromchild = p.stdout
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    65
    p.tochild = p.stdin
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    66
    p.childerr = p.stderr
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    67
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    68
    if timeout:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    69
        p.timeout = False
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    70
        def t():
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    71
            start = time.time()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    72
            while time.time() - start < timeout and p.returncode is None:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    73
                time.sleep(1)
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    74
            p.timeout = True
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    75
            if p.returncode is None:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    76
                try:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    77
                    p.terminate()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    78
                except OSError:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    79
                    pass
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    80
        threading.Thread(target=t).start()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
    81
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    82
    return p
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
# 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
    85
SKIPPED_STATUS = 80
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    86
SKIPPED_PREFIX = 'skipped: '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    87
FAILED_PREFIX  = 'hghave check failed: '
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    88
PYTHON = sys.executable
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
    89
IMPL_PATH = 'PYTHONPATH'
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
    90
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
    91
    IMPL_PATH = 'JYTHONPATH'
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    92
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    93
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
    94
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    95
defaults = {
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    96
    'jobs': ('HGTEST_JOBS', 1),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    97
    'timeout': ('HGTEST_TIMEOUT', 180),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    98
    'port': ('HGTEST_PORT', 20059),
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    99
}
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   100
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   101
def parseargs():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   102
    parser = optparse.OptionParser("%prog [options] [tests]")
740
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   103
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   104
    # keep these sorted
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   105
    parser.add_option("--blacklist", action="append",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   106
        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
   107
    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
   108
        help="output files annotated with coverage")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   109
    parser.add_option("--child", type="int",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   110
        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
   111
    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
   112
        help="print a test coverage report")
740
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   113
    parser.add_option("-d", "--debug", action="store_true",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   114
        help="debug mode: write output of test scripts to console"
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   115
             " 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
   116
    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
   117
        help="exit on the first test failure")
740
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   118
    parser.add_option("--inotify", action="store_true",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   119
        help="enable inotify extension when running tests")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   120
    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
   121
        help="prompt to accept changed output")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   122
    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
   123
        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
   124
             " (default: $%s or %d)" % defaults['jobs'])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   125
    parser.add_option("--keep-tmpdir", action="store_true",
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   126
        help="keep temporary directory after running tests")
740
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   127
    parser.add_option("-k", "--keywords",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   128
        help="run tests matching keywords")
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   129
    parser.add_option("-l", "--local", action="store_true",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   130
        help="shortcut for --with-hg=<testdir>/../hg")
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   131
    parser.add_option("-n", "--nodiff", action="store_true",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   132
        help="skip showing test changes")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   133
    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
   134
        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
   135
             " (default: $%s or %d)" % defaults['port'])
740
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   136
    parser.add_option("--pure", action="store_true",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   137
        help="use pure Python code instead of C extensions")
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   138
    parser.add_option("-R", "--restart", action="store_true",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   139
        help="restart at last error")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   140
    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
   141
        help="retest failed tests")
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   142
    parser.add_option("-S", "--noskips", action="store_true",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   143
        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
   144
    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
   145
        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
   146
             " (default: $%s or %d)" % defaults['timeout'])
740
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   147
    parser.add_option("--tmpdir", type="string",
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   148
        help="run tests in the given temporary directory"
7d3c26dea450 run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 739
diff changeset
   149
             " (implies --keep-tmpdir)")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   150
    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
   151
        help="output verbose messages")
741
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   152
    parser.add_option("--view", type="string",
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   153
        help="external diff viewer")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   154
    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
   155
        metavar="HG",
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   156
        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
   157
             "temporary installation")
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   158
    parser.add_option("-3", "--py3k-warnings", action="store_true",
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   159
        help="enable Py3k warnings on Python 2.6+")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   160
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   161
    for option, default in defaults.items():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   162
        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
   163
    parser.set_defaults(**defaults)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   164
    (options, args) = parser.parse_args()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   165
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   166
    # 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
   167
    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
   168
        options.pure = True
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
   169
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   170
    if options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   171
        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
   172
                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
   173
            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
   174
        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
   175
            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
   176
    if options.local:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   177
        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
   178
        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
   179
        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
   180
            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
   181
                         % hgbin)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   182
        options.with_hg = hgbin
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   183
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   184
    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
   185
    if options.anycoverage:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   186
        try:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   187
            import coverage
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   188
            covver = version.StrictVersion(coverage.__version__).version
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   189
            if covver < (3, 3):
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   190
                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
   191
        except ImportError:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   192
            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
   193
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   194
    if options.anycoverage and options.local:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   195
        # 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
   196
        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
   197
                     "is specified")
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   198
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   199
    global vlog
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   200
    if options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   201
        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
   202
            pid = "[%d]" % os.getpid()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   203
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   204
            pid = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   205
        def vlog(*msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   206
            if pid:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   207
                print pid,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   208
            for m in msg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   209
                print m,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   210
            print
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   211
            sys.stdout.flush()
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   212
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   213
        vlog = lambda *msg: None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   214
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   215
    if options.tmpdir:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   216
        options.tmpdir = os.path.expanduser(options.tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   217
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   218
    if options.jobs < 1:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   219
        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
   220
    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
   221
        print '(--interactive overrides --jobs)'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   222
        options.jobs = 1
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   223
    if options.interactive and options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   224
        parser.error("-i/--interactive and -d/--debug are incompatible")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   225
    if options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   226
        if options.timeout != defaults['timeout']:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   227
            sys.stderr.write(
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   228
                'warning: --timeout option ignored with --debug\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   229
        options.timeout = 0
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   230
    if options.py3k_warnings:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   231
        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
   232
            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
   233
    if options.blacklist:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   234
        blacklist = dict()
681
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   235
        for filename in options.blacklist:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   236
            try:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   237
                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
   238
                f = open(path, "r")
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   239
            except IOError, err:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   240
                if err.errno != errno.ENOENT:
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   241
                    raise
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   242
                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
   243
                continue
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   244
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   245
            for line in f.readlines():
882
c3681742c0c7 run-tests: handle mixed comment lines in blacklists
Patrick Mezard <pmezard@gmail.com>
parents: 880
diff changeset
   246
                line = line.split('#', 1)[0].strip()
c3681742c0c7 run-tests: handle mixed comment lines in blacklists
Patrick Mezard <pmezard@gmail.com>
parents: 880
diff changeset
   247
                if line:
681
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   248
                    blacklist[line] = filename
d0a410e49776 run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 680
diff changeset
   249
880
0b9f0c42b566 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 878
diff changeset
   250
            f.close()
0b9f0c42b566 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 878
diff changeset
   251
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   252
        options.blacklist = blacklist
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   253
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   254
    return (options, args)
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 rename(src, dst):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   257
    """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
   258
    for existing destination support.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   259
    """
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   260
    shutil.copy(src, dst)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   261
    os.remove(src)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   262
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   263
def splitnewlines(text):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   264
    '''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
   265
    keep line endings.'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   266
    i = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   267
    lines = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   268
    while True:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   269
        n = text.find('\n', i)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   270
        if n == -1:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   271
            last = text[i:]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   272
            if last:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   273
                lines.append(last)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   274
            return lines
680
f10a5301d082 many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 674
diff changeset
   275
        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
   276
        i = n + 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   277
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   278
def parsehghaveoutput(lines):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   279
    '''Parse hghave log lines.
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   280
    Return tuple of lists (missing, failed):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   281
      * the missing/unknown features
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   282
      * 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
   283
    missing = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   284
    failed = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   285
    for line in lines:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   286
        if line.startswith(SKIPPED_PREFIX):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   287
            line = line.splitlines()[0]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   288
            missing.append(line[len(SKIPPED_PREFIX):])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   289
        elif line.startswith(FAILED_PREFIX):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   290
            line = line.splitlines()[0]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   291
            failed.append(line[len(FAILED_PREFIX):])
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   292
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   293
    return missing, failed
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   294
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   295
def showdiff(expected, output, ref, err):
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   296
    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
   297
        sys.stdout.write(line)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   298
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   299
def findprogram(program):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   300
    """Search PATH for a executable program"""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   301
    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
   302
        name = os.path.join(p, program)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   303
        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
   304
            return name
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   305
    return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   306
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   307
def checktools():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   308
    # 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
   309
    # 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
   310
    for p in requiredtools:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   311
        if os.name == 'nt':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   312
            p += '.exe'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   313
        found = findprogram(p)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   314
        if found:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   315
            vlog("# Found prerequisite", p, "at", found)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   316
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   317
            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
   318
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   319
def killdaemons():
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   320
    # Kill off any leftover daemon processes
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   321
    try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   322
        fp = open(DAEMON_PIDS)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   323
        for line in fp:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   324
            try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   325
                pid = int(line)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   326
            except ValueError:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   327
                continue
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   328
            try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   329
                os.kill(pid, 0)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   330
                vlog('# Killing daemon process %d' % pid)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   331
                os.kill(pid, signal.SIGTERM)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   332
                time.sleep(0.25)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   333
                os.kill(pid, 0)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   334
                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
   335
                os.kill(pid, signal.SIGKILL)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   336
            except OSError, err:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   337
                if err.errno != errno.ESRCH:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   338
                    raise
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   339
        fp.close()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   340
        os.unlink(DAEMON_PIDS)
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   341
    except IOError:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   342
        pass
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   343
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   344
def cleanup(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   345
    if not options.keep_tmpdir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   346
        vlog("# Cleaning up HGTMP", HGTMP)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   347
        shutil.rmtree(HGTMP, True)
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
def usecorrectpython():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   350
    # 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
   351
    # 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
   352
    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
   353
    if exename == 'python':
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   354
        path = findprogram('python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   355
        if os.path.dirname(path) == exedir:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   356
            return
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   357
    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
   358
    mypython = os.path.join(BINDIR, 'python')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   359
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   360
        os.symlink(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   361
    except AttributeError:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   362
        # windows fallback
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   363
        shutil.copyfile(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   364
        shutil.copymode(sys.executable, mypython)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   365
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   366
def installhg(options):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   367
    vlog("# Performing temporary installation of HG")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   368
    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
   369
    pure = options.pure and "--pure" or ""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   370
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   371
    # Run installer in hg root
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   372
    script = os.path.realpath(sys.argv[0])
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   373
    hgroot = os.path.dirname(os.path.dirname(script))
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   374
    os.chdir(hgroot)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   375
    nohome = '--home=""'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   376
    if os.name == 'nt':
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   377
        # The --home="" trick works only on OS where os.sep == '/'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   378
        # 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
   379
        # least on Windows for now, deal with .pydistutils.cfg bugs
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   380
        # when they happen.
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   381
        nohome = ''
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   382
    cmd = ('%s setup.py %s clean --all'
822
842e2c76e64b run-tests: move build/ directory to HGTMP
Martin Geisler <mg@lazybytes.net>
parents: 802
diff changeset
   383
           ' build --build-base="%s"'
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   384
           ' install --force --prefix="%s" --install-lib="%s"'
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   385
           ' --install-scripts="%s" %s >%s 2>&1'
822
842e2c76e64b run-tests: move build/ directory to HGTMP
Martin Geisler <mg@lazybytes.net>
parents: 802
diff changeset
   386
           % (sys.executable, pure, os.path.join(HGTMP, "build"),
842e2c76e64b run-tests: move build/ directory to HGTMP
Martin Geisler <mg@lazybytes.net>
parents: 802
diff changeset
   387
              INST, PYTHONDIR, BINDIR, nohome, installerrs))
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   388
    vlog("# Running", cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   389
    if os.system(cmd) == 0:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   390
        if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   391
            os.remove(installerrs)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   392
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   393
        f = open(installerrs)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   394
        for line in f:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   395
            print line,
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   396
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   397
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   398
    os.chdir(TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   399
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   400
    usecorrectpython()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   401
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   402
    vlog("# Installing dummy diffstat")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   403
    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
   404
    f.write('#!' + sys.executable + '\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   405
            'import sys\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   406
            'files = 0\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   407
            'for line in sys.stdin:\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   408
            '    if line.startswith("diff "):\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   409
            '        files += 1\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   410
            '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
   411
    f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   412
    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
   413
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   414
    if options.py3k_warnings and not options.anycoverage:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   415
        vlog("# Updating hg command to enable Py3k Warnings switch")
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   416
        f = open(os.path.join(BINDIR, 'hg'), 'r')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   417
        lines = [line.rstrip() for line in f]
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   418
        lines[0] += ' -3'
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   419
        f.close()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   420
        f = open(os.path.join(BINDIR, 'hg'), 'w')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   421
        for line in lines:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   422
            f.write(line + '\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   423
        f.close()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   424
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   425
    if options.anycoverage:
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   426
        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
   427
        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
   428
        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
   429
        shutil.copyfile(custom, target)
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   430
        rc = os.path.join(TESTDIR, '.coveragerc')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   431
        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
   432
        os.environ['COVERAGE_PROCESS_START'] = rc
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   433
        fn = os.path.join(INST, '..', '.coverage')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   434
        os.environ['COVERAGE_FILE'] = fn
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   435
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   436
def outputcoverage(options):
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
    vlog('# Producing coverage report')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   439
    os.chdir(PYTHONDIR)
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 covrun(*args):
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   442
        cmd = 'coverage %s' % ' '.join(args)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   443
        vlog('# Running: %s' % cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   444
        os.system(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   445
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   446
    if options.child:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   447
        return
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   448
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   449
    covrun('-c')
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   450
    omit = ','.join([BINDIR, TESTDIR])
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   451
    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
   452
    if options.annotate:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   453
        adir = os.path.join(TESTDIR, 'annotated')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   454
        if not os.path.isdir(adir):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   455
            os.mkdir(adir)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   456
        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
   457
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   458
def pytest(test, options, replacements):
775
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   459
    py3kswitch = options.py3k_warnings and ' -3' or ''
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   460
    cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   461
    vlog("# Running", cmd)
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   462
    return run(cmd, options, replacements)
775
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   463
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   464
def shtest(test, options, replacements):
775
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   465
    cmd = '"%s"' % test
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   466
    vlog("# Running", cmd)
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   467
    return run(cmd, options, replacements)
775
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   468
858
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   469
needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   470
escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   471
escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256))
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   472
escapemap.update({'\\': '\\\\', '\r': r'\r'})
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   473
def escapef(m):
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   474
    return escapemap[m.group(0)]
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   475
def stringescape(s):
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   476
    return escapesub(escapef, s)
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   477
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   478
def tsttest(test, options, replacements):
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   479
    t = open(test)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   480
    out = []
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   481
    script = []
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   482
    salt = "SALT" + str(time.time())
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   483
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   484
    pos = prepos = -1
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   485
    after = {}
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   486
    expected = {}
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   487
    for n, l in enumerate(t):
856
e1a5259b3d03 tests: handle .t files without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 852
diff changeset
   488
        if not l.endswith('\n'):
e1a5259b3d03 tests: handle .t files without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 852
diff changeset
   489
            l += '\n'
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   490
        if l.startswith('  $ '): # commands
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   491
            after.setdefault(pos, []).append(l)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   492
            prepos = pos
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   493
            pos = n
793
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   494
            script.append('echo %s %s $?\n' % (salt, n))
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   495
            script.append(l[4:])
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   496
        elif l.startswith('  > '): # continuations
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   497
            after.setdefault(prepos, []).append(l)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   498
            script.append(l[4:])
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   499
        elif l.startswith('  '): # results
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   500
            # queue up a list of expected results
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   501
            expected.setdefault(pos, []).append(l[2:])
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   502
        else:
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   503
            # non-command/result - queue up for merged output
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   504
            after.setdefault(pos, []).append(l)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   505
880
0b9f0c42b566 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 878
diff changeset
   506
    t.close()
0b9f0c42b566 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 878
diff changeset
   507
793
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   508
    script.append('echo %s %s $?\n' % (salt, n + 1))
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   509
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   510
    fd, name = tempfile.mkstemp(suffix='hg-tst')
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   511
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   512
    try:
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   513
        for l in script:
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   514
            os.write(fd, l)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   515
        os.close(fd)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   516
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   517
        cmd = '/bin/sh "%s"' % name
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   518
        vlog("# Running", cmd)
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   519
        exitcode, output = run(cmd, options, replacements)
823
ab2ba4e79bed tests: show skip reason instead of "irrelevant" with unified tests, too
Thomas Arendsen Hein <thomas@intevation.de>
parents: 822
diff changeset
   520
        # do not merge output if skipped, return hghave message instead
862
c333552ec003 run-tests: fix --debug for .t tests
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 860
diff changeset
   521
        # similarly, with --debug, output is None
c333552ec003 run-tests: fix --debug for .t tests
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 860
diff changeset
   522
        if exitcode == SKIPPED_STATUS or output is None:
823
ab2ba4e79bed tests: show skip reason instead of "irrelevant" with unified tests, too
Thomas Arendsen Hein <thomas@intevation.de>
parents: 822
diff changeset
   523
            return exitcode, output
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   524
    finally:
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   525
        os.remove(name)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   526
777
cd294ce45931 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 776
diff changeset
   527
    def rematch(el, l):
cd294ce45931 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 776
diff changeset
   528
        try:
799
c20c12c560dd tests: ensure regexes match to the end of the string
Brodie Rao <brodie@bitheap.org>
parents: 798
diff changeset
   529
            # ensure that the regex matches to the end of the string
c20c12c560dd tests: ensure regexes match to the end of the string
Brodie Rao <brodie@bitheap.org>
parents: 798
diff changeset
   530
            return re.match(el + r'\Z', l)
777
cd294ce45931 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 776
diff changeset
   531
        except re.error:
cd294ce45931 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 776
diff changeset
   532
            # el is an invalid regex
cd294ce45931 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 776
diff changeset
   533
            return False
cd294ce45931 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 776
diff changeset
   534
801
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   535
    def globmatch(el, l):
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   536
        # The only supported special characters are * and ?. Escaping is
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   537
        # supported.
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   538
        i, n = 0, len(el)
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   539
        res = ''
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   540
        while i < n:
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   541
            c = el[i]
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   542
            i += 1
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   543
            if c == '\\' and el[i] in '*?\\':
802
630d72ae4f76 tests: various fixes for new unified test pattern format
Matt Mackall <mpm@selenic.com>
parents: 801
diff changeset
   544
                res += el[i - 1:i + 1]
801
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   545
                i += 1
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   546
            elif c == '*':
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   547
                res += '.*'
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   548
            elif c == '?':
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   549
                res += '.'
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   550
            else:
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   551
                res += re.escape(c)
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   552
        return rematch(res, l)
413c6fe6d1e3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 800
diff changeset
   553
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   554
    pos = -1
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   555
    postout = []
793
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   556
    ret = 0
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   557
    for n, l in enumerate(output):
857
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   558
        lout, lcmd = l, None
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   559
        if salt in l:
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   560
            lout, lcmd = l.split(salt, 1)
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   561
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   562
        if lout:
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   563
            if lcmd:
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   564
                lout += ' (no-eol)\n'
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   565
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   566
            el = None
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   567
            if pos in expected and expected[pos]:
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   568
                el = expected[pos].pop(0)
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   569
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   570
            if el == lout: # perfect match (fast)
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   571
                postout.append("  " + lout)
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   572
            elif (el and
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   573
                  (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', lout) or
860
1ea19e827b5b run-test: fixed wrong parenthesis
Erik Zielke <ez@aragost.com>
parents: 858
diff changeset
   574
                   el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', lout)
1ea19e827b5b run-test: fixed wrong parenthesis
Erik Zielke <ez@aragost.com>
parents: 858
diff changeset
   575
                   or el.endswith(" (esc)\n") and
1ea19e827b5b run-test: fixed wrong parenthesis
Erik Zielke <ez@aragost.com>
parents: 858
diff changeset
   576
                      el.decode('string-escape') == l)):
858
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   577
                postout.append("  " + el) # fallback regex/glob/esc match
857
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   578
            else:
858
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   579
                if needescape(lout):
ff1badf6ae7a tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 857
diff changeset
   580
                    lout = stringescape(lout.rstrip('\n')) + " (esc)\n"
857
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   581
                postout.append("  " + lout) # let diff deal with it
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   582
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   583
        if lcmd:
793
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   584
            # add on last return code
857
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   585
            ret = int(lcmd.split()[1])
793
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   586
            if ret != 0:
9cc90e2c826f tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 777
diff changeset
   587
                postout.append("  [%s]\n" % ret)
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   588
            if pos in after:
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   589
                postout += after.pop(pos)
857
7060aa668b7f tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 856
diff changeset
   590
            pos = int(lcmd.split()[0])
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   591
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   592
    if pos in after:
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   593
        postout += after.pop(pos)
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   594
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   595
    return exitcode, postout
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   596
878
e1a93489159d run-tests: only call WIFEXITED on systems it exists
Simon Heimberg <simohe@besonet.ch>
parents: 877
diff changeset
   597
wifexited = getattr(os, "WIFEXITED", lambda x: False)
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   598
def run(cmd, options, replacements):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   599
    """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
   600
    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
   601
    # 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
   602
    if options.debug:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   603
        proc = subprocess.Popen(cmd, shell=True)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   604
        ret = proc.wait()
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   605
        return (ret, None)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   606
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   607
    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
   608
        tochild, fromchild = os.popen4(cmd)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   609
        tochild.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   610
        output = fromchild.read()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   611
        ret = fromchild.close()
866
d51c3fd4e34a code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 862
diff changeset
   612
        if ret is None:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   613
            ret = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   614
    else:
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   615
        proc = Popen4(cmd, options.timeout)
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   616
        def cleanup():
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   617
            try:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   618
                proc.terminate()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   619
            except OSError:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   620
                pass
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   621
            ret = proc.wait()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   622
            if ret == 0:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   623
                ret = signal.SIGTERM << 8
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   624
            killdaemons()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   625
            return ret
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   626
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   627
        output = ''
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   628
        proc.tochild.close()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   629
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   630
        try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   631
            output = proc.fromchild.read()
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   632
        except KeyboardInterrupt:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   633
            vlog('# Handling keyboard interrupt')
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   634
            cleanup()
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   635
            raise
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   636
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   637
        ret = proc.wait()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   638
        if wifexited(ret):
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   639
            ret = os.WEXITSTATUS(ret)
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   640
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   641
        if proc.timeout:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   642
            ret = 'timeout'
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   643
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   644
        if ret:
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   645
            killdaemons()
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   646
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   647
    for s, r in replacements:
852
fb1e8925292d run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 844
diff changeset
   648
        output = re.sub(s, r, output)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   649
    return ret, splitnewlines(output)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   650
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   651
def runone(options, test):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   652
    '''tristate output:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   653
    None -> skipped
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   654
    True -> passed
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   655
    False -> failed'''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   656
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   657
    global results, resultslock
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   658
903
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   659
    testpath = os.path.join(TESTDIR, test)
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   660
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   661
    def result(l, e):
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   662
        resultslock.acquire()
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   663
        results[l].append(e)
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   664
        resultslock.release()
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   665
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   666
    def skip(msg):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   667
        if not options.verbose:
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   668
            result('s', (test, msg))
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   669
        else:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   670
            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
   671
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   672
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   673
    def fail(msg, ret):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   674
        if not options.nodiff:
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   675
            print "\nERROR: %s %s" % (testpath, msg)
910
b8ae2e290420 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 909
diff changeset
   676
        if (not ret and options.interactive
b8ae2e290420 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 909
diff changeset
   677
            and os.path.exists(testpath + ".err")):
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   678
            print "Accept this change? [n] ",
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   679
            answer = sys.stdin.readline().strip()
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   680
            if answer.lower() in "y yes".split():
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   681
                if test.endswith(".t"):
910
b8ae2e290420 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 909
diff changeset
   682
                    rename(testpath + ".err", testpath)
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   683
                else:
910
b8ae2e290420 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 909
diff changeset
   684
                    rename(testpath + ".err", testpath + ".out")
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   685
                return
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   686
        result('f', (test, msg))
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   687
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   688
    def success():
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   689
        result('p', test)
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   690
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   691
    def ignore(msg):
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   692
        result('i', (test, msg))
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   693
903
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   694
    if (test.startswith("test-") and '~' not in test and
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   695
        ('.' not in test or test.endswith('.py') or
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   696
         test.endswith('.bat') or test.endswith('.t'))):
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   697
        if not os.path.exists(test):
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   698
            skip("doesn't exist")
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   699
            return None
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   700
    else:
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   701
        return None # not a supported test, don't record
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
   702
907
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   703
    if options.blacklist:
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   704
        filename = options.blacklist.get(test)
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   705
        if filename is not None:
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   706
            skip("blacklisted")
907
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   707
            return None
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   708
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   709
    if options.retest and not os.path.exists(test + ".err"):
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   710
        ignore("not retesting")
907
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   711
        return None
edf2753d3170 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 906
diff changeset
   712
905
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   713
    if options.keywords:
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   714
        fp = open(test)
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   715
        t = fp.read().lower() + test.lower()
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   716
        fp.close()
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   717
        for k in options.keywords.lower().split():
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   718
            if k in t:
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   719
                break
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   720
            else:
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   721
                ignore("doesn't match keyword")
905
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   722
                return None
66b8706b3112 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 904
diff changeset
   723
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   724
    vlog("# Test", test)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   725
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   726
    # create a fresh hgrc
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   727
    hgrc = open(HGRCPATH, 'w+')
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   728
    hgrc.write('[ui]\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   729
    hgrc.write('slash = True\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   730
    hgrc.write('[defaults]\n')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   731
    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
   732
    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
   733
    hgrc.write('tag = -d "0 0"\n')
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   734
    if options.inotify:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   735
        hgrc.write('[extensions]\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   736
        hgrc.write('inotify=\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   737
        hgrc.write('[inotify]\n')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   738
        hgrc.write('pidfile=%s\n' % DAEMON_PIDS)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   739
        hgrc.write('appendpid=True\n')
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   740
    hgrc.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   741
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   742
    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
   743
    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
   744
    if os.path.exists(err):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   745
        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
   746
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   747
        tf = open(testpath)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   748
        firstline = tf.readline().rstrip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   749
        tf.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   750
    except:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   751
        firstline = ''
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   752
    lctest = test.lower()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   753
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   754
    if lctest.endswith('.py') or firstline == '#!/usr/bin/env python':
775
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   755
        runner = pytest
776
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   756
    elif lctest.endswith('.t'):
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   757
        runner = tsttest
1869efbf104d tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 775
diff changeset
   758
        ref = testpath
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   759
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   760
        # do not try to run non-executable programs
834
5a6898736b1a run-tests.py: remove support for .bat files
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 833
diff changeset
   761
        if not os.access(testpath, os.X_OK):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   762
            return skip("not executable")
775
16f4cb2900fe tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 741
diff changeset
   763
        runner = shtest
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   764
693
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   765
    # Make a tmp subdirectory to work in
895
1a9cd0b534a0 tests: set HOME to the test temp dir (issue2707)
Idan Kamara <idankk86@gmail.com>
parents: 882
diff changeset
   766
    testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
1a9cd0b534a0 tests: set HOME to the test temp dir (issue2707)
Idan Kamara <idankk86@gmail.com>
parents: 882
diff changeset
   767
        os.path.join(HGTMP, test)
1a9cd0b534a0 tests: set HOME to the test temp dir (issue2707)
Idan Kamara <idankk86@gmail.com>
parents: 882
diff changeset
   768
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   769
    os.mkdir(testtmp)
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   770
    os.chdir(testtmp)
693
8428f3bda904 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 692
diff changeset
   771
829
7d66d78e6179 tests: reintroduce ":$HGPORT" in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 826
diff changeset
   772
    ret, out = runner(testpath, options, [
852
fb1e8925292d run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 844
diff changeset
   773
        (re.escape(testtmp), '$TESTTMP'),
fb1e8925292d run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 844
diff changeset
   774
        (r':%s\b' % options.port, ':$HGPORT'),
fb1e8925292d run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 844
diff changeset
   775
        (r':%s\b' % (options.port + 1), ':$HGPORT1'),
fb1e8925292d run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 844
diff changeset
   776
        (r':%s\b' % (options.port + 2), ':$HGPORT2'),
829
7d66d78e6179 tests: reintroduce ":$HGPORT" in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 826
diff changeset
   777
        ])
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   778
    vlog("# Ret was:", ret)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   779
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   780
    mark = '.'
906
0c112b0ab062 run-tests: keep a list of passed tests
Matt Mackall <mpm@selenic.com>
parents: 905
diff changeset
   781
    if ret == 0:
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   782
        success()
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   783
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   784
    skipped = (ret == SKIPPED_STATUS)
741
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   785
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   786
    # 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
   787
    # check test output against it.
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   788
    if options.debug:
866
d51c3fd4e34a code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 862
diff changeset
   789
        refout = None                   # to match "out is None"
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   790
    elif os.path.exists(ref):
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   791
        f = open(ref, "r")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   792
        refout = splitnewlines(f.read())
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   793
        f.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   794
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   795
        refout = []
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   796
741
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   797
    if (ret != 0 or out != refout) and not skipped and not options.debug:
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   798
        # Save errors to a file for diagnosis
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   799
        f = open(err, "wb")
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   800
        for line in out:
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   801
            f.write(line)
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   802
        f.close()
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   803
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   804
    if skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   805
        mark = 's'
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   806
        if out is None:                 # debug mode: nothing to parse
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   807
            missing = ['unknown']
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   808
            failed = None
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   809
        else:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   810
            missing, failed = parsehghaveoutput(out)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   811
        if not missing:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   812
            missing = ['irrelevant']
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   813
        if failed:
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   814
            fail("hghave failed checking for %s" % failed[-1], ret)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   815
            skipped = False
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   816
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   817
            skip(missing[-1])
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   818
    elif ret == 'timeout':
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   819
        mark = 't'
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   820
        fail("timed out", ret)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   821
    elif out != refout:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   822
        mark = '!'
913
ee01b53f9ac9 run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 912
diff changeset
   823
        if ret:
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   824
            fail("output changed and returned error code %d" % ret, ret)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   825
        else:
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   826
            fail("output changed", ret)
899
97ec5d659039 tests: better output on timeouts
Matt Mackall <mpm@selenic.com>
parents: 895
diff changeset
   827
        if ret != 'timeout' and not options.nodiff:
741
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   828
            if options.view:
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   829
                os.system("%s %s %s" % (options.view, ref, err))
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   830
            else:
e5bfe51eeea9 run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 740
diff changeset
   831
                showdiff(refout, out, ref, err)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   832
        ret = 1
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   833
    elif ret:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   834
        mark = '!'
902
fb867941518c run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 899
diff changeset
   835
        fail("returned error code %d" % ret, ret)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   836
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   837
    if not options.verbose:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   838
        sys.stdout.write(mark)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   839
        sys.stdout.flush()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   840
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   841
    killdaemons()
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   842
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   843
    os.chdir(TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   844
    if not options.keep_tmpdir:
826
ac9b63e01e2a tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 824
diff changeset
   845
        shutil.rmtree(testtmp, True)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   846
    if skipped:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   847
        return None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   848
    return ret == 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   849
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   850
_hgpath = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   851
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   852
def _gethgpath():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   853
    """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
   854
    the current Python interpreter."""
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   855
    global _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   856
    if _hgpath is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   857
        return _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   858
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   859
    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
   860
    pipe = os.popen(cmd % PYTHON)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   861
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   862
        _hgpath = pipe.read().strip()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   863
    finally:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   864
        pipe.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   865
    return _hgpath
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   866
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   867
def _checkhglib(verb):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   868
    """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
   869
    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
   870
    expecthg = os.path.join(PYTHONDIR, 'mercurial')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   871
    actualhg = _gethgpath()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   872
    if actualhg != expecthg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   873
        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
   874
                         '         (expected %s)\n'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   875
                         % (verb, actualhg, expecthg))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   876
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   877
def runchildren(options, tests):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   878
    if INST:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   879
        installhg(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   880
        _checkhglib("Testing")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   881
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   882
    optcopy = dict(options.__dict__)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   883
    optcopy['jobs'] = 1
725
212432db2043 Fix --blacklist when --jobs > 1 in run_tests.py.
Ry4an Brase <ry4an-hg@ry4an.org>
parents: 724
diff changeset
   884
    del optcopy['blacklist']
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   885
    if optcopy['with_hg'] is None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   886
        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
   887
    optcopy.pop('anycoverage', None)
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   888
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   889
    opts = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   890
    for opt, value in optcopy.iteritems():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   891
        name = '--' + opt.replace('_', '-')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   892
        if value is True:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   893
            opts.append(name)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   894
        elif value is not None:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   895
            opts.append(name + '=' + str(value))
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
    tests.reverse()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   898
    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
   899
    while tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   900
        for job in jobs:
680
f10a5301d082 many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 674
diff changeset
   901
            if not tests:
f10a5301d082 many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 674
diff changeset
   902
                break
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   903
            job.append(tests.pop())
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   904
    fps = {}
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   905
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   906
    for j, job in enumerate(jobs):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   907
        if not job:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   908
            continue
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   909
        rfd, wfd = os.pipe()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   910
        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
   911
        childtmp = os.path.join(HGTMP, 'child%d' % j)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   912
        childopts += ['--tmpdir', childtmp]
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   913
        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
   914
        vlog(' '.join(cmdline))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   915
        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
   916
        os.close(wfd)
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   917
    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
   918
    failures = 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   919
    tested, skipped, failed = 0, 0, 0
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   920
    skips = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   921
    fails = []
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   922
    while fps:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   923
        pid, status = os.wait()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   924
        fp = fps.pop(pid)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   925
        l = fp.read().splitlines()
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   926
        try:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   927
            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
   928
        except ValueError:
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
   929
            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
   930
        split = -fail or len(l)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   931
        for s in l[3:split]:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   932
            skips.append(s.split(" ", 1))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   933
        for s in l[split:]:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   934
            fails.append(s.split(" ", 1))
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   935
        tested += test
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   936
        skipped += skip
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   937
        failed += fail
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   938
        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
   939
        failures |= status
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   940
    print
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   941
    if not options.noskips:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   942
        for s in skips:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
   943
            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
   944
    for s in fails:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   945
        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
   946
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   947
    _checkhglib("Tested")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   948
    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
   949
        tested, skipped, failed)
718
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   950
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   951
    if options.anycoverage:
88d7be7899ac tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 693
diff changeset
   952
        outputcoverage(options)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   953
    sys.exit(failures != 0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   954
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   955
results = dict(p=[], f=[], s=[], i=[])
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   956
resultslock = threading.Lock()
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   957
909
5ec26580cbb2 run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 908
diff changeset
   958
def runqueue(options, tests, results):
5ec26580cbb2 run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 908
diff changeset
   959
    for test in tests:
912
17e4691cc491 run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 910
diff changeset
   960
        ret = runone(options, test)
909
5ec26580cbb2 run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 908
diff changeset
   961
        if options.first and ret is not None and not ret:
5ec26580cbb2 run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 908
diff changeset
   962
            break
5ec26580cbb2 run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 908
diff changeset
   963
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   964
def runtests(options, tests):
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   965
    global DAEMON_PIDS, HGRCPATH
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   966
    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
   967
    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
   968
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   969
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   970
        if INST:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   971
            installhg(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   972
            _checkhglib("Testing")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   973
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   974
        if options.restart:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   975
            orig = list(tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   976
            while tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   977
                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
   978
                    break
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   979
                tests.pop(0)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   980
            if not tests:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   981
                print "running all tests"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   982
                tests = orig
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   983
909
5ec26580cbb2 run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 908
diff changeset
   984
        runqueue(options, tests, results)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   985
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   986
        failed = len(results['f'])
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   987
        tested = len(results['p']) + failed
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   988
        skipped = len(results['s'])
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   989
        ignored = len(results['i'])
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   990
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   991
        if options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   992
            fp = os.fdopen(options.child, 'w')
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   993
            fp.write('%d\n%d\n%d\n' % (tested, skipped, failed))
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   994
            for s in results['s']:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   995
                fp.write("%s %s\n" % s)
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
   996
            for s in results['f']:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   997
                fp.write("%s %s\n" % s)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   998
            fp.close()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   999
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1000
            print
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
  1001
            for s in results['s']:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1002
                print "Skipped %s: %s" % s
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
  1003
            for s in results['f']:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1004
                print "Failed %s: %s" % s
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1005
            _checkhglib("Tested")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1006
            print "# Ran %d tests, %d skipped, %d failed." % (
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
  1007
                tested, skipped + ignored, failed)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1008
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1009
        if options.anycoverage:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1010
            outputcoverage(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1011
    except KeyboardInterrupt:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1012
        failed = True
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1013
        print "\ninterrupted!"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1014
908
78f81dc655ca run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 907
diff changeset
  1015
    if failed:
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1016
        sys.exit(1)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1017
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1018
def main():
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1019
    (options, args) = parseargs()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1020
    if not options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1021
        os.umask(022)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1022
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1023
        checktools()
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1024
833
a9c6ada32647 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 829
diff changeset
  1025
    if len(args) == 0:
a9c6ada32647 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 829
diff changeset
  1026
        args = os.listdir(".")
a9c6ada32647 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 829
diff changeset
  1027
    args.sort()
a9c6ada32647 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 829
diff changeset
  1028
903
92c48e9ca3a7 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 902
diff changeset
  1029
    tests = args
833
a9c6ada32647 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 829
diff changeset
  1030
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1031
    # 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
  1032
    # the tests produce repeatable output.
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1033
    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
  1034
    os.environ['TZ'] = 'GMT'
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1035
    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
  1036
    os.environ['CDPATH'] = ''
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1037
    os.environ['COLUMNS'] = '80'
719
ad3048630bd8 run-tests: make sure GREP_OPTIONS isn't set
Brodie Rao <brodie@bitheap.org>
parents: 718
diff changeset
  1038
    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
  1039
    os.environ['http_proxy'] = ''
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1040
724
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
  1041
    # 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
  1042
    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
  1043
        if k.startswith('HG_'):
728
5df6643c39e9 run-tests.py: can't remove from os.environ on solaris
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 726
diff changeset
  1044
            # can't remove on solaris
5df6643c39e9 run-tests.py: can't remove from os.environ on solaris
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 726
diff changeset
  1045
            os.environ[k] = ''
724
211fa4b9803d run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 722
diff changeset
  1046
            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
  1047
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1048
    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
  1049
    TESTDIR = os.environ["TESTDIR"] = os.getcwd()
670
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1050
    if options.tmpdir:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1051
        options.keep_tmpdir = True
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1052
        tmpdir = options.tmpdir
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1053
        if os.path.exists(tmpdir):
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1054
            # 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
  1055
            # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1056
            # tmpdir already exists.
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1057
            sys.exit("error: temp dir %r already exists" % tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1058
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1059
            # Automatically removing tmpdir sounds convenient, but could
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1060
            # really annoy anyone in the habit of using "--tmpdir=/tmp"
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1061
            # or "--tmpdir=$HOME".
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1062
            #vlog("# Removing temp dir", tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1063
            #shutil.rmtree(tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1064
        os.makedirs(tmpdir)
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1065
    else:
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1066
        tmpdir = tempfile.mkdtemp('', 'hgtests.')
80d0ed025a02 run-tests.py: update
Christian Ebert <blacktrash@gmx.net>
parents: 562
diff changeset
  1067
    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
  1068
    DAEMON_PIDS = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1069
    HGRCPATH = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1070
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1071
    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
  1072
    os.environ["HGMERGE"] = "internal:merge"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1073
    os.environ["HGUSER"]   = "test"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1074
    os.environ["HGENCODING"] = "ascii"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1075
    os.environ["HGENCODINGMODE"] = "strict"
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1076
    os.environ["HGPORT"] = str(options.port)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1077
    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
  1078
    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
  1079
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1080
    if options.with_hg:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1081
        INST = None
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1082
        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
  1083
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1084
        # 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
  1085
        # 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
  1086
        # "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
  1087
        # 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
  1088
        # ... 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
  1089
        PYTHONDIR = BINDIR
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1090
    else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1091
        INST = os.path.join(HGTMP, "install")
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1092
        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
  1093
        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
  1094
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1095
    os.environ["BINDIR"] = BINDIR
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1096
    os.environ["PYTHON"] = PYTHON
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1097
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1098
    if not options.child:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1099
        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
  1100
        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
  1101
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1102
        # 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
  1103
        # 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
  1104
        # adds an extension to HGRC
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1105
        pypath = [PYTHONDIR, TESTDIR]
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1106
        # 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
  1107
        # 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
  1108
        # 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
  1109
        # 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
  1110
        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
  1111
        if oldpypath:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1112
            pypath.append(oldpypath)
720
8008f7627b2f tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 719
diff changeset
  1113
        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
  1114
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1115
    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
  1116
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1117
    vlog("# Using TESTDIR", TESTDIR)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1118
    vlog("# Using HGTMP", HGTMP)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1119
    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
  1120
    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
  1121
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1122
    try:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1123
        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
  1124
            runchildren(options, tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1125
        else:
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1126
            runtests(options, tests)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1127
    finally:
682
1c7056415039 run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 681
diff changeset
  1128
        time.sleep(1)
562
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1129
        cleanup(options)
b1aa7b64890b Add run-tests.py from main and update README
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
  1130
877
c2ca6e172fd8 run-tests: loadable as module
Simon Heimberg <simohe@besonet.ch>
parents: 866
diff changeset
  1131
if __name__ == '__main__':
c2ca6e172fd8 run-tests: loadable as module
Simon Heimberg <simohe@besonet.ch>
parents: 866
diff changeset
  1132
    main()