tests/run-tests.py
author Augie Fackler <durin42@gmail.com>
Wed, 04 May 2011 10:39:10 -0500
changeset 14192 38e387a64f58
parent 14134 8468ec1109d1
child 14201 57e04ded3da4
permissions -rwxr-xr-x
run-tests.py: correctly handle list options with parallel tasks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     1
#!/usr/bin/env python
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     2
#
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     3
# run-tests.py - Run a set of tests on Mercurial
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     4
#
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     5
# Copyright 2006 Matt Mackall <mpm@selenic.com>
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     6
#
8225
46293a0c7e9f updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents: 8161
diff changeset
     7
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 10154
diff changeset
     8
# GNU General Public License version 2 or any later version.
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     9
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    10
# Modifying this script is tricky because it has many modes:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    11
#   - serial (default) vs parallel (-jN, N > 1)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    12
#   - no coverage (default) vs coverage (-c, -C, -s)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    13
#   - temp install (default) vs specific hg script (--with-hg, --local)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    14
#   - tests are a mix of shell scripts and Python scripts
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    15
#
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    16
# If you change this script, it is recommended that you ensure you
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    17
# haven't broken it by running it in various modes with a representative
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    18
# sample of test scripts.  For example:
8843
eb7b247a98ea kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8724
diff changeset
    19
#
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    20
#  1) serial, no coverage, temp install:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    21
#      ./run-tests.py test-s*
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    22
#  2) serial, no coverage, local hg:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    23
#      ./run-tests.py --local test-s*
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    24
#  3) serial, coverage, temp install:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    25
#      ./run-tests.py -c test-s*
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    26
#  4) serial, coverage, local hg:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    27
#      ./run-tests.py -c --local test-s*      # unsupported
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    28
#  5) parallel, no coverage, temp install:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    29
#      ./run-tests.py -j2 test-s*
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    30
#  6) parallel, no coverage, local hg:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    31
#      ./run-tests.py -j2 --local test-s*
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    32
#  7) parallel, coverage, temp install:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    33
#      ./run-tests.py -j2 -c test-s*          # currently broken
9899
be574a37a8ae run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents: 9707
diff changeset
    34
#  8) parallel, coverage, local install:
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    35
#      ./run-tests.py -j2 -c --local test-s*  # unsupported (and broken)
9899
be574a37a8ae run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents: 9707
diff changeset
    36
#  9) parallel, custom tmp dir:
be574a37a8ae run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents: 9707
diff changeset
    37
#      ./run-tests.py -j2 --tmpdir /tmp/myhgtests
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    38
#
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    39
# (You could use any subset of the tests: test-s* happens to match
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    40
# enough that it's worth doing parallel runs, few enough that it
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    41
# completes fairly quickly, includes both shell and Python scripts, and
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    42
# includes some scripts that run daemon processes.)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
    43
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
    44
from distutils import version
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    45
import difflib
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    46
import errno
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    47
import optparse
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    48
import os
10905
13a1b2fb7ef2 pylint, pyflakes: remove unused or duplicate imports
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10903
diff changeset
    49
import shutil
8280
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    50
import subprocess
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    51
import signal
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    52
import sys
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    53
import tempfile
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    54
import time
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
    55
import re
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
    56
import threading
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    57
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    58
processlock = threading.Lock()
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    59
8280
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    60
closefds = os.name == 'posix'
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    61
def Popen4(cmd, wd, timeout):
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    62
    processlock.acquire()
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    63
    orig = os.getcwd()
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    64
    os.chdir(wd)
14001
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    65
    p = subprocess.Popen(cmd, shell=True, bufsize=-1,
8280
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    66
                         close_fds=closefds,
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    67
                         stdin=subprocess.PIPE, stdout=subprocess.PIPE,
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    68
                         stderr=subprocess.STDOUT)
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    69
    os.chdir(orig)
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    70
    processlock.release()
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
    71
8280
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    72
    p.fromchild = p.stdout
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    73
    p.tochild = p.stdin
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    74
    p.childerr = p.stderr
14001
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    75
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    76
    if timeout:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    77
        p.timeout = False
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    78
        def t():
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    79
            start = time.time()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    80
            while time.time() - start < timeout and p.returncode is None:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    81
                time.sleep(1)
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    82
            p.timeout = True
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    83
            if p.returncode is None:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    84
                try:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    85
                    p.terminate()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    86
                except OSError:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    87
                    pass
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    88
        threading.Thread(target=t).start()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
    89
8280
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    90
    return p
0b02d98d44d0 util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents: 8258
diff changeset
    91
5685
57d29a45ffbc Use skipped: instead of hghave: for skipping tests, use this in test-merge-types
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5524
diff changeset
    92
# reserved exit code to skip test (used by hghave)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
    93
SKIPPED_STATUS = 80
5685
57d29a45ffbc Use skipped: instead of hghave: for skipping tests, use this in test-merge-types
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5524
diff changeset
    94
SKIPPED_PREFIX = 'skipped: '
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
    95
FAILED_PREFIX  = 'hghave check failed: '
8096
a110d7a20f3f run-tests: upper-case global PYTHON variable
Martin Geisler <mg@lazybytes.net>
parents: 8095
diff changeset
    96
PYTHON = sys.executable
10758
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
    97
IMPL_PATH = 'PYTHONPATH'
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
    98
if 'java' in sys.platform:
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
    99
    IMPL_PATH = 'JYTHONPATH'
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   100
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   101
requiredtools = ["python", "diff", "grep", "unzip", "gunzip", "bunzip2", "sed"]
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   102
6366
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
   103
defaults = {
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
   104
    'jobs': ('HGTEST_JOBS', 1),
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
   105
    'timeout': ('HGTEST_TIMEOUT', 180),
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
   106
    'port': ('HGTEST_PORT', 20059),
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
   107
}
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
   108
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   109
def parseargs():
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   110
    parser = optparse.OptionParser("%prog [options] [tests]")
11039
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   111
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   112
    # keep these sorted
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   113
    parser.add_option("--blacklist", action="append",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   114
        help="skip tests listed in the specified blacklist file")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   115
    parser.add_option("-C", "--annotate", action="store_true",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   116
        help="output files annotated with coverage")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   117
    parser.add_option("--child", type="int",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   118
        help="run as child process, summary to given fd")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   119
    parser.add_option("-c", "--cover", action="store_true",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   120
        help="print a test coverage report")
11039
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   121
    parser.add_option("-d", "--debug", action="store_true",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   122
        help="debug mode: write output of test scripts to console"
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   123
             " rather than capturing and diff'ing it (disables timeout)")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   124
    parser.add_option("-f", "--first", action="store_true",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   125
        help="exit on the first test failure")
11039
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   126
    parser.add_option("--inotify", action="store_true",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   127
        help="enable inotify extension when running tests")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   128
    parser.add_option("-i", "--interactive", action="store_true",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   129
        help="prompt to accept changed output")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   130
    parser.add_option("-j", "--jobs", type="int",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   131
        help="number of jobs to run in parallel"
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   132
             " (default: $%s or %d)" % defaults['jobs'])
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   133
    parser.add_option("--keep-tmpdir", action="store_true",
9706
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
   134
        help="keep temporary directory after running tests")
11039
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   135
    parser.add_option("-k", "--keywords",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   136
        help="run tests matching keywords")
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   137
    parser.add_option("-l", "--local", action="store_true",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   138
        help="shortcut for --with-hg=<testdir>/../hg")
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   139
    parser.add_option("-n", "--nodiff", action="store_true",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   140
        help="skip showing test changes")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   141
    parser.add_option("-p", "--port", type="int",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   142
        help="port on which servers should listen"
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   143
             " (default: $%s or %d)" % defaults['port'])
11039
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   144
    parser.add_option("--pure", action="store_true",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   145
        help="use pure Python code instead of C extensions")
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   146
    parser.add_option("-R", "--restart", action="store_true",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   147
        help="restart at last error")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   148
    parser.add_option("-r", "--retest", action="store_true",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   149
        help="retest failed tests")
9580
25858f9e65e8 run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents: 9408
diff changeset
   150
    parser.add_option("-S", "--noskips", action="store_true",
25858f9e65e8 run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents: 9408
diff changeset
   151
        help="don't report skip tests verbosely")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   152
    parser.add_option("-t", "--timeout", type="int",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   153
        help="kill errant tests after TIMEOUT seconds"
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   154
             " (default: $%s or %d)" % defaults['timeout'])
11039
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   155
    parser.add_option("--tmpdir", type="string",
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   156
        help="run tests in the given temporary directory"
cf0a309f6c4d run-tests: sort options
Matt Mackall <mpm@selenic.com>
parents: 11038
diff changeset
   157
             " (implies --keep-tmpdir)")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   158
    parser.add_option("-v", "--verbose", action="store_true",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   159
        help="output verbose messages")
