tests/run-tests.py
author Greg Ward <greg-hg@gerg.ca>
Mon, 20 Apr 2009 21:04:24 -0400
changeset 8091 e85cc856d2e1
parent 8060 84d0fe34427b
child 8092 c49578c5122f
permissions -rwxr-xr-x
run-tests: factor out parse_args(). Clarify use of globals a bit.
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
#
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     7
# This software may be used and distributed according to the terms
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     8
# of the GNU General Public License, incorporated herein by reference.
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
     9
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    10
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
    11
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
    12
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
    13
import os
7813
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    14
try:
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    15
    import subprocess
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    16
    subprocess.Popen  # trigger ImportError early
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    17
    closefds = os.name == 'posix'
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    18
    def Popen4(cmd, bufsize=-1):
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    19
        p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    20
                             close_fds=closefds,
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    21
                             stdin=subprocess.PIPE, stdout=subprocess.PIPE,
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    22
                             stderr=subprocess.STDOUT)
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    23
        p.fromchild = p.stdout
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    24
        p.tochild = p.stdin
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    25
        p.childerr = p.stderr
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    26
        return p
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    27
except ImportError:
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    28
    subprocess = None
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
    29
    from popen2 import Popen4
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    30
import shutil
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    31
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
    32
import sys
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    33
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
    34
import time
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    35
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
    36
# 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
    37
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
    38
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
    39
FAILED_PREFIX  = 'hghave check failed: '
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
    40
4365
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
    41
