tests/run-tests.py
author Matt Mackall <mpm@selenic.com>
Fri, 21 Mar 2008 15:57:22 -0500
changeset 6343 1f9be57a6d6a
parent 6244 b36774d0fce1
child 6366 07c3cd695b48
permissions -rwxr-xr-x
tests: teach -i about fails list
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
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    14
import popen2
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    15
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
    16
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
    17
import sys
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    18
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
    19
import time
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    20
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
    21
# 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
    22
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
    23
SKIPPED_PREFIX = 'skipped: '
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
    24
4365
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
    25
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
    26
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
    27
parser = optparse.OptionParser("%prog [options] [tests]")
5383
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    28
parser.add_option("-C", "--annotate", action="store_true",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    29
    help="output files annotated with coverage")
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    30
parser.add_option("--child", type="int",
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    31
    help="run as child process, summary to given fd")
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
    32
parser.add_option("-c", "--cover", action="store_true",
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
    33
    help="print a test coverage report")
5383
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    34
parser.add_option("-f", "--first", action="store_true",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    35
    help="exit on the first test failure")
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    36
parser.add_option("-i", "--interactive", action="store_true",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    37
    help="prompt to accept changed output")
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    38
parser.add_option("-j", "--jobs", type="int",
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    39
    help="number of jobs to run in parallel")
6208
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
    40
parser.add_option("--keep-tmpdir", action="store_true",
c88b9e597588 tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents: 6004
diff changeset
    41
    help="keep temporary directory after running tests (best used with --tmpdir)")
5383
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    42
parser.add_option("-R", "--restart", action="store_true",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    43
    help="restart at last error")
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    44
parser.add_option("-p", "--port", type="int",
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    45
    help="port on which servers should listen")
5383
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    46
parser.add_option("-r", "--retest", action="store_true",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    47
    help="retest failed tests")
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
    48
parser.add_option("-s", "--cover_stdlib", action="store_true",
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
    49
    help="print a test coverage report inc. standard libraries")
5383
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    50
parser.add_option("-t", "--timeout", type="int",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    51
    help="kill errant tests after TIMEOUT seconds")
5388
557e4a916e12 run-tests.py: allow a different temporary directory to be specified
Bryan O'Sullivan <bos@serpentine.com>
parents: 5384
diff changeset
    52
parser.add_option("--tmpdir", type="string",
557e4a916e12 run-tests.py: allow a different temporary directory to be specified
Bryan O'Sullivan <bos@serpentine.com>
parents: 5384
diff changeset
    53
    help="run tests in the given temporary directory")
5383
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    54
parser.add_option("-v", "--verbose", action="store_true",
7cdc896fdcd5 run-tests.py: reorder options alphabetically.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5268
diff changeset
    55
    help="output verbose messages")
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    56
parser.add_option("--with-hg", type="string",
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    57
    help="test existing install at given location")
3300
642e5faf6bf0 run-tests: add --retest switch
Matt Mackall <mpm@selenic.com>
parents: 3223
diff changeset
    58
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    59
parser.set_defaults(jobs=1, port=20059, timeout=180)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    60
(options, args) = parser.parse_args()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    61
verbose = options.verbose
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
    62
coverage = options.cover or options.cover_stdlib or options.annotate
4319
8ece1ba156c7 run-tests.py: use coverage.py with *.py tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4318
diff changeset
    63