11040
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   160
    parser.add_option("--view", type="string",
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   161
        help="external diff viewer")
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   162
    parser.add_option("--with-hg", type="string",
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   163
        metavar="HG",
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   164
        help="test using specified hg script rather than a "
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   165
             "temporary installation")
9028
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   166
    parser.add_option("-3", "--py3k-warnings", action="store_true",
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   167
        help="enable Py3k warnings on Python 2.6+")
14134
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   168
    parser.add_option('--extra-config-opt', action="append",
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   169
                      help='set the given config opt in the test hgrc')
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   170
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   171
    for option, default in defaults.items():
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   172
        defaults[option] = int(os.environ.get(*default))
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   173
    parser.set_defaults(**defaults)
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   174
    (options, args) = parser.parse_args()
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   175
10758
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
   176
    # jython is always pure
10766
afbcea270bb8 run-tests: force to test pure on pypy as well
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10765
diff changeset
   177
    if 'java' in sys.platform or '__pypy__' in sys.modules:
10765
fd31a3237498 Fix run-tests.py -jX after 2ed667a9dfcb
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10758
diff changeset
   178
        options.pure = True
10758
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
   179
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   180
    if options.with_hg:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   181
        if not (os.path.isfile(options.with_hg) and
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   182
                os.access(options.with_hg, os.X_OK)):
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   183
            parser.error('--with-hg must specify an executable hg script')
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   184
        if not os.path.basename(options.with_hg) == 'hg':
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   185
            sys.stderr.write('warning: --with-hg should specify an hg script')
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   186
    if options.local:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   187
        testdir = os.path.dirname(os.path.realpath(sys.argv[0]))
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   188
        hgbin = os.path.join(os.path.dirname(testdir), 'hg')
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   189
        if not os.access(hgbin, os.X_OK):
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   190
            parser.error('--local specified, but %r not found or not executable'
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   191
                         % hgbin)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   192
        options.with_hg = hgbin
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   193
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   194
    options.anycoverage = options.cover or options.annotate
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   195
    if options.anycoverage:
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   196
        try:
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   197
            import coverage
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   198
            covver = version.StrictVersion(coverage.__version__).version
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   199
            if covver < (3, 3):
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   200
                parser.error('coverage options require coverage 3.3 or later')
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   201
        except ImportError:
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   202
            parser.error('coverage options now require the coverage package')
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   203
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   204
    if options.anycoverage and options.local:
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   205
        # this needs some path mangling somewhere, I guess
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   206
        parser.error("sorry, coverage options do not work when --local "
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   207
                     "is specified")
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   208
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   209
    global vlog
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   210
    if options.verbose:
8671
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   211
        if options.jobs > 1 or options.child is not None:
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   212
            pid = "[%d]" % os.getpid()
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   213
        else:
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   214
            pid = None
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   215
        def vlog(*msg):
14018
7ba2c728cf32 run-tests: add iolock to vlog
Matt Mackall <mpm@selenic.com>
parents: 14006
diff changeset
   216
            iolock.acquire()
8671
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   217
            if pid:
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   218
                print pid,
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   219
            for m in msg:
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   220
                print m,
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   221
            print
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   222
            sys.stdout.flush()
14018
7ba2c728cf32 run-tests: add iolock to vlog
Matt Mackall <mpm@selenic.com>
parents: 14006
diff changeset
   223
            iolock.release()
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   224
    else:
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   225
        vlog = lambda *msg: None
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   226
9394
31203db1b2ac run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9031
diff changeset
   227
    if options.tmpdir:
31203db1b2ac run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9031
diff changeset
   228
        options.tmpdir = os.path.expanduser(options.tmpdir)
31203db1b2ac run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9031
diff changeset
   229
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   230
    if options.jobs < 1:
9408
70bf7f853adc run-tests: standardize on --foo instead of -f/--foo
Martin Geisler <mg@lazybytes.net>
parents: 9407
diff changeset
   231
        parser.error('--jobs must be positive')
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   232
    if options.interactive and options.jobs > 1:
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   233
        print '(--interactive overrides --jobs)'
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   234
        options.jobs = 1
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   235
    if options.interactive and options.debug:
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   236
        parser.error("-i/--interactive and -d/--debug are incompatible")
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   237
    if options.debug:
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   238
        if options.timeout != defaults['timeout']:
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   239
            sys.stderr.write(
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   240
                'warning: --timeout option ignored with --debug\n')
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   241
        options.timeout = 0
9028
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   242
    if options.py3k_warnings:
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   243
        if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0):
9408
70bf7f853adc run-tests: standardize on --foo instead of -f/--foo
Martin Geisler <mg@lazybytes.net>
parents: 9407
diff changeset
   244
            parser.error('--py3k-warnings can only be used on Python 2.6+')
9959
b37b060d84c7 run-tests: add a "--blacklist target" option to skip predefined test lists
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9958
diff changeset
   245
    if options.blacklist:
b37b060d84c7 run-tests: add a "--blacklist target" option to skip predefined test lists
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9958
diff changeset
   246
        blacklist = dict()
10300
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   247
        for filename in options.blacklist:
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   248
            try:
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   249
                path = os.path.expanduser(os.path.expandvars(filename))
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   250
                f = open(path, "r")
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   251
            except IOError, err:
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   252
                if err.errno != errno.ENOENT:
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   253
                    raise
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   254
                print "warning: no such blacklist file: %s" % filename
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   255
                continue
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   256
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   257
            for line in f.readlines():
13539
b3330b8e1e6f run-tests: handle mixed comment lines in blacklists
Patrick Mezard <pmezard@gmail.com>
parents: 13400
diff changeset
   258
                line = line.split('#', 1)[0].strip()
b3330b8e1e6f run-tests: handle mixed comment lines in blacklists
Patrick Mezard <pmezard@gmail.com>
parents: 13400
diff changeset
   259
                if line:
10300
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   260
                    blacklist[line] = filename