required_tools = ["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
    42
6366
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
    43
defaults = {
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
    44
    '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
    45
    '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
    46
    '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
    47
}
07c3cd695b48 run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6343
diff changeset
    48
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    49
# globals set by parse_args() (ugh)
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    50
verbose = False
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    51
nodiff = False
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    52
coverage = False
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    53
python = None
3300
642e5faf6bf0 run-tests: add --retest switch
Matt Mackall <mpm@selenic.com>
parents: 3223
diff changeset
    54
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    55
def 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
    56
    parser = optparse.OptionParser("%prog [options] [tests]")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    57
    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
    58
        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
    59
    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
    60
        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
    61
    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
    62
        help="print a test coverage report")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    63
    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
    64
        help="exit on the first test failure")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    65
    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
    66
        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
    67
    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
    68
        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
    69
             " (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
    70
    parser.add_option("--keep-tmpdir", 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
    71
        help="keep temporary directory after running tests"
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    72
             " (best used with --tmpdir)")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    73
    parser.add_option("-R", "--restart", 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
    74
        help="restart at last error")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    75
    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
    76
        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
    77
             " (default: $%s or %d)" % defaults['port'])
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    78
    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
    79
        help="retest failed tests")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    80
    parser.add_option("-s", "--cover_stdlib", 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
    81
        help="print a test coverage report inc. standard libraries")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    82
    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
    83
        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
    84
             " (default: $%s or %d)" % defaults['timeout'])
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    85
    parser.add_option("--tmpdir", type="string",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    86
        help="run tests in the given temporary directory")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    87
    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
    88
        help="output verbose messages")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    89
    parser.add_option("-n", "--nodiff", 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
    90
        help="skip showing test changes")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    91
    parser.add_option("--with-hg", type="string",
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    92
        help="test existing install at given location")
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    93
    parser.add_option("--pure", 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
    94
        help="use pure Python code instead of C extensions")
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    95
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
    96
    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
    97
        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
    98
    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
    99
    (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
   100
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   101
    global verbose, nodiff, coverage, python
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   102
    verbose = options.verbose
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   103
    nodiff = options.nodiff
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   104
    coverage = options.cover or options.cover_stdlib or options.annotate
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   105
    python = sys.executable
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   106
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   107
    if 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
   108
        print >> sys.stderr, 'ERROR: -j/--jobs must be positive'
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   109
        sys.exit(1)
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   110
    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
   111
        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
   112
        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
   113
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   114
    return (options, args)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   115
5800
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   116
def rename(src, dst):
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   117
    """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
   118
    for existing destination support.
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   119
    """
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   120
    shutil.copy(src, dst)
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   121
    os.remove(src)
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   122
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   123
def vlog(*msg):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   124
    if verbose:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   125
        for m in msg:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   126
            print m,
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   127
        print
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   128
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   129
def splitnewlines(text):
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   130
    '''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
   131
    keep line endings.'''
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   132
    i = 0
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   133
    lines = []
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   134
    while True:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   135
        n = text.find('\n', i)
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   136
        if n == -1:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   137
            last = text[i:]
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   138
            if last:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   139
                lines.append(last)
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   140
            return lines
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   141
        lines.append(text[i:n+1])
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   142
        i = n + 1
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   143
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
   144
def parse_hghave_output(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
   145
    '''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
   146
    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
   147
      * 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
   148
      * 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
   149
    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
   150
    failed = []
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   151
    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
   152
        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
   153
            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
   154
            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
   155
        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
   156
            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
   157
            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
   158
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
   159
    return missing, failed
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   160
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   161
def show_diff(expected, output):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   162
    for line in difflib.unified_diff(expected, output,
2409
4068d6a7a99e Fix diff header (line endings) for failed test output in run-tests.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2408
diff changeset
   163
            "Expected output", "Test output"):
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   164
        sys.stdout.write(line)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   165
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   166
def find_program(program):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   167
    """Search PATH for a executable program"""
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   168
    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
   169
        name = os.path.join(p, program)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   170
        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
   171
            return name
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   172
    return None
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   173
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
   174
def check_required_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
   175
    # 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
   176
    # stuff from coreutils (cat, rm, etc) are not tested
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
   177
    for p in required_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
   178
        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
   179
            p += '.exe'
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
   180
        found = find_program(p)
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
   181
        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
   182
            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
   183
        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
   184
            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
   185
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   186
def cleanup_exit():
6208
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   187
    if not options.keep_tmpdir:
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   188
        if verbose:
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   189
            print "# Cleaning up HGTMP", HGTMP
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   190
        shutil.rmtree(HGTMP, True)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   191
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   192
def use_correct_python():
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   193
    # 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
   194
    # 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
   195
    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
   196
    if exename == 'python':
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   197
        path = find_program('python')
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   198
        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
   199
            return
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   200
    vlog('# Making python executable in test path use correct Python')
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   201
    my_python = os.path.join(BINDIR, 'python')
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   202
    try:
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   203
        os.symlink(sys.executable, my_python)
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   204
    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
   205
        # windows fallback
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   206
        shutil.copyfile(sys.executable, my_python)
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   207
        shutil.copymode(sys.executable, my_python)
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2989
diff changeset
   208
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
   209
def install_hg():
4319
8ece1ba156c7 run-tests.py: use coverage.py with *.py tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4318
diff changeset
   210
    global python
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
   211
    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
   212
    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
   213
    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
   214
5267
b817d17c7ee5 Make run-tests.py work when invoked outside of tests.
Brendan Cully <brendan@kublai.com>
parents: 5251
diff changeset
   215
    # Run installer in hg root
b817d17c7ee5 Make run-tests.py work when invoked outside of tests.
Brendan Cully <brendan@kublai.com>
parents: 5251
diff changeset
   216
    os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '..'))
7723
a343cd25e425 run-tests: add --pure flag for using pure Python modules
Martin Geisler <mg@daimi.au.dk>
parents: 7529
diff changeset
   217
    cmd = ('%s setup.py %s clean --all'
7139
bcbba59e233d run-tests.py: use --prefix instead of --home
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7018
diff changeset
   218
           ' install --force --prefix="%s" --install-lib="%s"'
5189
1843098e665a run-tests.py: pass --install-scripts to setup.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5081
diff changeset
   219
           ' --install-scripts="%s" >%s 2>&1'
7723
a343cd25e425 run-tests: add --pure flag for using pure Python modules
Martin Geisler <mg@daimi.au.dk>
parents: 7529
diff changeset
   220
           % (sys.executable, pure, INST, PYTHONDIR, BINDIR, 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
   221
    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
   222
    if os.system(cmd) == 0:
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
   223
        if not verbose:
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
   224
            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
   225
    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
   226
        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
   227
        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
   228
            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
   229
        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
   230
        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
   231
    os.chdir(TESTDIR)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   232
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
   233
    os.environ["PATH"] = "%s%s%s" % (BINDIR, os.pathsep, os.environ["PATH"])
5251
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   234
5268
980da86fc66a Include . in PYTHONPATH (makes testing unbundled extensions easier)
Brendan Cully <brendan@kublai.com>
parents: 5267
diff changeset
   235
    pydir = os.pathsep.join([PYTHONDIR, TESTDIR])
5251
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   236
    pythonpath = os.environ.get("PYTHONPATH")
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   237
    if pythonpath:
5268
980da86fc66a Include . in PYTHONPATH (makes testing unbundled extensions easier)
Brendan Cully <brendan@kublai.com>
parents: 5267
diff changeset
   238
        pythonpath = pydir + os.pathsep + pythonpath
5251
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   239
    else:
5268
980da86fc66a Include . in PYTHONPATH (makes testing unbundled extensions easier)
Brendan Cully <brendan@kublai.com>
parents: 5267
diff changeset
   240
        pythonpath = pydir
5251
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   241
    os.environ["PYTHONPATH"] = pythonpath
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   242
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   243
    use_correct_python()
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   244
    global hgpkg
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   245
    hgpkg = _hgpath()
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   246
7172
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   247
    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
   248
    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
   249
    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
   250
            'import sys\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   251
            'files = 0\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   252
            '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
   253
            '    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
   254
            '        files += 1\n'
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   255
            '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
   256
    f.close()
fb1d7a42663c Use dummy diffstat in tests and remove older diffstat workaround.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7144
diff changeset
   257
    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
   258
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   259
    if coverage:
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   260
        vlog("# Installing coverage wrapper")
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   261
        os.environ['COVERAGE_FILE'] = COVERAGE_FILE
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   262
        if os.path.exists(COVERAGE_FILE):
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   263
            os.unlink(COVERAGE_FILE)
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   264
        # Create a wrapper script to invoke hg via coverage.py
2146
eb1ed410aa34 run-tests.py: remove trailing white space
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2145
diff changeset
   265
        os.rename(os.path.join(BINDIR, "hg"), os.path.join(BINDIR, "_hg.py"))
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   266
        f = open(os.path.join(BINDIR, 'hg'), 'w')
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   267
        f.write('#!' + sys.executable + '\n')
4633
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4529
diff changeset
   268
        f.write('import sys, os; os.execv(sys.executable, [sys.executable, '
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4529
diff changeset
   269
                '"%s", "-x", "%s"] + sys.argv[1:])\n' %
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4529
diff changeset
   270
                (os.path.join(TESTDIR, 'coverage.py'),
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4529
diff changeset
   271
                 os.path.join(BINDIR, '_hg.py')))
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   272
        f.close()
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   273
        os.chmod(os.path.join(BINDIR, 'hg'), 0700)
4319
8ece1ba156c7 run-tests.py: use coverage.py with *.py tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4318
diff changeset
   274
        python = '"%s" "%s" -x' % (sys.executable,
8ece1ba156c7 run-tests.py: use coverage.py with *.py tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4318
diff changeset
   275
                                   os.path.join(TESTDIR,'coverage.py'))
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   276
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   277
def output_coverage():
2145
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   278
    vlog("# Producing coverage report")
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   279
    omit = [BINDIR, TESTDIR, PYTHONDIR]
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   280
    if not options.cover_stdlib:
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   281
        # Exclude as system paths (ignoring empty strings seen on win)
2146
eb1ed410aa34 run-tests.py: remove trailing white space
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2145
diff changeset
   282
        omit += [x for x in sys.path if x != '']
2145
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   283
    omit = ','.join(omit)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   284
    os.chdir(PYTHONDIR)
4318
b95a42114616 run-tests.py: tell coverage.py to ignore errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3776
diff changeset
   285
    cmd = '"%s" "%s" -i -r "--omit=%s"' % (
2145
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   286
        sys.executable, os.path.join(TESTDIR, 'coverage.py'), omit)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   287
    vlog("# Running: "+cmd)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   288
    os.system(cmd)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   289
    if options.annotate:
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   290
        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
   291
        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
   292
            os.mkdir(adir)
4318
b95a42114616 run-tests.py: tell coverage.py to ignore errors
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 3776
diff changeset
   293
        cmd = '"%s" "%s" -i -a "--directory=%s" "--omit=%s"' % (
2145
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   294
            sys.executable, os.path.join(TESTDIR, 'coverage.py'),
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   295
            adir, 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
   296
        vlog("# Running: "+cmd)
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   297
        os.system(cmd)
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   298
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   299
class Timeout(Exception):
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   300
    pass
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   301
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   302
def alarmed(signum, frame):
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   303
    raise Timeout
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   304
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   305
def run(cmd):
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   306
    """Run command in a sub-process, capturing the output (stdout and stderr).
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   307
    Return the exist code, and output."""
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   308
    # TODO: Use subprocess.Popen if we're running on Python 2.4
7792
cf427b04d5c0 tests: use same popen strategy for jython as for nt
Frank Wierzbicki <fwierzbicki@gmail.com>
parents: 7785
diff changeset
   309
    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
   310
        tochild, fromchild = os.popen4(cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   311
        tochild.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   312
        output = fromchild.read()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   313
        ret = fromchild.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   314
        if ret == None:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   315
            ret = 0
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   316
    else:
7813
076401cf2b63 run-tests.py: avoid using popen2.Popen4 - use subprocess instead
Mads Kiilerich <mads@kiilerich.com>
parents: 7792
diff changeset
   317
        proc = Popen4(cmd)
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   318
        try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   319
            output = ''
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   320
            proc.tochild.close()
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   321
            output = proc.fromchild.read()
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   322
            ret = proc.wait()
4880
6403f948bd6b run-tests: extract correct status when script terminates with exit
Patrick Mezard <pmezard@gmail.com>
parents: 4633
diff changeset
   323
            if os.WIFEXITED(ret):
6403f948bd6b run-tests: extract correct status when script terminates with exit
Patrick Mezard <pmezard@gmail.com>
parents: 4633
diff changeset
   324
                ret = os.WEXITSTATUS(ret)
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   325
        except Timeout:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   326
            vlog('# Process %d timed out - killing it' % proc.pid)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   327
            os.kill(proc.pid, signal.SIGTERM)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   328
            ret = proc.wait()
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   329
            if ret == 0:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   330
                ret = signal.SIGTERM << 8
5078
d27ed83289ee Add message to test output if a test is aborted due to a timeout.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4881
diff changeset
   331
            output += ("\n### Abort: timeout after %d seconds.\n"
d27ed83289ee Add message to test output if a test is aborted due to a timeout.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4881
diff changeset
   332
                       % options.timeout)
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   333
    return ret, splitnewlines(output)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   334
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
   335
def run_one(test, skips, fails):
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   336
    '''tristate output:
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   337
    None -> skipped
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   338
    True -> passed
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   339
    False -> failed'''
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   340
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   341
    def skip(msg):
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   342
        if not verbose:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   343
            skips.append((test, msg))
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   344
        else:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   345
            print "\nSkipping %s: %s" % (test, msg)
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   346
        return None
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   347
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
   348
    def fail(msg):
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   349
        fails.append((test, msg))
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   350
        if not nodiff:
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   351
            print "\nERROR: %s %s" % (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
   352
        return None
b36774d0fce1 run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6212
diff changeset
   353
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   354
    vlog("# Test", test)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   355
2989
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   356
    # create a fresh hgrc
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   357
    hgrc = file(HGRCPATH, 'w+')
4529
860478527568 run-tests.py: set ui.slash = True
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4387
diff changeset
   358
    hgrc.write('[ui]\n')
860478527568 run-tests.py: set ui.slash = True
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4387
diff changeset
   359
    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
   360
    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
   361
    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
   362
    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
   363
    hgrc.write('debugrawcommit = -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
   364
    hgrc.write('tag = -d "0 0"\n')
2989
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   365
    hgrc.close()
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   366
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   367
    err = os.path.join(TESTDIR, test+".err")
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   368
    ref = os.path.join(TESTDIR, test+".out")
4320
f9b61e0fc929 run-tests.py: small cleanup
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4319
diff changeset
   369
    testpath = os.path.join(TESTDIR, test)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   370
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   371
    if os.path.exists(err):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   372
        os.remove(err)       # Remove any previous output files
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   373
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   374
    # Make a tmp subdirectory to work in
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   375
    tmpd = os.path.join(HGTMP, test)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   376
    os.mkdir(tmpd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   377
    os.chdir(tmpd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   378
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
   379
    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
   380
        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
   381
        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
   382
        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
   383
    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
   384
        firstline = ''
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   385
    lctest = test.lower()
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   386
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
   387
    if lctest.endswith('.py') or firstline == '#!/usr/bin/env python':
4320
f9b61e0fc929 run-tests.py: small cleanup
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4319
diff changeset
   388
        cmd = '%s "%s"' % (python, testpath)
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   389
    elif lctest.endswith('.bat'):
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   390
        # do not run batch scripts on non-windows
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   391
        if os.name != 'nt':
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   392
            return skip("batch script")
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   393
        # To reliably get the error code from batch files on WinXP,
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   394
        # the "cmd /c call" prefix is needed. Grrr
4320
f9b61e0fc929 run-tests.py: small cleanup
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4319
diff changeset
   395
        cmd = 'cmd /c call "%s"' % testpath
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   396
    else:
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   397
        # do not run shell scripts on windows
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   398
        if os.name == 'nt':
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   399
            return skip("shell script")
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   400
        # do not try to run non-executable programs
7144
9364c3304ca2 run-tests.py: report missing file as an error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7139
diff changeset
   401
        if not os.path.exists(testpath):
9364c3304ca2 run-tests.py: report missing file as an error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7139
diff changeset
   402
            return fail("does not exist")
9364c3304ca2 run-tests.py: report missing file as an error
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 7139
diff changeset
   403
        elif 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
   404
            return skip("not executable")
4320
f9b61e0fc929 run-tests.py: small cleanup
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4319
diff changeset
   405
        cmd = '"%s"' % testpath
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   406
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   407
    if options.timeout > 0:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   408
        signal.alarm(options.timeout)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   409
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   410
    vlog("# Running", cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   411
    ret, out = run(cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   412
    vlog("# Ret was:", ret)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   413
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   414
    if options.timeout > 0:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   415
        signal.alarm(0)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   416
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   417
    mark = '.'
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   418
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   419
    skipped = (ret == SKIPPED_STATUS)
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
   420
    # If reference output file exists, check test output against it
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
   421
    if os.path.exists(ref):
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
   422
        f = open(ref, "r")
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   423
        ref_out = 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
   424
        f.close()
2246
3fd603eb6add run-tests.py: print diff if reference output not existing.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2213
diff changeset
   425
    else:
2703
d32b31e88391 run-tests.py: fix diff output when test-foo.out doesn't exist.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 2702
diff changeset
   426
        ref_out = []
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   427
    if skipped:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   428
        mark = 's'
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
   429
        missing, failed = parse_hghave_output(out)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   430
        if not missing:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   431
            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
   432
        if 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
   433
            fail("hghave failed checking for %s" % failed[-1])
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
   434
            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
   435
        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
   436
            skip(missing[-1])
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
   437
    elif out != ref_out:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   438
        mark = '!'
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
   439
        if ret:
38485d45f947 run-tests.py: Only one fail message when output changed and error code.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6366
diff changeset
   440
            fail("output changed and returned error code %d" % ret)
38485d45f947 run-tests.py: Only one fail message when output changed and error code.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6366
diff changeset
   441
        else:
38485d45f947 run-tests.py: Only one fail message when output changed and error code.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6366
diff changeset
   442
            fail("output changed")
7529
0a65a1dd7894 tests: fix no-diffs option
Matt Mackall <mpm@selenic.com>
parents: 7448
diff changeset
   443
        if not nodiff:
0a65a1dd7894 tests: fix no-diffs option
Matt Mackall <mpm@selenic.com>
parents: 7448
diff changeset
   444
            show_diff(ref_out, out)
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
   445
        ret = 1
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   446
    elif ret:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   447
        mark = '!'
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
   448
        fail("returned error code %d" % ret)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   449
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   450
    if not verbose:
7343
e47dab64be8d run-tests: allow turning off diff display
Matt Mackall <mpm@selenic.com>
parents: 7214
diff changeset
   451
        sys.stdout.write(mark)
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   452
        sys.stdout.flush()
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   453
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5078
diff changeset
   454
    if ret != 0 and not skipped:
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   455
        # Save errors to a file for diagnosis
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   456
        f = open(err, "wb")
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   457
        for line in out:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   458
            f.write(line)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   459
        f.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   460
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   461
    # Kill off any leftover daemon processes
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   462
    try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   463
        fp = file(DAEMON_PIDS)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   464
        for line in fp:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   465
            try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   466
                pid = int(line)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   467
            except ValueError:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   468
                continue
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   469
            try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   470
                os.kill(pid, 0)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   471
                vlog('# Killing daemon process %d' % pid)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   472
                os.kill(pid, signal.SIGTERM)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   473
                time.sleep(0.25)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   474
                os.kill(pid, 0)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   475
                vlog('# Daemon process %d is stuck - really killing it' % pid)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   476
                os.kill(pid, signal.SIGKILL)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   477
            except OSError, err:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   478
                if err.errno != errno.ESRCH:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   479
                    raise
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   480
        fp.close()
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   481
        os.unlink(DAEMON_PIDS)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   482
    except IOError:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   483
        pass
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   484
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   485
    os.chdir(TESTDIR)
6208
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
   486
    if not options.keep_tmpdir:
6209
4e8cd15240bf Replaced tab in run-tests.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6208
diff changeset
   487
        shutil.rmtree(tmpd, True)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   488
    if skipped:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   489
        return None
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   490
    return ret == 0
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   491
8091
e85cc856d2e1 run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents: 8060
diff changeset
   492
(options, args) = parse_args()
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   493
if not options.child:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   494
    os.umask(022)
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
   495
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   496
    check_required_tools()
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
   497
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
   498
# Reset some environment variables to well-known values so that
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
   499
# the tests produce repeatable output.
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
   500
os.environ['LANG'] = os.environ['LC_ALL'] = 'C'
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
   501
os.environ['TZ'] = 'GMT'
5779
e9f68860d5ed Don't let ui.username override web.contact (issue900)
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5760
diff changeset
   502
os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
7448
7900d240c3d8 Fix non-empty $CDPATH causing failed tests.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 7343
diff changeset
   503
os.environ['CDPATH'] = ''
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
   504
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
   505
TESTDIR = os.environ["TESTDIR"] = os.getcwd()
7730
5fb312ba29a8 Account for symlinks when setting up HGTMP.
Jim Correia <jim.correia@pobox.com>
parents: 7723
diff changeset
   506
HGTMP = os.environ['HGTMP'] = os.path.realpath(tempfile.mkdtemp('', 'hgtests.',
5fb312ba29a8 Account for symlinks when setting up HGTMP.
Jim Correia <jim.correia@pobox.com>
parents: 7723
diff changeset
   507
                                               options.tmpdir))
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   508
DAEMON_PIDS = None
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   509
HGRCPATH = None
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   510
4365
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   511
os.environ["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"'
6004
5af5f0f9d724 merge: allow smarter tool configuration
Matt Mackall <mpm@selenic.com>
parents: 5807
diff changeset
   512
os.environ["HGMERGE"] = "internal:merge"
4365
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   513
os.environ["HGUSER"]   = "test"
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   514
os.environ["HGENCODING"] = "ascii"
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   515
os.environ["HGENCODINGMODE"] = "strict"
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   516
os.environ["HGPORT"] = str(options.port)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   517
os.environ["HGPORT1"] = str(options.port + 1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   518
os.environ["HGPORT2"] = str(options.port + 2)
4365
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   519
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   520
if options.with_hg:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   521
    INST = options.with_hg
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   522
else:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   523
    INST = os.path.join(HGTMP, "install")
7785
660c8dd44060 test-merge-tool: Make sure no hgmerge can be found in $PATH
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
   524
BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin")
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   525
PYTHONDIR = os.path.join(INST, "lib", "python")
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   526
COVERAGE_FILE = os.path.join(TESTDIR, ".coverage")
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   527
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   528
def _hgpath():
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   529
    cmd = '%s -c "import mercurial; print mercurial.__path__[0]"'
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   530
    hgpath = os.popen(cmd % python)
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   531
    path = hgpath.read().strip()
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   532
    hgpath.close()
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   533
    return path
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   534
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   535
expecthg = os.path.join(HGTMP, 'install', 'lib', 'python', 'mercurial')
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   536
hgpkg = None
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   537
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   538
def run_children(tests):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   539
    if not options.with_hg:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   540
        install_hg()
7018
0b72836b0384 run-tests.py: fix the check for the hg installation with -jn (n > 1)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6982
diff changeset
   541
        if hgpkg != expecthg:
0b72836b0384 run-tests.py: fix the check for the hg installation with -jn (n > 1)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6982
diff changeset
   542
            print '# Testing unexpected mercurial: %s' % hgpkg
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   543
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   544
    optcopy = dict(options.__dict__)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   545
    optcopy['jobs'] = 1
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   546
    optcopy['with_hg'] = INST
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   547
    opts = []
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   548
    for opt, value in optcopy.iteritems():
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   549
        name = '--' + opt.replace('_', '-')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   550
        if value is True:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   551
            opts.append(name)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   552
        elif value is not None:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   553
            opts.append(name + '=' + str(value))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   554
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   555
    tests.reverse()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   556
    jobs = [[] for j in xrange(options.jobs)]
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   557
    while tests:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   558
        for j in xrange(options.jobs):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   559
            if not tests: break
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   560
            jobs[j].append(tests.pop())
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   561
    fps = {}
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   562
    for j in xrange(len(jobs)):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   563
        job = jobs[j]
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   564
        if not job:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   565
            continue
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   566
        rfd, wfd = os.pipe()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   567
        childopts = ['--child=%d' % wfd, '--port=%d' % (options.port + j * 3)]
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   568
        cmdline = [python, sys.argv[0]] + opts + childopts + job
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   569
        vlog(' '.join(cmdline))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   570
        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
   571
        os.close(wfd)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   572
    failures = 0
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   573
    tested, skipped, failed = 0, 0, 0
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   574
    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
   575
    fails = []
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   576
    while fps:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   577
        pid, status = os.wait()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   578
        fp = fps.pop(pid)
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   579
        l = fp.read().splitlines()
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   580
        test, skip, fail = map(int, l[:3])
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
   581
        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
   582
        for s in l[3:split]:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   583
            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
   584
        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
   585
            fails.append(s.split(" ", 1))
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   586
        tested += test
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   587
        skipped += skip
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   588
        failed += fail
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   589
        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
   590
        failures |= status
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   591
    print
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   592
    for s in skips:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   593
        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
   594
    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
   595
        print "Failed %s: %s" % (s[0], s[1])
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   596
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   597
    if hgpkg != expecthg:
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   598
        print '# Tested unexpected mercurial: %s' % hgpkg
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   599
    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
   600
        tested, skipped, failed)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   601
    sys.exit(failures != 0)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   602
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   603
def run_tests(tests):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   604
    global DAEMON_PIDS, HGRCPATH
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   605
    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
   606
    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
   607
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   608
    try:
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   609
        if not options.with_hg:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   610
            install_hg()
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
   611
7018
0b72836b0384 run-tests.py: fix the check for the hg installation with -jn (n > 1)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6982
diff changeset
   612
            if hgpkg != expecthg:
0b72836b0384 run-tests.py: fix the check for the hg installation with -jn (n > 1)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 6982
diff changeset
   613
                print '# Testing unexpected mercurial: %s' % hgpkg
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   614
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   615
        if options.timeout > 0:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   616
            try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   617
                signal.signal(signal.SIGALRM, alarmed)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   618
                vlog('# Running tests with %d-second timeout' %
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   619
                     options.timeout)
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   620
            except AttributeError:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   621
                print 'WARNING: cannot run tests with timeouts'
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   622
                options.timeout = 0
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   623
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   624
        tested = 0
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   625
        failed = 0
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   626
        skipped = 0
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   627
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   628
        if options.restart:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   629
            orig = list(tests)
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   630
            while tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   631
                if os.path.exists(tests[0] + ".err"):
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   632
                    break
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   633
                tests.pop(0)
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   634
            if not tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   635
                print "running all tests"
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   636
                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
   637
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   638
        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
   639
        fails = []
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   640
        for test in tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   641
            if options.retest and not os.path.exists(test + ".err"):
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   642
                skipped += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   643
                continue
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
   644
            ret = run_one(test, skips, fails)
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   645
            if ret is None:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   646
                skipped += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   647
            elif not ret:
3626
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   648
                if options.interactive:
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   649
                    print "Accept this change? [n] ",
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   650
                    answer = sys.stdin.readline().strip()
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   651
                    if answer.lower() in "y yes".split():
5800
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
   652
                        rename(test + ".err", test + ".out")
3626
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   653
                        tested += 1
6343
1f9be57a6d6a tests: teach -i about fails list
Matt Mackall <mpm@selenic.com>
parents: 6244
diff changeset
   654
                        fails.pop()
3626
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   655
                        continue
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   656
                failed += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   657
                if options.first:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   658
                    break
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   659
            tested += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   660
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   661
        if options.child:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   662
            fp = os.fdopen(options.child, 'w')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   663
            fp.write('%d\n%d\n%d\n' % (tested, skipped, failed))
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   664
            for s in skips:
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5685
diff changeset
   665
                fp.write("%s %s\n" % s)
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
   666
            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
   667
                fp.write("%s %s\n" % s)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   668
            fp.close()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   669
        else:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   670
            print
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   671
            for s in skips:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   672
                print "Skipped %s: %s" % s
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
   673
            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
   674
                print "Failed %s: %s" % s
6982
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   675
            if hgpkg != expecthg:
9fc5bf4adbcf imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6681
diff changeset
   676
                print '# Tested unexpected mercurial: %s' % hgpkg
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   677
            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
   678
                tested, skipped, failed)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   679
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   680
        if coverage:
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   681
            output_coverage()
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   682
    except KeyboardInterrupt:
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   683
        failed = True
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   684
        print "\ninterrupted!"
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   685
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   686
    if failed:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   687
        sys.exit(1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   688
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   689
if len(args) == 0:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   690
    args = os.listdir(".")
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   691
    args.sort()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   692
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   693
tests = []
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   694
for test in args:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   695
    if (test.startswith("test-") and '~' not in test and
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   696
        ('.' not in test or test.endswith('.py') or
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   697
         test.endswith('.bat'))):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   698
        tests.append(test)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   699
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   700
vlog("# Using TESTDIR", TESTDIR)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   701
vlog("# Using HGTMP", HGTMP)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   702
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   703
try:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   704
    if len(tests) > 1 and options.jobs > 1:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   705
        run_children(tests)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   706
    else:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   707
        run_tests(tests)
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
   708
finally:
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
   709
    cleanup_exit()