python = sys.executable
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    64
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    65
if options.jobs < 1:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    66
    print >> sys.stderr, 'ERROR: -j/--jobs must be positive'
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    67
    sys.exit(1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    68
if options.interactive and options.jobs > 1:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    69
    print >> sys.stderr, 'ERROR: cannot mix -interactive and --jobs > 1'
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    70
    sys.exit(1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
    71
5800
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
    72
def rename(src, dst):
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
    73
    """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
    74
    for existing destination support.
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
    75
    """
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
    76
    shutil.copy(src, dst)
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
    77
    os.remove(src)
2f597243e1d7 Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents: 5524
diff changeset
    78
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    79
def vlog(*msg):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    80
    if verbose:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    81
        for m in msg:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    82
            print m,
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    83
        print
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
    84
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    85
def splitnewlines(text):
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    86
    '''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
    87
    keep line endings.'''
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    88
    i = 0
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    89
    lines = []
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    90
    while True:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    91
        n = text.find('\n', i)
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    92
        if n == -1:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    93
            last = text[i:]
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    94
            if last:
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    95
                lines.append(last)
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    96
            return lines
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    97
        lines.append(text[i:n+1])
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    98
        i = n + 1
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
    99
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   100
def extract_missing_features(lines):
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   101
    '''Extract missing/unknown features log lines as a list'''
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   102
    missing = []
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   103
    for line in lines:
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
   104
        if not line.startswith(SKIPPED_PREFIX):
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   105
            continue
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   106
        line = line.splitlines()[0]
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
   107
        missing.append(line[len(SKIPPED_PREFIX):])
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   108
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   109
    return missing
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   110
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   111
def show_diff(expected, output):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   112
    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
   113
            "Expected output", "Test output"):
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   114
        sys.stdout.write(line)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   115
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   116
def find_program(program):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   117
    """Search PATH for a executable program"""
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   118
    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
   119
        name = os.path.join(p, program)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   120
        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
   121
            return name
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   122
    return None
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   123
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
   124
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
   125
    # 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
   126
    # 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
   127
    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
   128
        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
   129
            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
   130
        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
   131
        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
   132
            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
   133
        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
   134
            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
   135
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   136
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
   137
    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
   138
        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
   139
            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
   140
        shutil.rmtree(HGTMP, True)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   141
2570
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   142
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
   143
    # 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
   144
    # 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
   145
    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
   146
    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
   147
        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
   148
        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
   149
            return
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   150
    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
   151
    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
   152
    try:
2264b2b077a1 run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2409
diff changeset
   153
        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
   154
    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
   155
        # 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
   156
        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
   157
        shutil.copymode(sys.executable, my_python)
3223
53e843840349 Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2989
diff changeset
   158
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
   159
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
   160
    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
   161
    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
   162
    installerrs = os.path.join("tests", "install.err")
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   163
5267
b817d17c7ee5 Make run-tests.py work when invoked outside of tests.
Brendan Cully <brendan@kublai.com>
parents: 5251
diff changeset
   164
    # 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
   165
    os.chdir(os.path.join(os.path.dirname(sys.argv[0]), '..'))
2183
a56fc34d6e23 Always clean the build directory before installing for running the tests.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2146
diff changeset
   166
    cmd = ('%s setup.py clean --all'
5189
1843098e665a run-tests.py: pass --install-scripts to setup.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5081
diff changeset
   167
           ' install --force --home="%s" --install-lib="%s"'
1843098e665a run-tests.py: pass --install-scripts to setup.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5081
diff changeset
   168
           ' --install-scripts="%s" >%s 2>&1'
1843098e665a run-tests.py: pass --install-scripts to setup.py
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5081
diff changeset
   169
           % (sys.executable, 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
   170
    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
   171
    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
   172
        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
   173
            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
   174
    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
   175
        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
   176
        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
   177
            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
   178
        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
   179
        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
   180
    os.chdir(TESTDIR)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   181
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
   182
    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
   183
5268
980da86fc66a Include . in PYTHONPATH (makes testing unbundled extensions easier)
Brendan Cully <brendan@kublai.com>
parents: 5267
diff changeset
   184
    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
   185
    pythonpath = os.environ.get("PYTHONPATH")
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   186
    if pythonpath:
5268
980da86fc66a Include . in PYTHONPATH (makes testing unbundled extensions easier)
Brendan Cully <brendan@kublai.com>
parents: 5267
diff changeset
   187
        pythonpath = pydir + os.pathsep + pythonpath
5251
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   188
    else:
5268
980da86fc66a Include . in PYTHONPATH (makes testing unbundled extensions easier)
Brendan Cully <brendan@kublai.com>
parents: 5267
diff changeset
   189
        pythonpath = pydir
5251
90919a6f5c8f run-tests: append PYTHONPATH instead of overwriting it
Patrick Mezard <pmezard@gmail.com>
parents: 5189
diff changeset
   190
    os.environ["PYTHONPATH"] = pythonpath
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
    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
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   194
    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
   195
        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
   196
        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
   197
        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
   198
            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
   199
        # 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
   200
        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
   201
        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
   202
        f.write('#!' + sys.executable + '\n')
4633
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4529
diff changeset
   203
        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
   204
                '"%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
   205
                (os.path.join(TESTDIR, 'coverage.py'),
ff7253a0d1da Cleanup of whitespace, indentation and line continuation.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 4529
diff changeset
   206
                 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
   207
        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
   208
        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
   209
        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
   210
                                   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
   211
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   212
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
   213
    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
   214
    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
   215
    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
   216
        # 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
   217
        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
   218
    omit = ','.join(omit)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   219
    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
   220
    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
   221
        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
   222
    vlog("# Running: "+cmd)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   223
    os.system(cmd)
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   224
    if options.annotate:
5bb3cb9e5d13 make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2144
diff changeset
   225
        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
   226
        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
   227
            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
   228
        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
   229
            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
   230
            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
   231
        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
   232
        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
   233
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   234
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
   235
    pass
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   236
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   237
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
   238
    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
   239
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   240
def run(cmd):
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   241
    """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
   242
    Return the exist code, and output."""
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   243
    # TODO: Use subprocess.Popen if we're running on Python 2.4
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   244
    if os.name == 'nt':
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   245
        tochild, fromchild = os.popen4(cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   246
        tochild.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   247
        output = fromchild.read()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   248
        ret = fromchild.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   249
        if ret == None:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   250
            ret = 0
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   251
    else:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   252
        proc = popen2.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
   253
        try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   254
            output = ''
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   255
            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
   256
            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
   257
            ret = proc.wait()
4880
6403f948bd6b run-tests: extract correct status when script terminates with exit
Patrick Mezard <pmezard@gmail.com>
parents: 4633
diff changeset
   258
            if os.WIFEXITED(ret):
6403f948bd6b run-tests: extract correct status when script terminates with exit
Patrick Mezard <pmezard@gmail.com>
parents: 4633
diff changeset
   259
                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
   260
        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
   261
            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
   262
            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
   263
            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
   264
            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
   265
                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
   266
            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
   267
                       % options.timeout)
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   268
    return ret, splitnewlines(output)
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   269
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
   270
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
   271
    '''tristate output:
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   272
    None -> skipped
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   273
    True -> passed
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   274
    False -> failed'''
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   275
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   276
    def skip(msg):
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   277
        if not verbose:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   278
            skips.append((test, msg))
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   279
        else:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   280
            print "\nSkipping %s: %s" % (test, msg)
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   281
        return None
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   282
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
   283
    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
   284
        fails.append((test, 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
   285
        print "\nERROR: %s %s" % (test, 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
   286
        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
   287
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   288
    vlog("# Test", test)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   289
2989
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   290
    # 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
   291
    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
   292
    hgrc.write('[ui]\n')
860478527568 run-tests.py: set ui.slash = True
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4387
diff changeset
   293
    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
   294
    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
   295
    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
   296
    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
   297
    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
   298
    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
   299
    hgrc.close()
3091b1153e2c Clear contents of global hgrc for tests before running each test.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2710
diff changeset
   300
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   301
    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
   302
    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
   303
    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
   304
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   305
    if os.path.exists(err):
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   306
        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
   307
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   308
    # 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
   309
    tmpd = os.path.join(HGTMP, test)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   310
    os.mkdir(tmpd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   311
    os.chdir(tmpd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   312
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
   313
    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
   314
        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
   315
        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
   316
        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
   317
    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
   318
        firstline = ''
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   319
    lctest = test.lower()
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   320
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
   321
    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
   322
        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
   323
    elif lctest.endswith('.bat'):
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   324
        # 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
   325
        if os.name != 'nt':
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   326
            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
   327
        # 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
   328
        # 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
   329
        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
   330
    else:
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   331
        # 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
   332
        if os.name == 'nt':
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   333
            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
   334
        # do not try to run non-executable programs
4320
f9b61e0fc929 run-tests.py: small cleanup
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4319
diff changeset
   335
        if not os.access(testpath, os.X_OK):
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   336
            return skip("not executable")
4320
f9b61e0fc929 run-tests.py: small cleanup
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4319
diff changeset
   337
        cmd = '"%s"' % testpath
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   338
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   339
    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
   340
        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
   341
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   342
    vlog("# Running", cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   343
    ret, out = run(cmd)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   344
    vlog("# Ret was:", ret)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   345
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   346
    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
   347
        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
   348
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   349
    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
   350
    diffret = 0
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
   351
    # 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
   352
    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
   353
        f = open(ref, "r")
2247
546c76e5a3e6 run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2246
diff changeset
   354
        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
   355
        f.close()
2246
3fd603eb6add run-tests.py: print diff if reference output not existing.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2213
diff changeset
   356
    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
   357
        ref_out = []
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   358
    if not skipped and out != ref_out:
2246
3fd603eb6add run-tests.py: print diff if reference output not existing.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2213
diff changeset
   359
        diffret = 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
   360
        fail("output changed")
2246
3fd603eb6add run-tests.py: print diff if reference output not existing.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2213
diff changeset
   361
        show_diff(ref_out, out)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   362
    if skipped:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   363
        missing = extract_missing_features(out)
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   364
        if not missing:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   365
            missing = ['irrelevant']
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   366
        skip(missing[-1])
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   367
    elif ret:
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
   368
        fail("returned error code %d" % ret)
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
   369
    elif diffret:
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
   370
        ret = diffret
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   371
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   372
    if not verbose:
5518
d0a022d5871e run-tests.py: don't print a dot for skipped tests
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 5470
diff changeset
   373
        sys.stdout.write(skipped and 's' or '.')
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   374
        sys.stdout.flush()
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   375
5081
ea7b982b6c08 Remove trailing spaces
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5078
diff changeset
   376
    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
   377
        # 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
   378
        f = open(err, "wb")
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   379
        for line in out:
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   380
            f.write(line)
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   381
        f.close()
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   382
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   383
    # 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
   384
    try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   385
        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
   386
        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
   387
            try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   388
                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
   389
            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
   390
                continue
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   391
            try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   392
                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
   393
                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
   394
                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
   395
                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
   396
                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
   397
                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
   398
                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
   399
            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
   400
                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
   401
                    raise
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   402
        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
   403
        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
   404
    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
   405
        pass
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   406
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   407
    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
   408
    if not options.keep_tmpdir:
6209
4e8cd15240bf Replaced tab in run-tests.py
Thomas Arendsen Hein <thomas@intevation.de>
parents: 6208
diff changeset
   409
        shutil.rmtree(tmpd, True)
4881
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   410
    if skipped:
c51c9bc4579d Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents: 4880
diff changeset
   411
        return None
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   412
    return ret == 0
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   413
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   414
if not options.child:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   415
    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
   416
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   417
    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
   418
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
   419
# 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
   420
# 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
   421
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
   422
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
   423
os.environ["EMAIL"] = "Foo Bar <foo.bar@example.com>"
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
   424
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
   425
TESTDIR = os.environ["TESTDIR"] = os.getcwd()
5388
557e4a916e12 run-tests.py: allow a different temporary directory to be specified
Bryan O'Sullivan <bos@serpentine.com>
parents: 5384
diff changeset
   426
HGTMP = os.environ['HGTMP'] = tempfile.mkdtemp('', 'hgtests.', options.tmpdir)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   427
DAEMON_PIDS = None
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   428
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
   429
4365
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   430
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
   431
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
   432
os.environ["HGUSER"]   = "test"
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   433
os.environ["HGENCODING"] = "ascii"
46280c004f22 change tests to use simplemerge by default
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents: 4321
diff changeset
   434
os.environ["HGENCODINGMODE"] = "strict"
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   435
os.environ["HGPORT"] = str(options.port)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   436
os.environ["HGPORT1"] = str(options.port + 1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   437
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
   438
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   439
if options.with_hg:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   440
    INST = options.with_hg
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   441
else:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   442
    INST = os.path.join(HGTMP, "install")
2144
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   443
BINDIR = os.path.join(INST, "bin")
d3bddedfdbd0 Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents: 2133
diff changeset
   444
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
   445
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
   446
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   447
def run_children(tests):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   448
    if not options.with_hg:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   449
        install_hg()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   450
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   451
    optcopy = dict(options.__dict__)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   452
    optcopy['jobs'] = 1
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   453
    optcopy['with_hg'] = INST
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   454
    opts = []
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   455
    for opt, value in optcopy.iteritems():
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   456
        name = '--' + opt.replace('_', '-')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   457
        if value is True:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   458
            opts.append(name)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   459
        elif value is not None:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   460
            opts.append(name + '=' + str(value))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   461
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   462
    tests.reverse()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   463
    jobs = [[] for j in xrange(options.jobs)]
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   464
    while tests:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   465
        for j in xrange(options.jobs):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   466
            if not tests: break
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   467
            jobs[j].append(tests.pop())
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   468
    fps = {}
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   469
    for j in xrange(len(jobs)):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   470
        job = jobs[j]
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   471
        if not job:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   472
            continue
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   473
        rfd, wfd = os.pipe()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   474
        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
   475
        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
   476
        vlog(' '.join(cmdline))
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   477
        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
   478
        os.close(wfd)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   479
    failures = 0
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   480
    tested, skipped, failed = 0, 0, 0
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   481
    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
   482
    fails = []
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   483
    while fps:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   484
        pid, status = os.wait()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   485
        fp = fps.pop(pid)
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   486
        l = fp.read().splitlines()
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   487
        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
   488
        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
   489
        for s in l[3:split]:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   490
            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
   491
        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
   492
            fails.append(s.split(" ", 1))
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   493
        tested += test
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   494
        skipped += skip
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   495
        failed += fail
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   496
        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
   497
        failures |= status
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   498
    print
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   499
    for s in skips:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   500
        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
   501
    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
   502
        print "Failed %s: %s" % (s[0], s[1])
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   503
    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
   504
        tested, skipped, failed)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   505
    sys.exit(failures != 0)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   506
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   507
def run_tests(tests):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   508
    global DAEMON_PIDS, HGRCPATH
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   509
    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
   510
    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
   511
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   512
    try:
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   513
        if not options.with_hg:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   514
            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
   515
2571
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   516
        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
   517
            try:
83cfd95eafb5 tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2570
diff changeset
   518
                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
   519
                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
   520
                     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
   521
            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
   522
                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
   523
                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
   524
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   525
        tested = 0
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   526
        failed = 0
2710
e475fe2a6029 run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents: 2705
diff changeset
   527
        skipped = 0
2110
25a8d116ab6a Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff changeset
   528
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   529
        if options.restart:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   530
            orig = list(tests)
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   531
            while tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   532
                if os.path.exists(tests[0] + ".err"):
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   533
                    break
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   534
                tests.pop(0)
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   535
            if not tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   536
                print "running all tests"
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   537
                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
   538
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   539
        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
   540
        fails = []
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   541
        for test in tests:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   542
            if options.retest and not os.path.exists(test + ".err"):
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   543
                skipped += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   544
                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
   545
            ret = run_one(test, skips, fails)
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   546
            if ret is None:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   547
                skipped += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   548
            elif not ret:
3626
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   549
                if options.interactive:
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   550
                    print "Accept this change? [n] ",
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   551
                    answer = sys.stdin.readline().strip()
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   552
                    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
   553
                        rename(test + ".err", test + ".out")
3626
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   554
                        tested += 1
6343
1f9be57a6d6a tests: teach -i about fails list
Matt Mackall <mpm@selenic.com>
parents: 6244
diff changeset
   555
                        fails.pop()
3626
02e9355c3420 tests: add -i switch
Matt Mackall <mpm@selenic.com>
parents: 3625
diff changeset
   556
                        continue
3625
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   557
                failed += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   558
                if options.first:
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   559
                    break
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   560
            tested += 1
cc0cd5942223 tests: add -R switch
Matt Mackall <mpm@selenic.com>
parents: 3624
diff changeset
   561
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   562
        if options.child:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   563
            fp = os.fdopen(options.child, 'w')
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   564
            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
   565
            for s in skips:
5760
0145f9afb0e7 Removed tabs and trailing whitespace in python files
Thomas Arendsen Hein <thomas@intevation.de>
parents: 5685
diff changeset
   566
                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
   567
            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
   568
                fp.write("%s %s\n" % s)
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   569
            fp.close()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   570
        else:
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   571
            print
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   572
            for s in skips:
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   573
                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
   574
            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
   575
                print "Failed %s: %s" % s
5470
8374f3f081f2 tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents: 5388
diff changeset
   576
            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
   577
                tested, skipped, failed)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   578
2258
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   579
        if coverage:
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   580
            output_coverage()
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   581
    except KeyboardInterrupt:
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   582
        failed = True
7e43d68f3900 catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 2247
diff changeset
   583
        print "\ninterrupted!"
5384
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   584
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   585
    if failed:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   586
        sys.exit(1)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   587
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   588
if len(args) == 0:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   589
    args = os.listdir(".")
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   590
    args.sort()
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   591
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   592
tests = []
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   593
for test in args:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   594
    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
   595
        ('.' 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
   596
         test.endswith('.bat'))):
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   597
        tests.append(test)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   598
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   599
vlog("# Using TESTDIR", TESTDIR)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   600
vlog("# Using HGTMP", HGTMP)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   601
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   602
try:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   603
    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
   604
        run_children(tests)
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   605
    else:
e3a0c092b4e2 Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents: 5383
diff changeset
   606
        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
   607
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
   608
    cleanup_exit()