c437745f50ec run-tests: split tests/blacklist in tests/blacklists/*
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 10282
diff changeset
   261
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13348
diff changeset
   262
            f.close()
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13348
diff changeset
   263
9959
b37b060d84c7 run-tests: add a "--blacklist target" option to skip predefined test lists
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9958
diff changeset
   264
        options.blacklist = blacklist
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   265
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   266
    return (options, args)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   267
5800
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   268
def rename(src, dst):
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   269
    """Like os.rename(), trade atomicity and opened files friendliness
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   270
    for existing destination support.
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   271
    """
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   272
    shutil.copy(src, dst)
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   273
    os.remove(src)
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   274
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   275
def splitnewlines(text):
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   276
    '''like str.splitlines, but only split on newlines.
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   277
    keep line endings.'''
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   278
    i = 0
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   279
    lines = []
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   280
    while True:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   281
        n = text.find('\n', i)
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   282
        if n == -1:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   283
            last = text[i:]
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   284
            if last:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   285
                lines.append(last)
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   286
            return lines
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   287
        lines.append(text[i:n + 1])
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   288
        i = n + 1
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   289
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   290
def parsehghaveoutput(lines):
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   291
    '''Parse hghave log lines.
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   292
    Return tuple of lists (missing, failed):
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   293
      * the missing/unknown features
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   294
      * the features for which existence check failed'''
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   295
    missing = []
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   296
    failed = []
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   297
    for line in lines:
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   298
        if line.startswith(SKIPPED_PREFIX):
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   299
            line = line.splitlines()[0]
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   300
            missing.append(line[len(SKIPPED_PREFIX):])
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   301
        elif line.startswith(FAILED_PREFIX):
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   302
            line = line.splitlines()[0]
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   303
            failed.append(line[len(FAILED_PREFIX):])
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   304
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   305
    return missing, failed
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   306
10088
ec8304e66ea5 run-tests.py: Show paths to failing tests, .err and .out
Mads Kiilerich <mads@kiilerich.com>
parents: 10030
diff changeset
   307
def showdiff(expected, output, ref, err):
14062
643381286e0c run-tests: print a new line before writing the diff
Idan Kamara <idankk86@gmail.com>
parents: 14037
diff changeset
   308
    print
10088
ec8304e66ea5 run-tests.py: Show paths to failing tests, .err and .out
Mads Kiilerich <mads@kiilerich.com>
parents: 10030
diff changeset
   309
    for line in difflib.unified_diff(expected, output, ref, err):
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   310
        sys.stdout.write(line)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   311
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   312
def findprogram(program):
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   313
    """Search PATH for a executable program"""
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   314
    for p in os.environ.get('PATH', os.defpath).split(os.pathsep):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   315
        name = os.path.join(p, program)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   316
        if os.access(name, os.X_OK):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   317
            return name
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   318
    return None
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   319
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   320
def checktools():
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   321
    # Before we go any further, check for pre-requisite tools
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   322
    # stuff from coreutils (cat, rm, etc) are not tested
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   323
    for p in requiredtools:
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   324
        if os.name == 'nt':
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   325
            p += '.exe'
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   326
        found = findprogram(p)
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   327
        if found:
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   328
            vlog("# Found prerequisite", p, "at", found)
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   329
        else:
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   330
            print "WARNING: Did not find prerequisite tool: "+p
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   331
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   332
def killdaemons():
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   333
    # Kill off any leftover daemon processes
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   334
    try:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   335
        fp = open(DAEMON_PIDS)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   336
        for line in fp:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   337
            try:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   338
                pid = int(line)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   339
            except ValueError:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   340
                continue
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   341
            try:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   342
                os.kill(pid, 0)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   343
                vlog('# Killing daemon process %d' % pid)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   344
                os.kill(pid, signal.SIGTERM)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   345
                time.sleep(0.25)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   346
                os.kill(pid, 0)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   347
                vlog('# Daemon process %d is stuck - really killing it' % pid)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   348
                os.kill(pid, signal.SIGKILL)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   349
            except OSError, err:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   350
                if err.errno != errno.ESRCH:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   351
                    raise
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   352
        fp.close()
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   353
        os.unlink(DAEMON_PIDS)
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   354
    except IOError:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   355
        pass
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   356
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   357
def cleanup(options):
6208
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   358
    if not options.keep_tmpdir:
8671
a434c94b48e7 run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents: 8651
diff changeset
   359
        vlog("# Cleaning up HGTMP", HGTMP)
6208
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   360
        shutil.rmtree(HGTMP, True)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   361
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   362
def usecorrectpython():
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   363
    # some tests run python interpreter. they must use same
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   364
    # interpreter we use or bad things will happen.
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   365
    exedir, exename = os.path.split(sys.executable)
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   366
    if exename == 'python':
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   367
        path = findprogram('python')
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   368
        if os.path.dirname(path) == exedir:
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   369
            return
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   370
    vlog('# Making python executable in test path use correct Python')
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   371
    mypython = os.path.join(BINDIR, 'python')
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   372
    try:
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   373
        os.symlink(sys.executable, mypython)
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   374
    except AttributeError:
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   375
        # windows fallback
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   376
        shutil.copyfile(sys.executable, mypython)
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   377
        shutil.copymode(sys.executable, mypython)
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2989
diff changeset
   378
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   379
def installhg(options):
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   380
    vlog("# Performing temporary installation of HG")
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   381
    installerrs = os.path.join("tests", "install.err")
7723
a343cd25e425 run-tests: add --pure flag for using pure Python modules
Martin Geisler <mg@daimi.au.dk>
parents: 7529
diff changeset
   382
    pure = options.pure and "--pure" or ""
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   383
5267
b817d17c7ee5 Make run-tests.py work when invoked outside of tests.
Brendan Cully <brendan@kublai.com>
parents: 5251
diff changeset
   384
    # Run installer in hg root
8943
09ff905cdc86 run-tests: use os.path.realpath() to find hg's setup.py.
Greg Ward <greg-hg@gerg.ca>
parents: 8843
diff changeset
   385
    script = os.path.realpath(sys.argv[0])
09ff905cdc86 run-tests: use os.path.realpath() to find hg's setup.py.
Greg Ward <greg-hg@gerg.ca>
parents: 8843
diff changeset
   386
    hgroot = os.path.dirname(os.path.dirname(script))
09ff905cdc86 run-tests: use os.path.realpath() to find hg's setup.py.
Greg Ward <greg-hg@gerg.ca>
parents: 8843
diff changeset
   387
    os.chdir(hgroot)
9905
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   388
    nohome = '--home=""'
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   389
    if os.name == 'nt':
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   390
        # The --home="" trick works only on OS where os.sep == '/'
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   391
        # because of a distutils convert_path() fast-path. Avoid it at
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   392
        # least on Windows for now, deal with .pydistutils.cfg bugs
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   393
        # when they happen.
95517eb3c9a7 run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents: 9902
diff changeset
   394
        nohome = ''
7723
a343cd25e425 run-tests: add --pure flag for using pure Python modules
Martin Geisler <mg@daimi.au.dk>
parents: 7529
diff changeset
   395
    cmd = ('%s setup.py %s clean --all'
12502
41f2fa72fa82 run-tests: move build/ directory to HGTMP
Martin Geisler <mg@lazybytes.net>
parents: 12377
diff changeset
   396
           ' build --build-base="%s"'
7139
bcbba59e233d run-tests.py: use --prefix instead of --home
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7018
diff changeset
   397
           ' install --force --prefix="%s" --install-lib="%s"'
10030
cbc93d8ed46a run-tests: backout d7c23f4a14c7
Martin Geisler <mg@lazybytes.net>
parents: 10020
diff changeset
   398
           ' --install-scripts="%s" %s >%s 2>&1'
12502
41f2fa72fa82 run-tests: move build/ directory to HGTMP
Martin Geisler <mg@lazybytes.net>
parents: 12377
diff changeset
   399
           % (sys.executable, pure, os.path.join(HGTMP, "build"),
41f2fa72fa82 run-tests: move build/ directory to HGTMP
Martin Geisler <mg@lazybytes.net>
parents: 12377
diff changeset
   400
              INST, PYTHONDIR, BINDIR, nohome, installerrs))
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   401
    vlog("# Running", cmd)
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   402
    if os.system(cmd) == 0:
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   403
        if not options.verbose:
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   404
            os.remove(installerrs)
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   405
    else:
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   406
        f = open(installerrs)
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   407
        for line in f:
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   408
            print line,
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   409
        f.close()
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   410
        sys.exit(1)
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
   411
    os.chdir(TESTDIR)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   412
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   413
    usecorrectpython()
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   414
7172
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   415
    vlog("# Installing dummy diffstat")
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   416
    f = open(os.path.join(BINDIR, 'diffstat'), 'w')
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   417
    f.write('#!' + sys.executable + '\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   418
            'import sys\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   419
            'files = 0\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   420
            'for line in sys.stdin:\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   421
            '    if line.startswith("diff "):\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   422
            '        files += 1\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   423
            'sys.stdout.write("files patched: %d\\n" % files)\n')
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   424
    f.close()
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   425
    os.chmod(os.path.join(BINDIR, 'diffstat'), 0700)
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   426
9028
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   427
    if options.py3k_warnings and not options.anycoverage:
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   428
        vlog("# Updating hg command to enable Py3k Warnings switch")
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   429
        f = open(os.path.join(BINDIR, 'hg'), 'r')
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   430
        lines = [line.rstrip() for line in f]
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   431
        lines[0] += ' -3'
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   432
        f.close()
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   433
        f = open(os.path.join(BINDIR, 'hg'), 'w')
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   434
        for line in lines:
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   435
            f.write(line + '\n')
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   436
        f.close()
bea567ae3ff6 tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents: 8943
diff changeset
   437
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   438
    if options.anycoverage:
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   439
        custom = os.path.join(TESTDIR, 'sitecustomize.py')
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   440
        target = os.path.join(PYTHONDIR, 'sitecustomize.py')
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   441
        vlog('# Installing coverage trigger to %s' % target)
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   442
        shutil.copyfile(custom, target)
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   443
        rc = os.path.join(TESTDIR, '.coveragerc')
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   444
        vlog('# Installing coverage rc to %s' % rc)
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   445
        os.environ['COVERAGE_PROCESS_START'] = rc
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   446
        fn = os.path.join(INST, '..', '.coverage')
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   447
        os.environ['COVERAGE_FILE'] = fn
8092
c49578c5122f run-tests: move _hgpath() up so it's not in the middle of the main program.
Greg Ward <greg-hg@gerg.ca>
parents: 8091
diff changeset
   448
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   449
def outputcoverage(options):
8620
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   450
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   451
    vlog('# Producing coverage report')
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   452
    os.chdir(PYTHONDIR)
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   453
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   454
    def covrun(*args):
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   455
        cmd = 'coverage %s' % ' '.join(args)
8620
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   456
        vlog('# Running: %s' % cmd)
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   457
        os.system(cmd)
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   458
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   459
    if options.child:
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   460
        return
8620
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   461
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   462
    covrun('-c')
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   463
    omit = ','.join([BINDIR, TESTDIR])
8620
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   464
    covrun('-i', '-r', '"--omit=%s"' % omit) # report
2145
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   465
    if options.annotate:
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   466
        adir = os.path.join(TESTDIR, 'annotated')
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   467
        if not os.path.isdir(adir):
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   468
            os.mkdir(adir)
8620
b38f275bb5c2 tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 8592
diff changeset
   469
        covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit)
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   470
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   471
def pytest(test, wd, options, replacements):
11740
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   472
    py3kswitch = options.py3k_warnings and ' -3' or ''
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   473
    cmd = '%s%s "%s"' % (PYTHON, py3kswitch, test)
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   474
    vlog("# Running", cmd)
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   475
    return run(cmd, wd, options, replacements)
11740
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   476
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   477
def shtest(test, wd, options, replacements):
11740
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   478
    cmd = '"%s"' % test
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   479
    vlog("# Running", cmd)
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   480
    return run(cmd, wd, options, replacements)
11740
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   481
12941
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   482
needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   483
escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   484
escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256))
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   485
escapemap.update({'\\': '\\\\', '\r': r'\r'})
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   486
def escapef(m):
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   487
    return escapemap[m.group(0)]
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   488
def stringescape(s):
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   489
    return escapesub(escapef, s)
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   490
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   491
def tsttest(test, wd, options, replacements):
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   492
    t = open(test)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   493
    out = []
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   494
    script = []
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   495
    salt = "SALT" + str(time.time())
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   496
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   497
    pos = prepos = -1
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   498
    after = {}
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   499
    expected = {}
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   500
    for n, l in enumerate(t):
12934
ea7ad8c3988a tests: handle .t files without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12895
diff changeset
   501
        if not l.endswith('\n'):
ea7ad8c3988a tests: handle .t files without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12895
diff changeset
   502
            l += '\n'
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   503
        if l.startswith('  $ '): # commands
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   504
            after.setdefault(pos, []).append(l)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   505
            prepos = pos
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   506
            pos = n
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   507
            script.append('echo %s %s $?\n' % (salt, n))
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   508
            script.append(l[4:])
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   509
        elif l.startswith('  > '): # continuations
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   510
            after.setdefault(prepos, []).append(l)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   511
            script.append(l[4:])
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   512
        elif l.startswith('  '): # results
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   513
            # queue up a list of expected results
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   514
            expected.setdefault(pos, []).append(l[2:])
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   515
        else:
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   516
            # non-command/result - queue up for merged output
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   517
            after.setdefault(pos, []).append(l)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   518
13400
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13348
diff changeset
   519
    t.close()
14f3795a5ed7 explicitly close files
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 13348
diff changeset
   520
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   521
    script.append('echo %s %s $?\n' % (salt, n + 1))
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   522
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   523
    fd, name = tempfile.mkstemp(suffix='hg-tst')
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   524
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   525
    try:
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   526
        for l in script:
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   527
            os.write(fd, l)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   528
        os.close(fd)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   529
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   530
        cmd = '/bin/sh "%s"' % name
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   531
        vlog("# Running", cmd)
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   532
        exitcode, output = run(cmd, wd, options, replacements)
12573
be4b0a397470 tests: show skip reason instead of "irrelevant" with unified tests, too
Thomas Arendsen Hein <thomas@intevation.de>
parents: 12502
diff changeset
   533
        # do not merge output if skipped, return hghave message instead
13002
6747d4a5c45d run-tests: fix --debug for .t tests
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12955
diff changeset
   534
        # similarly, with --debug, output is None
6747d4a5c45d run-tests: fix --debug for .t tests
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 12955
diff changeset
   535
        if exitcode == SKIPPED_STATUS or output is None:
12573
be4b0a397470 tests: show skip reason instead of "irrelevant" with unified tests, too
Thomas Arendsen Hein <thomas@intevation.de>
parents: 12502
diff changeset
   536
            return exitcode, output
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   537
    finally:
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   538
        os.remove(name)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   539
11781
6f59154fb604 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11741
diff changeset
   540
    def rematch(el, l):
6f59154fb604 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11741
diff changeset
   541
        try:
12374
4e7dd28db0dd tests: ensure regexes match to the end of the string
Brodie Rao <brodie@bitheap.org>
parents: 12373
diff changeset
   542
            # ensure that the regex matches to the end of the string
4e7dd28db0dd tests: ensure regexes match to the end of the string
Brodie Rao <brodie@bitheap.org>
parents: 12373
diff changeset
   543
            return re.match(el + r'\Z', l)
11781
6f59154fb604 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11741
diff changeset
   544
        except re.error:
6f59154fb604 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11741
diff changeset
   545
            # el is an invalid regex
6f59154fb604 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11741
diff changeset
   546
            return False
6f59154fb604 tests: catch re.error if test line is not a valid regular expression
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 11741
diff changeset
   547
12376
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   548
    def globmatch(el, l):
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   549
        # The only supported special characters are * and ?. Escaping is
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   550
        # supported.
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   551
        i, n = 0, len(el)
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   552
        res = ''
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   553
        while i < n:
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   554
            c = el[i]
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   555
            i += 1
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   556
            if c == '\\' and el[i] in '*?\\':
12377
a5b77eb0409b tests: various fixes for new unified test pattern format
Matt Mackall <mpm@selenic.com>
parents: 12376
diff changeset
   557
                res += el[i - 1:i + 1]
12376
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   558
                i += 1
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   559
            elif c == '*':
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   560
                res += '.*'
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   561
            elif c == '?':
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   562
                res += '.'
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   563
            else:
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   564
                res += re.escape(c)
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   565
        return rematch(res, l)
97ffc68f71d3 tests: add glob matching for unified tests
Brodie Rao <brodie@bitheap.org>
parents: 12375
diff changeset
   566
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   567
    pos = -1
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   568
    postout = []
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   569
    ret = 0
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   570
    for n, l in enumerate(output):
12940
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   571
        lout, lcmd = l, None
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   572
        if salt in l:
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   573
            lout, lcmd = l.split(salt, 1)
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   574
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   575
        if lout:
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   576
            if lcmd:
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   577
                lout += ' (no-eol)\n'
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   578
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   579
            el = None
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   580
            if pos in expected and expected[pos]:
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   581
                el = expected[pos].pop(0)
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   582
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   583
            if el == lout: # perfect match (fast)
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   584
                postout.append("  " + lout)
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   585
            elif (el and
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   586
                  (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', lout) or
12955
158ca54a79cc run-test: fixed wrong parenthesis
Erik Zielke <ez@aragost.com>
parents: 12941
diff changeset
   587
                   el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', lout)
158ca54a79cc run-test: fixed wrong parenthesis
Erik Zielke <ez@aragost.com>
parents: 12941
diff changeset
   588
                   or el.endswith(" (esc)\n") and
158ca54a79cc run-test: fixed wrong parenthesis
Erik Zielke <ez@aragost.com>
parents: 12941
diff changeset
   589
                      el.decode('string-escape') == l)):
12941
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   590
                postout.append("  " + el) # fallback regex/glob/esc match
12940
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   591
            else:
12941
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   592
                if needescape(lout):
b911cb80c671 tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents: 12940
diff changeset
   593
                    lout = stringescape(lout.rstrip('\n')) + " (esc)\n"
12940
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   594
                postout.append("  " + lout) # let diff deal with it
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   595
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   596
        if lcmd:
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   597
            # add on last return code
12940
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   598
            ret = int(lcmd.split()[1])
12316
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   599
            if ret != 0:
4134686b83e1 tests: add exit codes to unified tests
Matt Mackall <mpm@selenic.com>
parents: 11781
diff changeset
   600
                postout.append("  [%s]\n" % ret)
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   601
            if pos in after:
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   602
                postout += after.pop(pos)
12940
518dd70d1a6e tests: (no-eol) markup for command output without trailing LF
Mads Kiilerich <mads@kiilerich.com>
parents: 12934
diff changeset
   603
            pos = int(lcmd.split()[0])
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   604
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   605
    if pos in after:
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   606
        postout += after.pop(pos)
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   607
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   608
    return exitcode, postout
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   609
13348
31fdb04cb5e8 run-tests: only call WIFEXITED on systems it exists
Simon Heimberg <simohe@besonet.ch>
parents: 13347
diff changeset
   610
wifexited = getattr(os, "WIFEXITED", lambda x: False)
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   611
def run(cmd, wd, options, replacements):
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   612
    """Run command in a sub-process, capturing the output (stdout and stderr).
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   613
    Return a tuple (exitcode, output).  output is None in debug mode."""
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   614
    # TODO: Use subprocess.Popen if we're running on Python 2.4
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   615
    if options.debug:
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   616
        proc = subprocess.Popen(cmd, shell=True)
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   617
        ret = proc.wait()
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   618
        return (ret, None)
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   619
7792
cf427b04d5c0 tests: use same popen strategy for jython as for nt
Frank Wierzbicki <fwierzbicki@gmail.com>
parents: 7785
diff changeset
   620
    if os.name == 'nt' or sys.platform.startswith('java'):
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   621
        tochild, fromchild = os.popen4(cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   622
        tochild.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   623
        output = fromchild.read()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   624
        ret = fromchild.close()
13031
3da456d0c885 code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 13002
diff changeset
   625
        if ret is None:
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   626
            ret = 0
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   627
    else:
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   628
        proc = Popen4(cmd, wd, options.timeout)
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   629
        def cleanup():
14001
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   630
            try:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   631
                proc.terminate()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   632
            except OSError:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   633
                pass
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   634
            ret = proc.wait()
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   635
            if ret == 0:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   636
                ret = signal.SIGTERM << 8
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   637
            killdaemons()
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   638
            return ret
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   639
14001
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   640
        output = ''
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   641
        proc.tochild.close()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   642
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   643
        try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   644
            output = proc.fromchild.read()
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   645
        except KeyboardInterrupt:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   646
            vlog('# Handling keyboard interrupt')
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   647
            cleanup()
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   648
            raise
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   649
14001
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   650
        ret = proc.wait()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   651
        if wifexited(ret):
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   652
            ret = os.WEXITSTATUS(ret)
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   653
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   654
        if proc.timeout:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   655
            ret = 'timeout'
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   656
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   657
        if ret:
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   658
            killdaemons()
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   659
12639
236058a65cb4 tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 12621
diff changeset
   660
    for s, r in replacements:
12895
53cfde2b3cf9 run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 12721
diff changeset
   661
        output = re.sub(s, r, output)
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   662
    return ret, splitnewlines(output)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   663
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   664
def runone(options, test):
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   665
    '''tristate output:
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   666
    None -> skipped
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   667
    True -> passed
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   668
    False -> failed'''
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   669
14002
a738c30d4b18 run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents: 14001
diff changeset
   670
    global results, resultslock, iolock
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   671
13989
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   672
    testpath = os.path.join(TESTDIR, test)
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   673
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   674
    def result(l, e):
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   675
        resultslock.acquire()
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   676
        results[l].append(e)
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   677
        resultslock.release()
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   678
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   679
    def skip(msg):
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   680
        if not options.verbose:
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   681
            result('s', (test, msg))
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   682
        else:
14003
ba734ff5cadd run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents: 14002
diff changeset
   683
            iolock.acquire()
10088
ec8304e66ea5 run-tests.py: Show paths to failing tests, .err and .out
Mads Kiilerich <mads@kiilerich.com>
parents: 10030
diff changeset
   684
            print "\nSkipping %s: %s" % (testpath, msg)
14003
ba734ff5cadd run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents: 14002
diff changeset
   685
            iolock.release()
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   686
        return None
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   687
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   688
    def fail(msg, ret):
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   689
        if not options.nodiff:
14003
ba734ff5cadd run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents: 14002
diff changeset
   690
            iolock.acquire()
10088
ec8304e66ea5 run-tests.py: Show paths to failing tests, .err and .out
Mads Kiilerich <mads@kiilerich.com>
parents: 10030
diff changeset
   691
            print "\nERROR: %s %s" % (testpath, msg)
14003
ba734ff5cadd run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents: 14002
diff changeset
   692
            iolock.release()
13999
8f9478be9a94 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 13995
diff changeset
   693
        if (not ret and options.interactive
8f9478be9a94 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 13995
diff changeset
   694
            and os.path.exists(testpath + ".err")):
14003
ba734ff5cadd run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents: 14002
diff changeset
   695
            iolock.acquire()
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   696
            print "Accept this change? [n] ",
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   697
            answer = sys.stdin.readline().strip()
14003
ba734ff5cadd run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents: 14002
diff changeset
   698
            iolock.release()
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   699
            if answer.lower() in "y yes".split():
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   700
                if test.endswith(".t"):
13999
8f9478be9a94 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 13995
diff changeset
   701
                    rename(testpath + ".err", testpath)
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   702
                else:
13999
8f9478be9a94 run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents: 13995
diff changeset
   703
                    rename(testpath + ".err", testpath + ".out")
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   704
                return
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   705
        result('f', (test, msg))
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
   706
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
   707
    def success():
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   708
        result('p', test)
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
   709
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
   710
    def ignore(msg):
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   711
        result('i', (test, msg))
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   712
13989
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   713
    if (test.startswith("test-") and '~' not in test and
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   714
        ('.' not in test or test.endswith('.py') or
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   715
         test.endswith('.bat') or test.endswith('.t'))):
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   716
        if not os.path.exists(test):
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   717
            skip("doesn't exist")
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   718
            return None
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   719
    else:
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   720
        return None # not a supported test, don't record
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
   721
13993
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   722
    if options.blacklist:
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   723
        filename = options.blacklist.get(test)
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   724
        if filename is not None:
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   725
            skip("blacklisted")
13993
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   726
            return None
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   727
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   728
    if options.retest and not os.path.exists(test + ".err"):
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
   729
        ignore("not retesting")
13993
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   730
        return None
174d0a113757 run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents: 13992
diff changeset
   731
13991
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   732
    if options.keywords:
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   733
        fp = open(test)
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   734
        t = fp.read().lower() + test.lower()
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   735
        fp.close()
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   736
        for k in options.keywords.lower().split():
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   737
            if k in t:
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   738
                break
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   739
            else:
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
   740
                ignore("doesn't match keyword")
13991
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   741
                return None
8cfe191e2ce4 run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents: 13990
diff changeset
   742
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   743
    vlog("# Test", test)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   744
2989
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   745
    # create a fresh hgrc
9031
3b76321aa0de compat: use open() instead of file() everywhere
Alejandro Santos <alejolp@alejolp.com>
parents: 9028
diff changeset
   746
    hgrc = open(HGRCPATH, 'w+')
4529
860478527568 run-tests.py: set ui.slash = True
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4387
diff changeset
   747
    hgrc.write('[ui]\n')
860478527568 run-tests.py: set ui.slash = True
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4387
diff changeset
   748
    hgrc.write('slash = True\n')
5524
453acf64f71f run-tests.py: add a default --date "0 0" argument to commit et al
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5518
diff changeset
   749
    hgrc.write('[defaults]\n')
453acf64f71f run-tests.py: add a default --date "0 0" argument to commit et al
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5518
diff changeset
   750
    hgrc.write('backout = -d "0 0"\n')
453acf64f71f run-tests.py: add a default --date "0 0" argument to commit et al
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5518
diff changeset
   751
    hgrc.write('commit = -d "0 0"\n')
453acf64f71f run-tests.py: add a default --date "0 0" argument to commit et al
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5518
diff changeset
   752
    hgrc.write('tag = -d "0 0"\n')
9958
777c1df76ef4 run-tests: add --inotify option to test runner
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9940
diff changeset
   753
    if options.inotify:
777c1df76ef4 run-tests: add --inotify option to test runner
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9940
diff changeset
   754
        hgrc.write('[extensions]\n')
777c1df76ef4 run-tests: add --inotify option to test runner
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9940
diff changeset
   755
        hgrc.write('inotify=\n')
777c1df76ef4 run-tests: add --inotify option to test runner
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9940
diff changeset
   756
        hgrc.write('[inotify]\n')
777c1df76ef4 run-tests: add --inotify option to test runner
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9940
diff changeset
   757
        hgrc.write('pidfile=%s\n' % DAEMON_PIDS)
10013
b2e87fde6806 run-tests: --inotify: use inotify.appendpid to append pids to $DAEMON_PIDS
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 9959
diff changeset
   758
        hgrc.write('appendpid=True\n')
14134
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   759
    if options.extra_config_opt:
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   760
        for opt in options.extra_config_opt:
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   761
            section, key = opt.split('.', 1)
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   762
            assert '=' in key, ('extra config opt %s must '
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   763
                                'have an = for assignment' % opt)
8468ec1109d1 run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents: 14062
diff changeset
   764
            hgrc.write('[%s]\n%s\n' % (section, key))
2989
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   765
    hgrc.close()
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   766
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   767
    ref = os.path.join(TESTDIR, test+".out")
10406
6586a6889f66 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 10336
diff changeset
   768
    err = os.path.join(TESTDIR, test+".err")
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   769
    if os.path.exists(err):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   770
        os.remove(err)       # Remove any previous output files
4321
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   771
    try:
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   772
        tf = open(testpath)
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   773
        firstline = tf.readline().rstrip()
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   774
        tf.close()
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   775
    except:
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   776
        firstline = ''
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   777
    lctest = test.lower()
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   778
4321
99184c6fd88f run-tests.py: use coverage.py with "#!/usr/bin/env python" tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4320
diff changeset
   779
    if lctest.endswith('.py') or firstline == '#!/usr/bin/env python':
11740
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   780
        runner = pytest
11741
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   781
    elif lctest.endswith('.t'):
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   782
        runner = tsttest
431e2bf37ae7 tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents: 11740
diff changeset
   783
        ref = testpath
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   784
    else:
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   785
        # do not try to run non-executable programs
12678
61642a4679e9 run-tests.py: remove support for .bat files
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12677
diff changeset
   786
        if not os.access(testpath, os.X_OK):
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   787
            return skip("not executable")
11740
e5c79e31feb6 tests: move script execution in runner helpers
Matt Mackall <mpm@selenic.com>
parents: 11040
diff changeset
   788
        runner = shtest
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   789
10406
6586a6889f66 run-tests.py: skipped tests shouldn't change working directory
Mads Kiilerich <mads@kiilerich.com>
parents: 10336
diff changeset
   790
    # Make a tmp subdirectory to work in
13764
8ed67e44c71c tests: set HOME to the test temp dir (issue2707)
Idan Kamara <idankk86@gmail.com>
parents: 13539
diff changeset
   791
    testtmp = os.environ["TESTTMP"] = os.environ["HOME"] = \
8ed67e44c71c tests: set HOME to the test temp dir (issue2707)
Idan Kamara <idankk86@gmail.com>
parents: 13539
diff changeset
   792
        os.path.join(HGTMP, test)
8ed67e44c71c tests: set HOME to the test temp dir (issue2707)
Idan Kamara <idankk86@gmail.com>
parents: 13539
diff changeset
   793
12639
236058a65cb4 tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 12621
diff changeset
   794
    os.mkdir(testtmp)
14019
fbbd5f91d5e1 run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents: 14018
diff changeset
   795
    ret, out = runner(testpath, testtmp, options, [
12895
53cfde2b3cf9 run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 12721
diff changeset
   796
        (re.escape(testtmp), '$TESTTMP'),
53cfde2b3cf9 run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 12721
diff changeset
   797
        (r':%s\b' % options.port, ':$HGPORT'),
53cfde2b3cf9 run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 12721
diff changeset
   798
        (r':%s\b' % (options.port + 1), ':$HGPORT1'),
53cfde2b3cf9 run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents: 12721
diff changeset
   799
        (r':%s\b' % (options.port + 2), ':$HGPORT2'),
12643
d08bb64888bc tests: reintroduce ":$HGPORT" in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 12639
diff changeset
   800
        ])
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   801
    vlog("# Ret was:", ret)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   802
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   803
    mark = '.'
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   804
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   805
    skipped = (ret == SKIPPED_STATUS)
11040
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   806
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   807
    # If we're not in --debug mode and reference output file exists,
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   808
    # check test output against it.
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   809
    if options.debug:
13031
3da456d0c885 code style: prefer 'is' and 'is not' tests with singletons
Martin Geisler <mg@aragost.com>
parents: 13002
diff changeset
   810
        refout = None                   # to match "out is None"
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   811
    elif os.path.exists(ref):
2213
6f76a479ae51 run-tests.py must print changed test output no matter what exit code is.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2183
diff changeset
   812
        f = open(ref, "r")
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   813
        refout = splitnewlines(f.read())
2213
6f76a479ae51 run-tests.py must print changed test output no matter what exit code is.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2183
diff changeset
   814
        f.close()
2246
3fd603eb6add run-tests.py: print diff if reference output not existing.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2213
diff changeset
   815
    else:
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   816
        refout = []
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   817
11040
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   818
    if (ret != 0 or out != refout) and not skipped and not options.debug:
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   819
        # Save errors to a file for diagnosis
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   820
        f = open(err, "wb")
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   821
        for line in out:
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   822
            f.write(line)
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   823
        f.close()
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   824
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   825
    if skipped:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   826
        mark = 's'
9707
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   827
        if out is None:                 # debug mode: nothing to parse
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   828
            missing = ['unknown']
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   829
            failed = None
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   830
        else:
38deec407f8d run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents: 9706
diff changeset
   831
            missing, failed = parsehghaveoutput(out)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   832
        if not missing:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   833
            missing = ['irrelevant']
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   834
        if failed:
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   835
            fail("hghave failed checking for %s" % failed[-1], ret)
8060
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   836
            skipped = False
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   837
        else:
84d0fe34427b run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents: 7813
diff changeset
   838
            skip(missing[-1])
14001
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   839
    elif ret == 'timeout':
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   840
        mark = 't'
9c4da6ab4e5a run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents: 14000
diff changeset
   841
        fail("timed out", ret)
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
   842
    elif out != refout:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   843
        mark = '!'
14006
a395575691a6 run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents: 14003
diff changeset
   844
        if not options.nodiff:
14002
a738c30d4b18 run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents: 14001
diff changeset
   845
            iolock.acquire()
11040
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   846
            if options.view:
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   847
                os.system("%s %s %s" % (options.view, ref, err))
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   848
            else:
8f951ed6c63c run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents: 11039
diff changeset
   849
                showdiff(refout, out, ref, err)
14002
a738c30d4b18 run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents: 14001
diff changeset
   850
            iolock.release()
14006
a395575691a6 run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents: 14003
diff changeset
   851
        if ret:
a395575691a6 run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents: 14003
diff changeset
   852
            fail("output changed and returned error code %d" % ret, ret)
a395575691a6 run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents: 14003
diff changeset
   853
        else:
a395575691a6 run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents: 14003
diff changeset
   854
            fail("output changed", ret)
6383
38485d45f947 run-tests.py: Only one fail message when output changed and error code.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6366
diff changeset
   855
        ret = 1
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   856
    elif ret:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   857
        mark = '!'
13988
994ad067ac6e run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents: 13918
diff changeset
   858
        fail("returned error code %d" % ret, ret)
14037
4ab1e987941b run-tests: don't count test as succeeded if it failed
Idan Kamara <idankk86@gmail.com>
parents: 14019
diff changeset
   859
    else:
4ab1e987941b run-tests: don't count test as succeeded if it failed
Idan Kamara <idankk86@gmail.com>
parents: 14019
diff changeset
   860
        success()
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   861
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
   862
    if not options.verbose:
14002
a738c30d4b18 run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents: 14001
diff changeset
   863
        iolock.acquire()
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   864
        sys.stdout.write(mark)
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   865
        sys.stdout.flush()
14002
a738c30d4b18 run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents: 14001
diff changeset
   866
        iolock.release()
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   867
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   868
    killdaemons()
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   869
6208
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   870
    if not options.keep_tmpdir:
12639
236058a65cb4 tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents: 12621
diff changeset
   871
        shutil.rmtree(testtmp, True)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   872
    if skipped:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   873
        return None
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   874
    return ret == 0
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   875
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   876
_hgpath = None
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   877
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   878
def _gethgpath():
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   879
    """Return the path to the mercurial package that is actually found by
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   880
    the current Python interpreter."""
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   881
    global _hgpath
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   882
    if _hgpath is not None:
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   883
        return _hgpath
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   884
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   885
    cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   886
    pipe = os.popen(cmd % PYTHON)
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   887
    try:
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   888
        _hgpath = pipe.read().strip()
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   889
    finally:
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   890
        pipe.close()
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   891
    return _hgpath
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   892
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   893
def _checkhglib(verb):
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   894
    """Ensure that the 'mercurial' package imported by python is
8673
a8066f2fd1aa run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents: 8672
diff changeset
   895
    the one we expect it to be.  If not, print a warning to stderr."""
a8066f2fd1aa run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents: 8672
diff changeset
   896
    expecthg = os.path.join(PYTHONDIR, 'mercurial')
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   897
    actualhg = _gethgpath()
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   898
    if actualhg != expecthg:
8673
a8066f2fd1aa run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents: 8672
diff changeset
   899
        sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n'
a8066f2fd1aa run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents: 8672
diff changeset
   900
                         '         (expected %s)\n'
a8066f2fd1aa run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents: 8672
diff changeset
   901
                         % (verb, actualhg, expecthg))
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   902
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   903
def runchildren(options, tests):
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   904
    if INST:
8107
0eeb4f0a5d21 run-tests: fix -jN broken by 60a9e3cf0cf4
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 8097
diff changeset
   905
        installhg(options)
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   906
        _checkhglib("Testing")
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   907
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   908
    optcopy = dict(options.__dict__)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   909
    optcopy['jobs'] = 1
10904
26d1d23e5a2b Fix --blacklist when --jobs > 1 in run_tests.py.
Ry4an Brase <ry4an-hg@ry4an.org>
parents: 10902
diff changeset
   910
    del optcopy['blacklist']
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   911
    if optcopy['with_hg'] is None:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
   912
        optcopy['with_hg'] = os.path.join(BINDIR, "hg")
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   913
    optcopy.pop('anycoverage', None)
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   914
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   915
    opts = []
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   916
    for opt, value in optcopy.iteritems():
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   917
        name = '--' + opt.replace('_', '-')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   918
        if value is True:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   919
            opts.append(name)
14192
38e387a64f58 run-tests.py: correctly handle list options with parallel tasks
Augie Fackler <durin42@gmail.com>
parents: 14134
diff changeset
   920
        elif isinstance(value, list):
38e387a64f58 run-tests.py: correctly handle list options with parallel tasks
Augie Fackler <durin42@gmail.com>
parents: 14134
diff changeset
   921
            for v in value:
38e387a64f58 run-tests.py: correctly handle list options with parallel tasks
Augie Fackler <durin42@gmail.com>
parents: 14134
diff changeset
   922
                opts.append(name + '=' + str(v))
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   923
        elif value is not None:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   924
            opts.append(name + '=' + str(value))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   925
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   926
    tests.reverse()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   927
    jobs = [[] for j in xrange(options.jobs)]
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   928
    while tests:
8161
1bb8a75fceb3 run-tests: cosmetics
Simon Heimberg <simohe@besonet.ch>
parents: 8116
diff changeset
   929
        for job in jobs:
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   930
            if not tests:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   931
                break
8161
1bb8a75fceb3 run-tests: cosmetics
Simon Heimberg <simohe@besonet.ch>
parents: 8116
diff changeset
   932
            job.append(tests.pop())
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   933
    fps = {}
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   934
8161
1bb8a75fceb3 run-tests: cosmetics
Simon Heimberg <simohe@besonet.ch>
parents: 8116
diff changeset
   935
    for j, job in enumerate(jobs):
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   936
        if not job:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   937
            continue
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   938
        rfd, wfd = os.pipe()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   939
        childopts = ['--child=%d' % wfd, '--port=%d' % (options.port + j * 3)]
9899
be574a37a8ae run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents: 9707
diff changeset
   940
        childtmp = os.path.join(HGTMP, 'child%d' % j)
be574a37a8ae run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents: 9707
diff changeset
   941
        childopts += ['--tmpdir', childtmp]
8096
a110d7a20f3f run-tests: upper-case global PYTHON variable
Martin Geisler <mg@lazybytes.net>
parents: 8095
diff changeset
   942
        cmdline = [PYTHON, sys.argv[0]] + opts + childopts + job
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   943
        vlog(' '.join(cmdline))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   944
        fps[os.spawnvp(os.P_NOWAIT, cmdline[0], cmdline)] = os.fdopen(rfd, 'r')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   945
        os.close(wfd)
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   946
    signal.signal(signal.SIGINT, signal.SIG_IGN)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   947
    failures = 0
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   948
    tested, skipped, failed = 0, 0, 0
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   949
    skips = []
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   950
    fails = []
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   951
    while fps:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   952
        pid, status = os.wait()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   953
        fp = fps.pop(pid)
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   954
        l = fp.read().splitlines()
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   955
        try:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   956
            test, skip, fail = map(int, l[:3])
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   957
        except ValueError:
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
   958
            test, skip, fail = 0, 0, 0
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   959
        split = -fail or len(l)
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   960
        for s in l[3:split]:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   961
            skips.append(s.split(" ", 1))
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   962
        for s in l[split:]:
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   963
            fails.append(s.split(" ", 1))
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   964
        tested += test
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   965
        skipped += skip
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   966
        failed += fail
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   967
        vlog('pid %d exited, status %d' % (pid, status))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   968
        failures |= status
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   969
    print
9580
25858f9e65e8 run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents: 9408
diff changeset
   970
    if not options.noskips:
25858f9e65e8 run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents: 9408
diff changeset
   971
        for s in skips:
25858f9e65e8 run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents: 9408
diff changeset
   972
            print "Skipped %s: %s" % (s[0], s[1])
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   973
    for s in fails:
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   974
        print "Failed %s: %s" % (s[0], s[1])
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   975
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   976
    _checkhglib("Tested")
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   977
    print "# Ran %d tests, %d skipped, %d failed." % (
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   978
        tested, skipped, failed)
10648
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   979
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   980
    if options.anycoverage:
58128004cca1 tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents: 10413
diff changeset
   981
        outputcoverage(options)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   982
    sys.exit(failures != 0)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   983
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   984
results = dict(p=[], f=[], s=[], i=[])
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   985
resultslock = threading.Lock()
14002
a738c30d4b18 run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents: 14001
diff changeset
   986
iolock = threading.Lock()
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   987
13995
b29b7cbc252f run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 13994
diff changeset
   988
def runqueue(options, tests, results):
b29b7cbc252f run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 13994
diff changeset
   989
    for test in tests:
14000
636a6f5aa2cd run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents: 13999
diff changeset
   990
        ret = runone(options, test)
13995
b29b7cbc252f run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 13994
diff changeset
   991
        if options.first and ret is not None and not ret:
b29b7cbc252f run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 13994
diff changeset
   992
            break
b29b7cbc252f run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 13994
diff changeset
   993
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
   994
def runtests(options, tests):
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   995
    global DAEMON_PIDS, HGRCPATH
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   996
    DAEMON_PIDS = os.environ["DAEMON_PIDS"] = os.path.join(HGTMP, 'daemon.pids')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   997
    HGRCPATH = os.environ["HGRCPATH"] = os.path.join(HGTMP, '.hgrc')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   998
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   999
    try:
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1000
        if INST:
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
  1001
            installhg(options)
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
  1002
            _checkhglib("Testing")
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
  1003
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1004
        if options.restart:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1005
            orig = list(tests)
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1006
            while tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1007
                if os.path.exists(tests[0] + ".err"):
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1008
                    break
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1009
                tests.pop(0)
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1010
            if not tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1011
                print "running all tests"
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1012
                tests = orig
2133
4334be196f8d Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents: 2110
diff changeset
  1013
13995
b29b7cbc252f run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents: 13994
diff changeset
  1014
        runqueue(options, tests, results)
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
  1015
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1016
        failed = len(results['f'])
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1017
        tested = len(results['p']) + failed
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1018
        skipped = len(results['s'])
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1019
        ignored = len(results['i'])
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1020
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1021
        if options.child:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1022
            fp = os.fdopen(options.child, 'w')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1023
            fp.write('%d\n%d\n%d\n' % (tested, skipped, failed))
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1024
            for s in results['s']:
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5685
diff changeset
  1025
                fp.write("%s %s\n" % s)
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1026
            for s in results['f']:
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
  1027
                fp.write("%s %s\n" % s)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1028
            fp.close()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1029
        else:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
  1030
            print
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1031
            for s in results['s']:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
  1032
                print "Skipped %s: %s" % s
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1033
            for s in results['f']:
6244
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
  1034
                print "Failed %s: %s" % s
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
  1035
            _checkhglib("Tested")
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
  1036
            print "# Ran %d tests, %d skipped, %d failed." % (
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1037
                tested, skipped + ignored, failed)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1038
8095
f5428d4ffd97 run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents: 8094
diff changeset
  1039
        if options.anycoverage:
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
  1040
            outputcoverage(options)
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
  1041
    except KeyboardInterrupt:
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
  1042
        failed = True
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
  1043
        print "\ninterrupted!"
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1044
13994
f31a5b7f5c07 run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents: 13993
diff changeset
  1045
    if failed:
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1046
        sys.exit(1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1047
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1048
def main():
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
  1049
    (options, args) = parseargs()
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1050
    if not options.child:
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1051
        os.umask(022)
8093
70d8f70264c4 run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents: 8092
diff changeset
  1052
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
  1053
        checktools()
8093
70d8f70264c4 run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents: 8092
diff changeset
  1054
12677
9848a94e2ad6 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12643
diff changeset
  1055
    if len(args) == 0:
9848a94e2ad6 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12643
diff changeset
  1056
        args = os.listdir(".")
9848a94e2ad6 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12643
diff changeset
  1057
    args.sort()
9848a94e2ad6 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12643
diff changeset
  1058
13989
55ba68a4dd28 run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents: 13988
diff changeset
  1059
    tests = args
12677
9848a94e2ad6 run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 12643
diff changeset
  1060
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1061
    # Reset some environment variables to well-known values so that
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1062
    # the tests produce repeatable output.
9931
a0680daed7b2 run-tests: LANGUAGE may make tests fail
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 9707
diff changeset
  1063
    os.environ['LANG'] = os.environ['LC_ALL'] = os.environ['LANGUAGE'] = 'C'
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1064
    os.environ['TZ'] = 'GMT'
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1065
    os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1066
    os.environ['CDPATH'] = ''
9913
e3237af51def run-tests: always set $COLUMNS, fix running tests under emacs shell
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 9899
diff changeset
  1067
    os.environ['COLUMNS'] = '80'
10750
92ff2d0b751a run-tests: make sure GREP_OPTIONS isn't set
Brodie Rao <brodie@bitheap.org>
parents: 10648
diff changeset
  1068
    os.environ['GREP_OPTIONS'] = ''
10154
d4a62b6d4a58 run-tests.py: clears http_proxy for all tests
Wagner Bruna <wbruna@softwareexpress.com.br>
parents: 9939
diff changeset
  1069
    os.environ['http_proxy'] = ''
8093
70d8f70264c4 run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents: 8092
diff changeset
  1070
10902
4eb6311d217a run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10648
diff changeset
  1071
    # unset env related to hooks
4eb6311d217a run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10648
diff changeset
  1072
    for k in os.environ.keys():
4eb6311d217a run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10648
diff changeset
  1073
        if k.startswith('HG_'):
10923
1782278bab8a run-tests.py: can't remove from os.environ on solaris
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10904
diff changeset
  1074
            # can't remove on solaris
1782278bab8a run-tests.py: can't remove from os.environ on solaris
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10904
diff changeset
  1075
            os.environ[k] = ''
10902
4eb6311d217a run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10648
diff changeset
  1076
            del os.environ[k]
4eb6311d217a run-tests.py: reset env variables set by hooks
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10648
diff changeset
  1077
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1078
    global TESTDIR, HGTMP, INST, BINDIR, PYTHONDIR, COVERAGE_FILE
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1079
    TESTDIR = os.environ["TESTDIR"] = os.getcwd()
9706
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1080
    if options.tmpdir:
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1081
        options.keep_tmpdir = True
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1082
        tmpdir = options.tmpdir
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1083
        if os.path.exists(tmpdir):
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1084
            # Meaning of tmpdir has changed since 1.3: we used to create
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1085
            # HGTMP inside tmpdir; now HGTMP is tmpdir.  So fail if
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1086
            # tmpdir already exists.
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1087
            sys.exit("error: temp dir %r already exists" % tmpdir)
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1088
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1089
            # Automatically removing tmpdir sounds convenient, but could
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1090
            # really annoy anyone in the habit of using "--tmpdir=/tmp"
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1091
            # or "--tmpdir=$HOME".
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1092
            #vlog("# Removing temp dir", tmpdir)
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1093
            #shutil.rmtree(tmpdir)
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1094
        os.makedirs(tmpdir)
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1095
    else:
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1096
        tmpdir = tempfile.mkdtemp('', 'hgtests.')
f8b4df4b033d run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents: 9582
diff changeset
  1097
    HGTMP = os.environ['HGTMP'] = os.path.realpath(tmpdir)
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1098
    DAEMON_PIDS = None
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1099
    HGRCPATH = None
8093
70d8f70264c4 run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents: 8092
diff changeset
  1100
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1101
    os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1102
    os.environ["HGMERGE"] = "internal:merge"
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1103
    os.environ["HGUSER"]   = "test"
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1104
    os.environ["HGENCODING"] = "ascii"
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1105
    os.environ["HGENCODINGMODE"] = "strict"
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1106
    os.environ["HGPORT"] = str(options.port)
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1107
    os.environ["HGPORT1"] = str(options.port + 1)
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1108
    os.environ["HGPORT2"] = str(options.port + 2)
8093
70d8f70264c4 run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents: 8092
diff changeset
  1109
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1110
    if options.with_hg:
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1111
        INST = None
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1112
        BINDIR = os.path.dirname(os.path.realpath(options.with_hg))
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1113
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1114
        # This looks redundant with how Python initializes sys.path from
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1115
        # the location of the script being executed.  Needed because the
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1116
        # "hg" specified by --with-hg is not the only Python script
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1117
        # executed in the test suite that needs to import 'mercurial'
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1118
        # ... which means it's not really redundant at all.
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1119
        PYTHONDIR = BINDIR
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1120
    else:
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1121
        INST = os.path.join(HGTMP, "install")
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1122
        BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1123
        PYTHONDIR = os.path.join(INST, "lib", "python")
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1124
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1125
    os.environ["BINDIR"] = BINDIR
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1126
    os.environ["PYTHON"] = PYTHON
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1127
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1128
    if not options.child:
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1129
        path = [BINDIR] + os.environ["PATH"].split(os.pathsep)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1130
        os.environ["PATH"] = os.pathsep.join(path)
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1131
8724
6e41d3c5619f Unbreak run-tests support for out-of-tree extensions
Brendan Cully <brendan@kublai.com>
parents: 8696
diff changeset
  1132
        # Include TESTDIR in PYTHONPATH so that out-of-tree extensions
6e41d3c5619f Unbreak run-tests support for out-of-tree extensions
Brendan Cully <brendan@kublai.com>
parents: 8696
diff changeset
  1133
        # can run .../tests/run-tests.py test-foo where test-foo
6e41d3c5619f Unbreak run-tests support for out-of-tree extensions
Brendan Cully <brendan@kublai.com>
parents: 8696
diff changeset
  1134
        # adds an extension to HGRC
6e41d3c5619f Unbreak run-tests support for out-of-tree extensions
Brendan Cully <brendan@kublai.com>
parents: 8696
diff changeset
  1135
        pypath = [PYTHONDIR, TESTDIR]
8687
78ab2a12b4d9 run-tests: don't replace PYTHONPATH, just augment it.
Greg Ward <greg-hg@gerg.ca>
parents: 8674
diff changeset
  1136
        # We have to augment PYTHONPATH, rather than simply replacing
78ab2a12b4d9 run-tests: don't replace PYTHONPATH, just augment it.
Greg Ward <greg-hg@gerg.ca>
parents: 8674
diff changeset
  1137
        # it, in case external libraries are only available via current
78ab2a12b4d9 run-tests: don't replace PYTHONPATH, just augment it.
Greg Ward <greg-hg@gerg.ca>
parents: 8674
diff changeset
  1138
        # PYTHONPATH.  (In particular, the Subversion bindings on OS X
78ab2a12b4d9 run-tests: don't replace PYTHONPATH, just augment it.
Greg Ward <greg-hg@gerg.ca>
parents: 8674
diff changeset
  1139
        # are in /opt/subversion.)
10758
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
  1140
        oldpypath = os.environ.get(IMPL_PATH)
8724
6e41d3c5619f Unbreak run-tests support for out-of-tree extensions
Brendan Cully <brendan@kublai.com>
parents: 8696
diff changeset
  1141
        if oldpypath:
6e41d3c5619f Unbreak run-tests support for out-of-tree extensions
Brendan Cully <brendan@kublai.com>
parents: 8696
diff changeset
  1142
            pypath.append(oldpypath)
10758
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
  1143
        os.environ[IMPL_PATH] = os.pathsep.join(pypath)
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1144
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1145
    COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
8093
70d8f70264c4 run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents: 8092
diff changeset
  1146
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1147
    vlog("# Using TESTDIR", TESTDIR)
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1148
    vlog("# Using HGTMP", HGTMP)
8674
0941ee76489e run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents: 8673
diff changeset
  1149
    vlog("# Using PATH", os.environ["PATH"])
10758
2ed667a9dfcb tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents: 10750
diff changeset
  1150
    vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH])
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1151
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1152
    try:
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1153
        if len(tests) > 1 and options.jobs > 1:
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
  1154
            runchildren(options, tests)
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1155
        else:
8672
d6b243731763 run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents: 8671
diff changeset
  1156
            runtests(options, tests)
8094
60a9e3cf0cf4 run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8093
diff changeset
  1157
    finally:
10336
bc9a3bb267fa run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents: 10300
diff changeset
  1158
        time.sleep(1)
8097
eea3c1a8fba8 run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents: 8096
diff changeset
  1159
        cleanup(options)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
  1160
13347
ce07defe7d9f run-tests: loadable as module
Simon Heimberg <simohe@besonet.ch>
parents: 13031
diff changeset
  1161
if __name__ == '__main__':
ce07defe7d9f run-tests: loadable as module
Simon Heimberg <simohe@besonet.ch>
parents: 13031
diff changeset
  1162
    main()