author | Gregory Szorc <gregory.szorc@gmail.com> |
Sat, 19 Apr 2014 20:22:32 -0700 | |
changeset 21319 | 44c96e2bab20 |
parent 21318 | 6b3d66e4d3be |
child 21320 | e5eed8ded168 |
permissions | -rwxr-xr-x |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
2 |
# |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
3 |
# run-tests.py - Run a set of tests on Mercurial |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
4 |
# |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
5 |
# Copyright 2006 Matt Mackall <mpm@selenic.com> |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
6 |
# |
8225
46293a0c7e9f
updated license to be explicit about GPL version 2
Martin Geisler <mg@lazybytes.net>
parents:
8161
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
10263 | 8 |
# GNU General Public License version 2 or any later version. |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
9 |
|
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
10 |
# Modifying this script is tricky because it has many modes: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
11 |
# - serial (default) vs parallel (-jN, N > 1) |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
12 |
# - no coverage (default) vs coverage (-c, -C, -s) |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
13 |
# - temp install (default) vs specific hg script (--with-hg, --local) |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
14 |
# - tests are a mix of shell scripts and Python scripts |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
15 |
# |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
16 |
# If you change this script, it is recommended that you ensure you |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
17 |
# haven't broken it by running it in various modes with a representative |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
18 |
# sample of test scripts. For example: |
8843
eb7b247a98ea
kill trailing whitespace
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8724
diff
changeset
|
19 |
# |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
20 |
# 1) serial, no coverage, temp install: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
21 |
# ./run-tests.py test-s* |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
22 |
# 2) serial, no coverage, local hg: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
23 |
# ./run-tests.py --local test-s* |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
24 |
# 3) serial, coverage, temp install: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
25 |
# ./run-tests.py -c test-s* |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
26 |
# 4) serial, coverage, local hg: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
27 |
# ./run-tests.py -c --local test-s* # unsupported |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
28 |
# 5) parallel, no coverage, temp install: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
29 |
# ./run-tests.py -j2 test-s* |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
30 |
# 6) parallel, no coverage, local hg: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
31 |
# ./run-tests.py -j2 --local test-s* |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
32 |
# 7) parallel, coverage, temp install: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
33 |
# ./run-tests.py -j2 -c test-s* # currently broken |
9899
be574a37a8ae
run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents:
9707
diff
changeset
|
34 |
# 8) parallel, coverage, local install: |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
35 |
# ./run-tests.py -j2 -c --local test-s* # unsupported (and broken) |
9899
be574a37a8ae
run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents:
9707
diff
changeset
|
36 |
# 9) parallel, custom tmp dir: |
be574a37a8ae
run-tests: give each child its own tmp dir (issue1911)
Greg Ward <greg@gerg.ca>
parents:
9707
diff
changeset
|
37 |
# ./run-tests.py -j2 --tmpdir /tmp/myhgtests |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
38 |
# |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
39 |
# (You could use any subset of the tests: test-s* happens to match |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
40 |
# enough that it's worth doing parallel runs, few enough that it |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
41 |
# completes fairly quickly, includes both shell and Python scripts, and |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
42 |
# includes some scripts that run daemon processes.) |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
43 |
|
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
44 |
from distutils import version |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
45 |
import difflib |
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
46 |
import errno |
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
47 |
import optparse |
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
48 |
import os |
10905
13a1b2fb7ef2
pylint, pyflakes: remove unused or duplicate imports
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10903
diff
changeset
|
49 |
import shutil |
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
50 |
import subprocess |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
51 |
import signal |
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
52 |
import sys |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
53 |
import tempfile |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
54 |
import time |
18616
35b4affe6fdd
test: display used python hash seed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18565
diff
changeset
|
55 |
import random |
11741
431e2bf37ae7
tests: basic support for unified tests
Matt Mackall <mpm@selenic.com>
parents:
11740
diff
changeset
|
56 |
import re |
14000
636a6f5aa2cd
run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents:
13999
diff
changeset
|
57 |
import threading |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
16906
diff
changeset
|
58 |
import killdaemons as killmod |
18057
6b88ded2a993
run-tests: support running tests in parallel on windows
Bryan O'Sullivan <bryano@fb.com>
parents:
18050
diff
changeset
|
59 |
import Queue as queue |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
60 |
|
14019
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
61 |
processlock = threading.Lock() |
19413
a4de0d3dc35a
run-tests: lock popen wait/poll
Brendan Cully <brendan@kublai.com>
parents:
19407
diff
changeset
|
62 |
|
19415
a0699972e75a
run-tests: replace popen locking with a noop _cleanup handler on py24
Brendan Cully <brendan@kublai.com>
parents:
19414
diff
changeset
|
63 |
# subprocess._cleanup can race with any Popen.wait or Popen.poll on py24 |
a0699972e75a
run-tests: replace popen locking with a noop _cleanup handler on py24
Brendan Cully <brendan@kublai.com>
parents:
19414
diff
changeset
|
64 |
# http://bugs.python.org/issue1731717 for details. We shouldn't be producing |
a0699972e75a
run-tests: replace popen locking with a noop _cleanup handler on py24
Brendan Cully <brendan@kublai.com>
parents:
19414
diff
changeset
|
65 |
# zombies but it's pretty harmless even if we do. |
20219
f694cd81b600
run-tests: better check for python version
Simon Heimberg <simohe@besonet.ch>
parents:
20046
diff
changeset
|
66 |
if sys.version_info < (2, 5): |
19415
a0699972e75a
run-tests: replace popen locking with a noop _cleanup handler on py24
Brendan Cully <brendan@kublai.com>
parents:
19414
diff
changeset
|
67 |
subprocess._cleanup = lambda: None |
14019
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
68 |
|
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
69 |
closefds = os.name == 'posix' |
19262
7864e8f274fe
run-tests: add env dict to isolate test environment
Matt Mackall <mpm@selenic.com>
parents:
19252
diff
changeset
|
70 |
def Popen4(cmd, wd, timeout, env=None): |
14019
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
71 |
processlock.acquire() |
19262
7864e8f274fe
run-tests: add env dict to isolate test environment
Matt Mackall <mpm@selenic.com>
parents:
19252
diff
changeset
|
72 |
p = subprocess.Popen(cmd, shell=True, bufsize=-1, cwd=wd, env=env, |
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
73 |
close_fds=closefds, |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
74 |
stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
75 |
stderr=subprocess.STDOUT) |
14019
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
76 |
processlock.release() |
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
77 |
|
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
78 |
p.fromchild = p.stdout |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
79 |
p.tochild = p.stdin |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
80 |
p.childerr = p.stderr |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
81 |
|
14337
439ed4721a6d
run-tests: ignore timeout when Popen.terminate is unavailable
Patrick Mezard <pmezard@gmail.com>
parents:
14336
diff
changeset
|
82 |
p.timeout = False |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
83 |
if timeout: |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
84 |
def t(): |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
85 |
start = time.time() |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
86 |
while time.time() - start < timeout and p.returncode is None: |
16346
48692b416fbc
tests: shorten post-test sleeps
Matt Mackall <mpm@selenic.com>
parents:
15942
diff
changeset
|
87 |
time.sleep(.1) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
88 |
p.timeout = True |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
89 |
if p.returncode is None: |
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
90 |
terminate(p) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
91 |
threading.Thread(target=t).start() |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
92 |
|
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
93 |
return p |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
94 |
|
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
|
95 |
# 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
|
96 |
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
|
97 |
SKIPPED_PREFIX = 'skipped: ' |
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
98 |
FAILED_PREFIX = 'hghave check failed: ' |
15448
873f94ecd706
run-tests: convert windows paths to unix
Mads Kiilerich <mads@kiilerich.com>
parents:
15447
diff
changeset
|
99 |
PYTHON = sys.executable.replace('\\', '/') |
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
100 |
IMPL_PATH = 'PYTHONPATH' |
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
101 |
if 'java' in sys.platform: |
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
102 |
IMPL_PATH = 'JYTHONPATH' |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
103 |
|
21231
1ce16c7b7fb4
run-tests: initialize global variables to suppress pyflakes warning
Yuya Nishihara <yuya@tcha.org>
parents:
21024
diff
changeset
|
104 |
TESTDIR = HGTMP = INST = BINDIR = TMPBINDIR = PYTHONDIR = None |
1ce16c7b7fb4
run-tests: initialize global variables to suppress pyflakes warning
Yuya Nishihara <yuya@tcha.org>
parents:
21024
diff
changeset
|
105 |
|
18049
07ad75b22910
run-tests: check for the correct python when starting
Bryan O'Sullivan <bryano@fb.com>
parents:
18048
diff
changeset
|
106 |
requiredtools = [os.path.basename(sys.executable), "diff", "grep", "unzip", |
07ad75b22910
run-tests: check for the correct python when starting
Bryan O'Sullivan <bryano@fb.com>
parents:
18048
diff
changeset
|
107 |
"gunzip", "bunzip2", "sed"] |
20019
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
108 |
createdfiles = [] |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
109 |
|
6366
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
110 |
defaults = { |
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
111 |
'jobs': ('HGTEST_JOBS', 1), |
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
112 |
'timeout': ('HGTEST_TIMEOUT', 180), |
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
113 |
'port': ('HGTEST_PORT', 20059), |
15941
af289d6cd422
tests: let run-tests.py default to use 'sh' in $PATH instead of '/bin/sh'
Mads Kiilerich <mads@kiilerich.com>
parents:
15940
diff
changeset
|
114 |
'shell': ('HGTEST_SHELL', 'sh'), |
6366
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
115 |
} |
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
116 |
|
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
117 |
def parselistfiles(files, listtype, warn=True): |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
118 |
entries = dict() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
119 |
for filename in files: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
120 |
try: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
121 |
path = os.path.expanduser(os.path.expandvars(filename)) |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
122 |
f = open(path, "r") |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
123 |
except IOError, err: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
124 |
if err.errno != errno.ENOENT: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
125 |
raise |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
126 |
if warn: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
127 |
print "warning: no such %s file: %s" % (listtype, filename) |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
128 |
continue |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
129 |
|
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
130 |
for line in f.readlines(): |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
131 |
line = line.split('#', 1)[0].strip() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
132 |
if line: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
133 |
entries[line] = filename |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
134 |
|
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
135 |
f.close() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
136 |
return entries |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
137 |
|
21008
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
138 |
def getparser(): |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
139 |
parser = optparse.OptionParser("%prog [options] [tests]") |
11039 | 140 |
|
141 |
# keep these sorted |
|
142 |
parser.add_option("--blacklist", action="append", |
|
143 |
help="skip tests listed in the specified blacklist file") |
|
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
144 |
parser.add_option("--whitelist", action="append", |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
145 |
help="always run tests listed in the specified whitelist file") |
20821
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
146 |
parser.add_option("--changed", type="string", |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
147 |
help="run tests that are changed in parent rev or working directory") |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
148 |
parser.add_option("-C", "--annotate", action="store_true", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
149 |
help="output files annotated with coverage") |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
150 |
parser.add_option("-c", "--cover", action="store_true", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
151 |
help="print a test coverage report") |
11039 | 152 |
parser.add_option("-d", "--debug", action="store_true", |
153 |
help="debug mode: write output of test scripts to console" |
|
21024
7731a2281cf0
spelling: fixes from spell checker
Mads Kiilerich <madski@unity3d.com>
parents:
21023
diff
changeset
|
154 |
" rather than capturing and diffing it (disables timeout)") |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
155 |
parser.add_option("-f", "--first", action="store_true", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
156 |
help="exit on the first test failure") |
15859
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
157 |
parser.add_option("-H", "--htmlcov", action="store_true", |
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
158 |
help="create an HTML report of the coverage of the files") |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
159 |
parser.add_option("-i", "--interactive", action="store_true", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
160 |
help="prompt to accept changed output") |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
161 |
parser.add_option("-j", "--jobs", type="int", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
162 |
help="number of jobs to run in parallel" |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
163 |
" (default: $%s or %d)" % defaults['jobs']) |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
164 |
parser.add_option("--keep-tmpdir", action="store_true", |
9706
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
165 |
help="keep temporary directory after running tests") |
11039 | 166 |
parser.add_option("-k", "--keywords", |
167 |
help="run tests matching keywords") |
|
168 |
parser.add_option("-l", "--local", action="store_true", |
|
169 |
help="shortcut for --with-hg=<testdir>/../hg") |
|
19283
8300adf9ca33
run-tests: add --loop support
Matt Mackall <mpm@selenic.com>
parents:
19282
diff
changeset
|
170 |
parser.add_option("--loop", action="store_true", |
8300adf9ca33
run-tests: add --loop support
Matt Mackall <mpm@selenic.com>
parents:
19282
diff
changeset
|
171 |
help="loop tests repeatedly") |
11039 | 172 |
parser.add_option("-n", "--nodiff", action="store_true", |
173 |
help="skip showing test changes") |
|
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
174 |
parser.add_option("-p", "--port", type="int", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
175 |
help="port on which servers should listen" |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
176 |
" (default: $%s or %d)" % defaults['port']) |
17966
ae20cde050c2
run-tests: add a --compiler option
Bryan O'Sullivan <bryano@fb.com>
parents:
17965
diff
changeset
|
177 |
parser.add_option("--compiler", type="string", |
ae20cde050c2
run-tests: add a --compiler option
Bryan O'Sullivan <bryano@fb.com>
parents:
17965
diff
changeset
|
178 |
help="compiler to build with") |
11039 | 179 |
parser.add_option("--pure", action="store_true", |
180 |
help="use pure Python code instead of C extensions") |
|
181 |
parser.add_option("-R", "--restart", action="store_true", |
|
182 |
help="restart at last error") |
|
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
183 |
parser.add_option("-r", "--retest", action="store_true", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
184 |
help="retest failed tests") |
9580
25858f9e65e8
run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents:
9408
diff
changeset
|
185 |
parser.add_option("-S", "--noskips", action="store_true", |
25858f9e65e8
run-tests: add --noskips option
Matt Mackall <mpm@selenic.com>
parents:
9408
diff
changeset
|
186 |
help="don't report skip tests verbosely") |
14202
b68a41420397
run-tests: add --shell command line flag
Martin Geisler <mg@lazybytes.net>
parents:
14201
diff
changeset
|
187 |
parser.add_option("--shell", type="string", |
b68a41420397
run-tests: add --shell command line flag
Martin Geisler <mg@lazybytes.net>
parents:
14201
diff
changeset
|
188 |
help="shell to use (default: $%s or %s)" % defaults['shell']) |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
189 |
parser.add_option("-t", "--timeout", type="int", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
190 |
help="kill errant tests after TIMEOUT seconds" |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
191 |
" (default: $%s or %d)" % defaults['timeout']) |
17921
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
192 |
parser.add_option("--time", action="store_true", |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
193 |
help="time how long each test takes") |
11039 | 194 |
parser.add_option("--tmpdir", type="string", |
195 |
help="run tests in the given temporary directory" |
|
196 |
" (implies --keep-tmpdir)") |
|
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
197 |
parser.add_option("-v", "--verbose", action="store_true", |
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
198 |
help="output verbose messages") |
11040
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
199 |
parser.add_option("--view", type="string", |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
200 |
help="external diff viewer") |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
201 |
parser.add_option("--with-hg", type="string", |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
202 |
metavar="HG", |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
203 |
help="test using specified hg script rather than a " |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
204 |
"temporary installation") |
9028
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
205 |
parser.add_option("-3", "--py3k-warnings", action="store_true", |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
206 |
help="enable Py3k warnings on Python 2.6+") |
14134
8468ec1109d1
run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents:
14062
diff
changeset
|
207 |
parser.add_option('--extra-config-opt', action="append", |
8468ec1109d1
run-tests: add flag to provide extra hgrc options for test runs
Augie Fackler <durin42@gmail.com>
parents:
14062
diff
changeset
|
208 |
help='set the given config opt in the test hgrc') |
19057
3d265e0822d3
run-tests: introduce --random for running tests in random error
Mads Kiilerich <madski@unity3d.com>
parents:
18788
diff
changeset
|
209 |
parser.add_option('--random', action="store_true", |
3d265e0822d3
run-tests: introduce --random for running tests in random error
Mads Kiilerich <madski@unity3d.com>
parents:
18788
diff
changeset
|
210 |
help='run tests in random order') |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
211 |
|
14201
57e04ded3da4
run-tests: use type of default to convert environment variable
Martin Geisler <mg@lazybytes.net>
parents:
14192
diff
changeset
|
212 |
for option, (envvar, default) in defaults.items(): |
57e04ded3da4
run-tests: use type of default to convert environment variable
Martin Geisler <mg@lazybytes.net>
parents:
14192
diff
changeset
|
213 |
defaults[option] = type(default)(os.environ.get(envvar, default)) |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
214 |
parser.set_defaults(**defaults) |
21008
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
215 |
|
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
216 |
return parser |
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
217 |
|
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
218 |
def parseargs(args, parser): |
21006
723e41ad59b4
run-tests: Pass arguments into argument parser
Gregory Szorc <gregory.szorc@gmail.com>
parents:
20821
diff
changeset
|
219 |
(options, args) = parser.parse_args(args) |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
220 |
|
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
221 |
# jython is always pure |
10766
afbcea270bb8
run-tests: force to test pure on pypy as well
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10765
diff
changeset
|
222 |
if 'java' in sys.platform or '__pypy__' in sys.modules: |
10765
fd31a3237498
Fix run-tests.py -jX after 2ed667a9dfcb
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10758
diff
changeset
|
223 |
options.pure = True |
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
224 |
|
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
225 |
if options.with_hg: |
15942
d7a34c07e69b
run-tests: expand user in --with-hg
Mads Kiilerich <mads@kiilerich.com>
parents:
15941
diff
changeset
|
226 |
options.with_hg = os.path.expanduser(options.with_hg) |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
227 |
if not (os.path.isfile(options.with_hg) and |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
228 |
os.access(options.with_hg, os.X_OK)): |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
229 |
parser.error('--with-hg must specify an executable hg script') |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
230 |
if not os.path.basename(options.with_hg) == 'hg': |
14359
ad5c68a0db6a
run-tests: print a newline after all warnings
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14340
diff
changeset
|
231 |
sys.stderr.write('warning: --with-hg should specify an hg script\n') |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
232 |
if options.local: |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
233 |
testdir = os.path.dirname(os.path.realpath(sys.argv[0])) |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
234 |
hgbin = os.path.join(os.path.dirname(testdir), 'hg') |
16538
dd194e5df4c1
tests: don't require 'hg' without extension on windows
Mads Kiilerich <mads@kiilerich.com>
parents:
16346
diff
changeset
|
235 |
if os.name != 'nt' and not os.access(hgbin, os.X_OK): |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
236 |
parser.error('--local specified, but %r not found or not executable' |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
237 |
% hgbin) |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
238 |
options.with_hg = hgbin |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
239 |
|
15859
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
240 |
options.anycoverage = options.cover or options.annotate or options.htmlcov |
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
241 |
if options.anycoverage: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
242 |
try: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
243 |
import coverage |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
244 |
covver = version.StrictVersion(coverage.__version__).version |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
245 |
if covver < (3, 3): |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
246 |
parser.error('coverage options require coverage 3.3 or later') |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
247 |
except ImportError: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
248 |
parser.error('coverage options now require the coverage package') |
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
249 |
|
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
250 |
if options.anycoverage and options.local: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
251 |
# this needs some path mangling somewhere, I guess |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
252 |
parser.error("sorry, coverage options do not work when --local " |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
253 |
"is specified") |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
254 |
|
19250
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
255 |
global verbose |
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
256 |
if options.verbose: |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
257 |
verbose = '' |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
258 |
|
9394
31203db1b2ac
run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9031
diff
changeset
|
259 |
if options.tmpdir: |
31203db1b2ac
run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9031
diff
changeset
|
260 |
options.tmpdir = os.path.expanduser(options.tmpdir) |
31203db1b2ac
run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9031
diff
changeset
|
261 |
|
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
262 |
if options.jobs < 1: |
9408
70bf7f853adc
run-tests: standardize on --foo instead of -f/--foo
Martin Geisler <mg@lazybytes.net>
parents:
9407
diff
changeset
|
263 |
parser.error('--jobs must be positive') |
9707
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
264 |
if options.interactive and options.debug: |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
265 |
parser.error("-i/--interactive and -d/--debug are incompatible") |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
266 |
if options.debug: |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
267 |
if options.timeout != defaults['timeout']: |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
268 |
sys.stderr.write( |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
269 |
'warning: --timeout option ignored with --debug\n') |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
270 |
options.timeout = 0 |
9028
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
271 |
if options.py3k_warnings: |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
272 |
if sys.version_info[:2] < (2, 6) or sys.version_info[:2] >= (3, 0): |
9408
70bf7f853adc
run-tests: standardize on --foo instead of -f/--foo
Martin Geisler <mg@lazybytes.net>
parents:
9407
diff
changeset
|
273 |
parser.error('--py3k-warnings can only be used on Python 2.6+') |
9959
b37b060d84c7
run-tests: add a "--blacklist target" option to skip predefined test lists
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9958
diff
changeset
|
274 |
if options.blacklist: |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
275 |
options.blacklist = parselistfiles(options.blacklist, 'blacklist') |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
276 |
if options.whitelist: |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
277 |
options.whitelisted = parselistfiles(options.whitelist, 'whitelist') |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
278 |
else: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
279 |
options.whitelisted = {} |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
280 |
|
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
281 |
return (options, args) |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
282 |
|
5800
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
283 |
def rename(src, dst): |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
284 |
"""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
|
285 |
for existing destination support. |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
286 |
""" |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
287 |
shutil.copy(src, dst) |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
288 |
os.remove(src) |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
289 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
290 |
def parsehghaveoutput(lines): |
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
291 |
'''Parse hghave log lines. |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
292 |
Return tuple of lists (missing, failed): |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
293 |
* the missing/unknown features |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
294 |
* the features for which existence check failed''' |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
295 |
missing = [] |
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
296 |
failed = [] |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
297 |
for line in lines: |
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
298 |
if line.startswith(SKIPPED_PREFIX): |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
299 |
line = line.splitlines()[0] |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
300 |
missing.append(line[len(SKIPPED_PREFIX):]) |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
301 |
elif line.startswith(FAILED_PREFIX): |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
302 |
line = line.splitlines()[0] |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
303 |
failed.append(line[len(FAILED_PREFIX):]) |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
304 |
|
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
305 |
return missing, failed |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
306 |
|
10088
ec8304e66ea5
run-tests.py: Show paths to failing tests, .err and .out
Mads Kiilerich <mads@kiilerich.com>
parents:
10030
diff
changeset
|
307 |
def showdiff(expected, output, ref, err): |
14062
643381286e0c
run-tests: print a new line before writing the diff
Idan Kamara <idankk86@gmail.com>
parents:
14037
diff
changeset
|
308 |
|
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
309 |
servefail = False |
10088
ec8304e66ea5
run-tests.py: Show paths to failing tests, .err and .out
Mads Kiilerich <mads@kiilerich.com>
parents:
10030
diff
changeset
|
310 |
for line in difflib.unified_diff(expected, output, ref, err): |
2247
546c76e5a3e6
run-tests.py: fix handling of newlines.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2246
diff
changeset
|
311 |
sys.stdout.write(line) |
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
312 |
if not servefail and line.startswith( |
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
313 |
'+ abort: child process failed to start'): |
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
314 |
servefail = True |
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
315 |
return {'servefail': servefail} |
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
316 |
|
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
317 |
|
19250
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
318 |
verbose = False |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
319 |
def vlog(*msg): |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
320 |
if verbose is not False: |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
321 |
iolock.acquire() |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
322 |
if verbose: |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
323 |
print verbose, |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
324 |
for m in msg: |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
325 |
print m, |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
326 |
|
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
327 |
sys.stdout.flush() |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
328 |
iolock.release() |
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
329 |
|
19251
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
330 |
def log(*msg): |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
331 |
iolock.acquire() |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
332 |
if verbose: |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
333 |
print verbose, |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
334 |
for m in msg: |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
335 |
print m, |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
336 |
|
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
337 |
sys.stdout.flush() |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
338 |
iolock.release() |
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
339 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
340 |
def findprogram(program): |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
341 |
"""Search PATH for a executable program""" |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
342 |
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
|
343 |
name = os.path.join(p, program) |
14335
220f31030e7f
run-tests: fix python executable detection and copy on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
14282
diff
changeset
|
344 |
if os.name == 'nt' or os.access(name, os.X_OK): |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
345 |
return name |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
346 |
return None |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
347 |
|
19242
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
348 |
def createhgrc(path, options): |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
349 |
# create a fresh hgrc |
19299
cdc612db2ffb
run-tests: open hgrc file only for writing
Simon Heimberg <simohe@besonet.ch>
parents:
19294
diff
changeset
|
350 |
hgrc = open(path, 'w') |
19242
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
351 |
hgrc.write('[ui]\n') |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
352 |
hgrc.write('slash = True\n') |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
353 |
hgrc.write('interactive = False\n') |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
354 |
hgrc.write('[defaults]\n') |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
355 |
hgrc.write('backout = -d "0 0"\n') |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
356 |
hgrc.write('commit = -d "0 0"\n') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
19759
diff
changeset
|
357 |
hgrc.write('shelve = --date "0 0"\n') |
19242
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
358 |
hgrc.write('tag = -d "0 0"\n') |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
359 |
if options.extra_config_opt: |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
360 |
for opt in options.extra_config_opt: |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
361 |
section, key = opt.split('.', 1) |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
362 |
assert '=' in key, ('extra config opt %s must ' |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
363 |
'have an = for assignment' % opt) |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
364 |
hgrc.write('[%s]\n%s\n' % (section, key)) |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
365 |
hgrc.close() |
d25fc3264d44
run-tests: pull hgrc creation out as function
Matt Mackall <mpm@selenic.com>
parents:
19241
diff
changeset
|
366 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
367 |
def checktools(): |
2133
4334be196f8d
Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents:
2110
diff
changeset
|
368 |
# 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
|
369 |
# stuff from coreutils (cat, rm, etc) are not tested |
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
370 |
for p in requiredtools: |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
371 |
if os.name == 'nt' and not p.endswith('.exe'): |
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
|
372 |
p += '.exe' |
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
373 |
found = findprogram(p) |
2133
4334be196f8d
Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents:
2110
diff
changeset
|
374 |
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
|
375 |
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
|
376 |
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
|
377 |
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
|
378 |
|
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
379 |
def terminate(proc): |
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
380 |
"""Terminate subprocess (with fallback for Python versions < 2.6)""" |
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
381 |
vlog('# Terminating process %d' % proc.pid) |
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
382 |
try: |
14971
0b21ae0a2366
tests: use getattr instead of hasattr
Augie Fackler <durin42@gmail.com>
parents:
14867
diff
changeset
|
383 |
getattr(proc, 'terminate', lambda : os.kill(proc.pid, signal.SIGTERM))() |
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
384 |
except OSError: |
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
385 |
pass |
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
386 |
|
19263
062c0a0a5549
run-tests: use env dict to kill daemons
Matt Mackall <mpm@selenic.com>
parents:
19262
diff
changeset
|
387 |
def killdaemons(pidfile): |
062c0a0a5549
run-tests: use env dict to kill daemons
Matt Mackall <mpm@selenic.com>
parents:
19262
diff
changeset
|
388 |
return killmod.killdaemons(pidfile, tryhard=False, remove=True, |
17464
eddfb9a550d0
run-tests: do not duplicate killdaemons() code
Patrick Mezard <patrick@mezard.eu>
parents:
16906
diff
changeset
|
389 |
logfn=vlog) |
10336
bc9a3bb267fa
run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents:
10300
diff
changeset
|
390 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
391 |
def cleanup(options): |
6208
c88b9e597588
tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
6004
diff
changeset
|
392 |
if not options.keep_tmpdir: |
8671
a434c94b48e7
run-tests: show PID if running in parallel mode with -v.
Greg Ward <greg-hg@gerg.ca>
parents:
8651
diff
changeset
|
393 |
vlog("# Cleaning up HGTMP", HGTMP) |
6208
c88b9e597588
tests: add --keep-tmp to run-tests.py to debug test environment
Peter Arrenbrecht <peter.arrenbrecht@gmail.com>
parents:
6004
diff
changeset
|
394 |
shutil.rmtree(HGTMP, True) |
20019
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
395 |
for f in createdfiles: |
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
396 |
try: |
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
397 |
os.remove(f) |
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
398 |
except OSError: |
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
399 |
pass |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
400 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
401 |
def usecorrectpython(): |
2570
2264b2b077a1
run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2409
diff
changeset
|
402 |
# 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
|
403 |
# interpreter we use or bad things will happen. |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
404 |
pyexename = sys.platform == 'win32' and 'python.exe' or 'python' |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
405 |
if getattr(os, 'symlink', None): |
18061
0e4316c3a703
run-tests: fix whitespace nonsense
Bryan O'Sullivan <bos@serpentine.com>
parents:
18060
diff
changeset
|
406 |
vlog("# Making python executable in test path a symlink to '%s'" % |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
407 |
sys.executable) |
20541
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
408 |
mypython = os.path.join(TMPBINDIR, pyexename) |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
409 |
try: |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
410 |
if os.readlink(mypython) == sys.executable: |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
411 |
return |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
412 |
os.unlink(mypython) |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
413 |
except OSError, err: |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
414 |
if err.errno != errno.ENOENT: |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
415 |
raise |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
416 |
if findprogram(pyexename) != sys.executable: |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
417 |
try: |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
418 |
os.symlink(sys.executable, mypython) |
20019
edbf7f1fd2a2
run-tests: remove files that we potentially create outside of $TMPDIR
Sean Farley <sean.michael.farley@gmail.com>
parents:
20018
diff
changeset
|
419 |
createdfiles.append(mypython) |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
420 |
except OSError, err: |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
421 |
# child processes may race, which is harmless |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
422 |
if err.errno != errno.EEXIST: |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
423 |
raise |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
424 |
else: |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
425 |
exedir, exename = os.path.split(sys.executable) |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
426 |
vlog("# Modifying search path to find %s as %s in '%s'" % |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
427 |
(exename, pyexename, exedir)) |
18059
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
428 |
path = os.environ['PATH'].split(os.pathsep) |
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
429 |
while exedir in path: |
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
430 |
path.remove(exedir) |
c135ab6413b4
run-tests: on windows, put correct python at front of PATH
Bryan O'Sullivan <bryano@fb.com>
parents:
18058
diff
changeset
|
431 |
os.environ['PATH'] = os.pathsep.join([exedir] + path) |
18244
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
432 |
if not findprogram(pyexename): |
5a3c71b0e042
run-tests.py: fix handling of symlink to the right python
Mads Kiilerich <mads@kiilerich.com>
parents:
18230
diff
changeset
|
433 |
print "WARNING: Cannot find %s in search path" % pyexename |
3223
53e843840349
Whitespace/Tab cleanup
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2989
diff
changeset
|
434 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
435 |
def installhg(options): |
2133
4334be196f8d
Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents:
2110
diff
changeset
|
436 |
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
|
437 |
installerrs = os.path.join("tests", "install.err") |
17966
ae20cde050c2
run-tests: add a --compiler option
Bryan O'Sullivan <bryano@fb.com>
parents:
17965
diff
changeset
|
438 |
compiler = '' |
ae20cde050c2
run-tests: add a --compiler option
Bryan O'Sullivan <bryano@fb.com>
parents:
17965
diff
changeset
|
439 |
if options.compiler: |
ae20cde050c2
run-tests: add a --compiler option
Bryan O'Sullivan <bryano@fb.com>
parents:
17965
diff
changeset
|
440 |
compiler = '--compiler ' + options.compiler |
7723
a343cd25e425
run-tests: add --pure flag for using pure Python modules
Martin Geisler <mg@daimi.au.dk>
parents:
7529
diff
changeset
|
441 |
pure = options.pure and "--pure" or "" |
19758
14c4f605f0fc
run-tests: if run by python3, execute setup.py with --c2to3
Augie Fackler <raf@durin42.com>
parents:
19527
diff
changeset
|
442 |
py3 = '' |
14c4f605f0fc
run-tests: if run by python3, execute setup.py with --c2to3
Augie Fackler <raf@durin42.com>
parents:
19527
diff
changeset
|
443 |
if sys.version_info[0] == 3: |
14c4f605f0fc
run-tests: if run by python3, execute setup.py with --c2to3
Augie Fackler <raf@durin42.com>
parents:
19527
diff
changeset
|
444 |
py3 = '--c2to3' |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
445 |
|
5267
b817d17c7ee5
Make run-tests.py work when invoked outside of tests.
Brendan Cully <brendan@kublai.com>
parents:
5251
diff
changeset
|
446 |
# Run installer in hg root |
8943
09ff905cdc86
run-tests: use os.path.realpath() to find hg's setup.py.
Greg Ward <greg-hg@gerg.ca>
parents:
8843
diff
changeset
|
447 |
script = os.path.realpath(sys.argv[0]) |
09ff905cdc86
run-tests: use os.path.realpath() to find hg's setup.py.
Greg Ward <greg-hg@gerg.ca>
parents:
8843
diff
changeset
|
448 |
hgroot = os.path.dirname(os.path.dirname(script)) |
09ff905cdc86
run-tests: use os.path.realpath() to find hg's setup.py.
Greg Ward <greg-hg@gerg.ca>
parents:
8843
diff
changeset
|
449 |
os.chdir(hgroot) |
9905
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
450 |
nohome = '--home=""' |
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
451 |
if os.name == 'nt': |
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
452 |
# The --home="" trick works only on OS where os.sep == '/' |
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
453 |
# because of a distutils convert_path() fast-path. Avoid it at |
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
454 |
# least on Windows for now, deal with .pydistutils.cfg bugs |
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
455 |
# when they happen. |
95517eb3c9a7
run-tests: work around a distutils bug triggered by 0a8a43b4ca75
Patrick Mezard <pmezard@gmail.com>
parents:
9902
diff
changeset
|
456 |
nohome = '' |
19758
14c4f605f0fc
run-tests: if run by python3, execute setup.py with --c2to3
Augie Fackler <raf@durin42.com>
parents:
19527
diff
changeset
|
457 |
cmd = ('%(exe)s setup.py %(py3)s %(pure)s clean --all' |
17966
ae20cde050c2
run-tests: add a --compiler option
Bryan O'Sullivan <bryano@fb.com>
parents:
17965
diff
changeset
|
458 |
' build %(compiler)s --build-base="%(base)s"' |
17965
0167da3cbc44
run-tests: make build command line less intimidating
Bryan O'Sullivan <bryano@fb.com>
parents:
17936
diff
changeset
|
459 |
' install --force --prefix="%(prefix)s" --install-lib="%(libdir)s"' |
0167da3cbc44
run-tests: make build command line less intimidating
Bryan O'Sullivan <bryano@fb.com>
parents:
17936
diff
changeset
|
460 |
' --install-scripts="%(bindir)s" %(nohome)s >%(logfile)s 2>&1' |
20680
d3d3e94e2910
run-tests: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20622
diff
changeset
|
461 |
% {'exe': sys.executable, 'py3': py3, 'pure': pure, |
d3d3e94e2910
run-tests: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20622
diff
changeset
|
462 |
'compiler': compiler, 'base': os.path.join(HGTMP, "build"), |
d3d3e94e2910
run-tests: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20622
diff
changeset
|
463 |
'prefix': INST, 'libdir': PYTHONDIR, 'bindir': BINDIR, |
d3d3e94e2910
run-tests: move from dict() construction to {} literals
Augie Fackler <raf@durin42.com>
parents:
20622
diff
changeset
|
464 |
'nohome': nohome, 'logfile': 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
|
465 |
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
|
466 |
if os.system(cmd) == 0: |
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
467 |
if not options.verbose: |
2133
4334be196f8d
Tidyups for run-tests.py inc. try/finally cleanup and allow tests to be specified on command line
Stephen Darnell <stephen@darnell.plus.com>
parents:
2110
diff
changeset
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
os.chdir(TESTDIR) |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
476 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
477 |
usecorrectpython() |
2570
2264b2b077a1
run-tests.py: make tests use same python interpreter as test harness.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2409
diff
changeset
|
478 |
|
9028
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
479 |
if options.py3k_warnings and not options.anycoverage: |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
480 |
vlog("# Updating hg command to enable Py3k Warnings switch") |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
481 |
f = open(os.path.join(BINDIR, 'hg'), 'r') |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
482 |
lines = [line.rstrip() for line in f] |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
483 |
lines[0] += ' -3' |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
484 |
f.close() |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
485 |
f = open(os.path.join(BINDIR, 'hg'), 'w') |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
486 |
for line in lines: |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
487 |
f.write(line + '\n') |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
488 |
f.close() |
bea567ae3ff6
tests: add -3 switch to run-tests.py
Alejandro Santos <alejolp@alejolp.com>
parents:
8943
diff
changeset
|
489 |
|
14336
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
490 |
hgbat = os.path.join(BINDIR, 'hg.bat') |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
491 |
if os.path.isfile(hgbat): |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
492 |
# hg.bat expects to be put in bin/scripts while run-tests.py |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
493 |
# installation layout put it in bin/ directly. Fix it |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
494 |
f = open(hgbat, 'rb') |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
495 |
data = f.read() |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
496 |
f.close() |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
497 |
if '"%~dp0..\python" "%~dp0hg" %*' in data: |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
498 |
data = data.replace('"%~dp0..\python" "%~dp0hg" %*', |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
499 |
'"%~dp0python" "%~dp0hg" %*') |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
500 |
f = open(hgbat, 'wb') |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
501 |
f.write(data) |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
502 |
f.close() |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
503 |
else: |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
504 |
print 'WARNING: cannot fix hg.bat reference to python.exe' |
0cbf0d1f7939
run-tests: fix hg.bat python reference
Patrick Mezard <pmezard@gmail.com>
parents:
14335
diff
changeset
|
505 |
|
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
506 |
if options.anycoverage: |
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
507 |
custom = os.path.join(TESTDIR, 'sitecustomize.py') |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
508 |
target = os.path.join(PYTHONDIR, 'sitecustomize.py') |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
509 |
vlog('# Installing coverage trigger to %s' % target) |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
510 |
shutil.copyfile(custom, target) |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
511 |
rc = os.path.join(TESTDIR, '.coveragerc') |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
512 |
vlog('# Installing coverage rc to %s' % rc) |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
513 |
os.environ['COVERAGE_PROCESS_START'] = rc |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
514 |
fn = os.path.join(INST, '..', '.coverage') |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
515 |
os.environ['COVERAGE_FILE'] = fn |
8092
c49578c5122f
run-tests: move _hgpath() up so it's not in the middle of the main program.
Greg Ward <greg-hg@gerg.ca>
parents:
8091
diff
changeset
|
516 |
|
17921
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
517 |
def outputtimes(options): |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
518 |
vlog('# Producing time report') |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
519 |
times.sort(key=lambda t: (t[1], t[0]), reverse=True) |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
520 |
cols = '%7.3f %s' |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
521 |
print '\n%-7s %s' % ('Time', 'Test') |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
522 |
for test, timetaken in times: |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
523 |
print cols % (timetaken, test) |
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
524 |
|
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
525 |
def outputcoverage(options): |
8620
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
526 |
|
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
527 |
vlog('# Producing coverage report') |
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
528 |
os.chdir(PYTHONDIR) |
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
529 |
|
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
530 |
def covrun(*args): |
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
531 |
cmd = 'coverage %s' % ' '.join(args) |
8620
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
532 |
vlog('# Running: %s' % cmd) |
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
533 |
os.system(cmd) |
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
534 |
|
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
535 |
covrun('-c') |
15858
14132a55d66b
run-tests: use a list comprehension instead of map
Matt Mackall <mpm@selenic.com>
parents:
15857
diff
changeset
|
536 |
omit = ','.join(os.path.join(x, '*') for x in [BINDIR, TESTDIR]) |
8620
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
537 |
covrun('-i', '-r', '"--omit=%s"' % omit) # report |
15859
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
538 |
if options.htmlcov: |
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
539 |
htmldir = os.path.join(TESTDIR, 'htmlcov') |
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
540 |
covrun('-i', '-b', '"--directory=%s"' % htmldir, '"--omit=%s"' % omit) |
2145
5bb3cb9e5d13
make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2144
diff
changeset
|
541 |
if options.annotate: |
5bb3cb9e5d13
make indentation of coverage code in run-tests.py nicer.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2144
diff
changeset
|
542 |
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
|
543 |
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
|
544 |
os.mkdir(adir) |
8620
b38f275bb5c2
tests: make coverage run in parallel mode, clean up coverage code
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
8592
diff
changeset
|
545 |
covrun('-i', '-a', '"--directory=%s"' % adir, '"--omit=%s"' % omit) |
2144
d3bddedfdbd0
Add code coverage to the python version of run-tests (inc. annotation)
Stephen Darnell <stephen@darnell.plus.com>
parents:
2133
diff
changeset
|
546 |
|
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
547 |
class Test(object): |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
548 |
"""Encapsulates a single, runnable test. |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
549 |
|
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
550 |
Test instances can be run multiple times via run(). However, multiple |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
551 |
runs cannot be run concurrently. |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
552 |
""" |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
553 |
|
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
554 |
def __init__(self, path, options, count, refpath): |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
555 |
self._path = path |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
556 |
self._options = options |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
557 |
self._count = count |
21319
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
558 |
self._daemonpids = [] |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
559 |
|
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
560 |
# If we're not in --debug mode and reference output file exists, |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
561 |
# check test output against it. |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
562 |
if options.debug: |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
563 |
self._refout = None # to match "out is None" |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
564 |
elif os.path.exists(refpath): |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
565 |
f = open(refpath, 'r') |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
566 |
self._refout = f.read().splitlines(True) |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
567 |
f.close() |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
568 |
else: |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
569 |
self._refout = [] |
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
570 |
|
21310
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
571 |
self._threadtmp = os.path.join(HGTMP, 'child%d' % count) |
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
572 |
os.mkdir(self._threadtmp) |
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
573 |
|
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
574 |
def cleanup(self): |
21319
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
575 |
for entry in self._daemonpids: |
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
576 |
killdaemons(entry) |
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
577 |
|
21310
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
578 |
if self._threadtmp and not self._options.keep_tmpdir: |
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
579 |
shutil.rmtree(self._threadtmp, True) |
21304
e626a67da4ba
run-tests: clean up temp directory variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21303
diff
changeset
|
580 |
|
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
581 |
def run(self, result): |
21310
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
582 |
testtmp = os.path.join(self._threadtmp, os.path.basename(self._path)) |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
583 |
os.mkdir(testtmp) |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
584 |
replacements, port = self._getreplacements(testtmp) |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
585 |
env = self._getenv(testtmp, port) |
21319
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
586 |
self._daemonpids.append(env['DAEMON_PIDS']) |
21300
a2774731a51a
run-tests: move createhgrc() call into Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21299
diff
changeset
|
587 |
createhgrc(env['HGRCPATH'], self._options) |
a2774731a51a
run-tests: move createhgrc() call into Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21299
diff
changeset
|
588 |
|
21305
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
589 |
starttime = time.time() |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
590 |
|
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
591 |
def updateduration(): |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
592 |
result.duration = time.time() - starttime |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
593 |
|
21302
9e5d8eaa4a20
run-tests: move killdaemons into Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21301
diff
changeset
|
594 |
try: |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
595 |
ret, out = self._run(testtmp, replacements, env) |
21305
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
596 |
updateduration() |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
597 |
result.ret = ret |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
598 |
result.out = out |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
599 |
except KeyboardInterrupt: |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
600 |
updateduration() |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
601 |
result.interrupted = True |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
602 |
except Exception, e: |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
603 |
updateduration() |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
604 |
result.exception = e |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
605 |
|
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
606 |
killdaemons(env['DAEMON_PIDS']) |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
607 |
|
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
608 |
result.refout = self._refout |
21308
935ade207253
run-tests: capture reference output in TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21307
diff
changeset
|
609 |
|
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
610 |
if not self._options.keep_tmpdir: |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
611 |
shutil.rmtree(testtmp) |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
612 |
|
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
613 |
def _run(self, testtmp, replacements, env): |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
614 |
raise NotImplemented('Subclasses must implement Test.run()') |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
615 |
|
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
616 |
def _getreplacements(self, testtmp): |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
617 |
port = self._options.port + self._count * 3 |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
618 |
r = [ |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
619 |
(r':%s\b' % port, ':$HGPORT'), |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
620 |
(r':%s\b' % (port + 1), ':$HGPORT1'), |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
621 |
(r':%s\b' % (port + 2), ':$HGPORT2'), |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
622 |
] |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
623 |
|
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
624 |
if os.name == 'nt': |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
625 |
r.append( |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
626 |
(''.join(c.isalpha() and '[%s%s]' % (c.lower(), c.upper()) or |
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
627 |
c in '/\\' and r'[/\\]' or c.isdigit() and c or '\\' + c |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
628 |
for c in testtmp), '$TESTTMP')) |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
629 |
else: |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
630 |
r.append((re.escape(testtmp), '$TESTTMP')) |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
631 |
|
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
632 |
return r, port |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
633 |
|
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
634 |
def _getenv(self, testtmp, port): |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
635 |
env = os.environ.copy() |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
636 |
env['TESTTMP'] = testtmp |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
637 |
env['HOME'] = testtmp |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
638 |
env["HGPORT"] = str(port) |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
639 |
env["HGPORT1"] = str(port + 1) |
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
640 |
env["HGPORT2"] = str(port + 2) |
21310
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
641 |
env["HGRCPATH"] = os.path.join(self._threadtmp, '.hgrc') |
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
642 |
env["DAEMON_PIDS"] = os.path.join(self._threadtmp, 'daemon.pids') |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
643 |
env["HGEDITOR"] = sys.executable + ' -c "import sys; sys.exit(0)"' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
644 |
env["HGMERGE"] = "internal:merge" |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
645 |
env["HGUSER"] = "test" |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
646 |
env["HGENCODING"] = "ascii" |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
647 |
env["HGENCODINGMODE"] = "strict" |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
648 |
|
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
649 |
# Reset some environment variables to well-known values so that |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
650 |
# the tests produce repeatable output. |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
651 |
env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
652 |
env['TZ'] = 'GMT' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
653 |
env["EMAIL"] = "Foo Bar <foo.bar@example.com>" |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
654 |
env['COLUMNS'] = '80' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
655 |
env['TERM'] = 'xterm' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
656 |
|
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
657 |
for k in ('HG HGPROF CDPATH GREP_OPTIONS http_proxy no_proxy ' + |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
658 |
'NO_PROXY').split(): |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
659 |
if k in env: |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
660 |
del env[k] |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
661 |
|
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
662 |
# unset env related to hooks |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
663 |
for k in env.keys(): |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
664 |
if k.startswith('HG_'): |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
665 |
del env[k] |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
666 |
|
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
667 |
return env |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
668 |
|
21305
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
669 |
class TestResult(object): |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
670 |
"""Holds the result of a test execution.""" |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
671 |
|
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
672 |
def __init__(self): |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
673 |
self.ret = None |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
674 |
self.out = None |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
675 |
self.duration = None |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
676 |
self.interrupted = False |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
677 |
self.exception = None |
21308
935ade207253
run-tests: capture reference output in TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21307
diff
changeset
|
678 |
self.refout = None |
21305
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
679 |
|
21307
cd4fd7b3c3c4
run-tests: give TestResult a skipped attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21306
diff
changeset
|
680 |
@property |
cd4fd7b3c3c4
run-tests: give TestResult a skipped attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21306
diff
changeset
|
681 |
def skipped(self): |
cd4fd7b3c3c4
run-tests: give TestResult a skipped attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21306
diff
changeset
|
682 |
"""Whether the test was skipped.""" |
cd4fd7b3c3c4
run-tests: give TestResult a skipped attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21306
diff
changeset
|
683 |
return self.ret == SKIPPED_STATUS |
cd4fd7b3c3c4
run-tests: give TestResult a skipped attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21306
diff
changeset
|
684 |
|
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
685 |
class PythonTest(Test): |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
686 |
"""A Python-based test.""" |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
687 |
def _run(self, testtmp, replacements, env): |
21311
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
688 |
py3kswitch = self._options.py3k_warnings and ' -3' or '' |
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
689 |
cmd = '%s%s "%s"' % (PYTHON, py3kswitch, self._path) |
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
690 |
vlog("# Running", cmd) |
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
691 |
if os.name == 'nt': |
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
692 |
replacements.append((r'\r\n', '\n')) |
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
693 |
return run(cmd, testtmp, self._options, replacements, env) |
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
694 |
|
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
695 |
|
12941
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
696 |
needescape = re.compile(r'[\x00-\x08\x0b-\x1f\x7f-\xff]').search |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
697 |
escapesub = re.compile(r'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
698 |
escapemap = dict((chr(i), r'\x%02x' % i) for i in range(256)) |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
699 |
escapemap.update({'\\': '\\\\', '\r': r'\r'}) |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
700 |
def escapef(m): |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
701 |
return escapemap[m.group(0)] |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
702 |
def stringescape(s): |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
703 |
return escapesub(escapef, s) |
b911cb80c671
tests: use (esc) markup for string-escape
Mads Kiilerich <mads@kiilerich.com>
parents:
12940
diff
changeset
|
704 |
|
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
705 |
class TTest(Test): |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
706 |
"""A "t test" is a test backed by a .t file.""" |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
707 |
|
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
708 |
def _run(self, testtmp, replacements, env): |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
709 |
f = open(self._path) |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
710 |
lines = f.readlines() |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
711 |
f.close() |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
712 |
|
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
713 |
salt, script, after, expected = self._parsetest(lines, testtmp) |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
714 |
|
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
715 |
# Write out the generated script. |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
716 |
fname = '%s.sh' % testtmp |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
717 |
f = open(fname, 'w') |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
718 |
for l in script: |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
719 |
f.write(l) |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
720 |
f.close() |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
721 |
|
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
722 |
cmd = '%s "%s"' % (self._options.shell, fname) |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
723 |
vlog("# Running", cmd) |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
724 |
|
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
725 |
exitcode, output = run(cmd, testtmp, self._options, replacements, env) |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
726 |
# Do not merge output if skipped. Return hghave message instead. |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
727 |
# Similarly, with --debug, output is None. |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
728 |
if exitcode == SKIPPED_STATUS or output is None: |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
729 |
return exitcode, output |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
730 |
|
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
731 |
return self._processoutput(exitcode, output, salt, after, expected) |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
732 |
|
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
733 |
def _hghave(self, reqs, testtmp): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
734 |
# TODO do something smarter when all other uses of hghave are gone. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
735 |
tdir = TESTDIR.replace('\\', '/') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
736 |
proc = Popen4('%s -c "%s/hghave %s"' % |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
737 |
(self._options.shell, tdir, ' '.join(reqs)), |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
738 |
testtmp, 0) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
739 |
stdout, stderr = proc.communicate() |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
740 |
ret = proc.wait() |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
741 |
if wifexited(ret): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
742 |
ret = os.WEXITSTATUS(ret) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
743 |
if ret == 2: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
744 |
print stdout |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
745 |
sys.exit(1) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
746 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
747 |
return ret == 0 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
748 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
749 |
def _parsetest(self, lines, testtmp): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
750 |
# We generate a shell script which outputs unique markers to line |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
751 |
# up script results with our source. These markers include input |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
752 |
# line number and the last return code. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
753 |
salt = "SALT" + str(time.time()) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
754 |
def addsalt(line, inpython): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
755 |
if inpython: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
756 |
script.append('%s %d 0\n' % (salt, line)) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
757 |
else: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
758 |
script.append('echo %s %s $?\n' % (salt, line)) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
759 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
760 |
script = [] |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
761 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
762 |
# After we run the shell script, we re-unify the script output |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
763 |
# with non-active parts of the source, with synchronization by our |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
764 |
# SALT line number markers. The after table contains the non-active |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
765 |
# components, ordered by line number. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
766 |
after = {} |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
767 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
768 |
# Expected shell script output. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
769 |
expected = {} |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
770 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
771 |
pos = prepos = -1 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
772 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
773 |
# True or False when in a true or false conditional section |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
774 |
skipping = None |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
775 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
776 |
# We keep track of whether or not we're in a Python block so we |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
777 |
# can generate the surrounding doctest magic. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
778 |
inpython = False |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
779 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
780 |
if self._options.debug: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
781 |
script.append('set -x\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
782 |
if os.getenv('MSYSTEM'): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
783 |
script.append('alias pwd="pwd -W"\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
784 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
785 |
for n, l in enumerate(lines): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
786 |
if not l.endswith('\n'): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
787 |
l += '\n' |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
788 |
if l.startswith('#if'): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
789 |
lsplit = l.split() |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
790 |
if len(lsplit) < 2 or lsplit[0] != '#if': |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
791 |
after.setdefault(pos, []).append(' !!! invalid #if\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
792 |
if skipping is not None: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
793 |
after.setdefault(pos, []).append(' !!! nested #if\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
794 |
skipping = not self._hghave(lsplit[1:], testtmp) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
795 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
796 |
elif l.startswith('#else'): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
797 |
if skipping is None: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
798 |
after.setdefault(pos, []).append(' !!! missing #if\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
799 |
skipping = not skipping |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
800 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
801 |
elif l.startswith('#endif'): |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
802 |
if skipping is None: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
803 |
after.setdefault(pos, []).append(' !!! missing #if\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
804 |
skipping = None |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
805 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
806 |
elif skipping: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
807 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
808 |
elif l.startswith(' >>> '): # python inlines |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
809 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
810 |
prepos = pos |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
811 |
pos = n |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
812 |
if not inpython: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
813 |
# We've just entered a Python block. Add the header. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
814 |
inpython = True |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
815 |
addsalt(prepos, False) # Make sure we report the exit code. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
816 |
script.append('%s -m heredoctest <<EOF\n' % PYTHON) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
817 |
addsalt(n, True) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
818 |
script.append(l[2:]) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
819 |
elif l.startswith(' ... '): # python inlines |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
820 |
after.setdefault(prepos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
821 |
script.append(l[2:]) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
822 |
elif l.startswith(' $ '): # commands |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
823 |
if inpython: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
824 |
script.append('EOF\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
825 |
inpython = False |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
826 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
827 |
prepos = pos |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
828 |
pos = n |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
829 |
addsalt(n, False) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
830 |
cmd = l[4:].split() |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
831 |
if len(cmd) == 2 and cmd[0] == 'cd': |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
832 |
l = ' $ cd %s || exit 1\n' % cmd[1] |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
833 |
script.append(l[4:]) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
834 |
elif l.startswith(' > '): # continuations |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
835 |
after.setdefault(prepos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
836 |
script.append(l[4:]) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
837 |
elif l.startswith(' '): # results |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
838 |
# Queue up a list of expected results. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
839 |
expected.setdefault(pos, []).append(l[2:]) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
840 |
else: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
841 |
if inpython: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
842 |
script.append('EOF\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
843 |
inpython = False |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
844 |
# Non-command/result. Queue up for merged output. |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
845 |
after.setdefault(pos, []).append(l) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
846 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
847 |
if inpython: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
848 |
script.append('EOF\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
849 |
if skipping is not None: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
850 |
after.setdefault(pos, []).append(' !!! missing #endif\n') |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
851 |
addsalt(n + 1, False) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
852 |
|
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
853 |
return salt, script, after, expected |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
854 |
|
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
855 |
def _processoutput(self, exitcode, output, salt, after, expected): |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
856 |
# Merge the script output back into a unified test. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
857 |
warnonly = 1 # 1: not yet; 2: yes; 3: for sure not |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
858 |
if exitcode != 0: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
859 |
warnonly = 3 |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
860 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
861 |
pos = -1 |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
862 |
postout = [] |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
863 |
for l in output: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
864 |
lout, lcmd = l, None |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
865 |
if salt in l: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
866 |
lout, lcmd = l.split(salt, 1) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
867 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
868 |
if lout: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
869 |
if not lout.endswith('\n'): |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
870 |
lout += ' (no-eol)\n' |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
871 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
872 |
# Find the expected output at the current position. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
873 |
el = None |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
874 |
if expected.get(pos, None): |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
875 |
el = expected[pos].pop(0) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
876 |
|
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
877 |
r = TTest.linematch(el, lout) |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
878 |
if isinstance(r, str): |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
879 |
if r == '+glob': |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
880 |
lout = el[:-1] + ' (glob)\n' |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
881 |
r = '' # Warn only this line. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
882 |
elif r == '-glob': |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
883 |
lout = ''.join(el.rsplit(' (glob)', 1)) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
884 |
r = '' # Warn only this line. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
885 |
else: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
886 |
log('\ninfo, unknown linematch result: %r\n' % r) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
887 |
r = False |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
888 |
if r: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
889 |
postout.append(' ' + el) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
890 |
else: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
891 |
if needescape(lout): |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
892 |
lout = stringescape(lout.rstrip('\n')) + ' (esc)\n' |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
893 |
postout.append(' ' + lout) # Let diff deal with it. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
894 |
if r != '': # If line failed. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
895 |
warnonly = 3 # for sure not |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
896 |
elif warnonly == 1: # Is "not yet" and line is warn only. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
897 |
warnonly = 2 # Yes do warn. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
898 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
899 |
if lcmd: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
900 |
# Add on last return code. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
901 |
ret = int(lcmd.split()[1]) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
902 |
if ret != 0: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
903 |
postout.append(' [%s]\n' % ret) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
904 |
if pos in after: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
905 |
# Merge in non-active test bits. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
906 |
postout += after.pop(pos) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
907 |
pos = int(lcmd.split()[0]) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
908 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
909 |
if pos in after: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
910 |
postout += after.pop(pos) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
911 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
912 |
if warnonly == 2: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
913 |
exitcode = False # Set exitcode to warned. |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
914 |
|
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
915 |
return exitcode, postout |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
916 |
|
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
917 |
@staticmethod |
21316
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
918 |
def rematch(el, l): |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
919 |
try: |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
920 |
# use \Z to ensure that the regex matches to the end of the string |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
921 |
if os.name == 'nt': |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
922 |
return re.match(el + r'\r?\n\Z', l) |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
923 |
return re.match(el + r'\n\Z', l) |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
924 |
except re.error: |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
925 |
# el is an invalid regex |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
926 |
return False |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
927 |
|
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
928 |
@staticmethod |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
929 |
def globmatch(el, l): |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
930 |
# The only supported special characters are * and ? plus / which also |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
931 |
# matches \ on windows. Escaping of these characters is supported. |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
932 |
if el + '\n' == l: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
933 |
if os.altsep: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
934 |
# matching on "/" is not needed for this line |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
935 |
return '-glob' |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
936 |
return True |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
937 |
i, n = 0, len(el) |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
938 |
res = '' |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
939 |
while i < n: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
940 |
c = el[i] |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
941 |
i += 1 |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
942 |
if c == '\\' and el[i] in '*?\\/': |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
943 |
res += el[i - 1:i + 1] |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
944 |
i += 1 |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
945 |
elif c == '*': |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
946 |
res += '.*' |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
947 |
elif c == '?': |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
948 |
res += '.' |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
949 |
elif c == '/' and os.altsep: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
950 |
res += '[/\\\\]' |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
951 |
else: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
952 |
res += re.escape(c) |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
953 |
return TTest.rematch(res, l) |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
954 |
|
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
955 |
@staticmethod |
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
956 |
def linematch(el, l): |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
957 |
if el == l: # perfect match (fast) |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
958 |
return True |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
959 |
if el: |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
960 |
if el.endswith(" (esc)\n"): |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
961 |
el = el[:-7].decode('string-escape') + '\n' |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
962 |
if el == l or os.name == 'nt' and el[:-1] + '\r\n' == l: |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
963 |
return True |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
964 |
if el.endswith(" (re)\n"): |
21316
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
965 |
return TTest.rematch(el[:-6], l) |
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
966 |
if el.endswith(" (glob)\n"): |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
967 |
return TTest.globmatch(el[:-8], l) |
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
968 |
if os.altsep and l.replace('\\', '/') == el: |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
969 |
return '+glob' |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
970 |
return False |
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
971 |
|
13348
31fdb04cb5e8
run-tests: only call WIFEXITED on systems it exists
Simon Heimberg <simohe@besonet.ch>
parents:
13347
diff
changeset
|
972 |
wifexited = getattr(os, "WIFEXITED", lambda x: False) |
19262
7864e8f274fe
run-tests: add env dict to isolate test environment
Matt Mackall <mpm@selenic.com>
parents:
19252
diff
changeset
|
973 |
def run(cmd, wd, options, replacements, env): |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
974 |
"""Run command in a sub-process, capturing the output (stdout and stderr). |
9707
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
975 |
Return a tuple (exitcode, output). output is None in debug mode.""" |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
976 |
# TODO: Use subprocess.Popen if we're running on Python 2.4 |
9707
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
977 |
if options.debug: |
19262
7864e8f274fe
run-tests: add env dict to isolate test environment
Matt Mackall <mpm@selenic.com>
parents:
19252
diff
changeset
|
978 |
proc = subprocess.Popen(cmd, shell=True, cwd=wd, env=env) |
9707
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
979 |
ret = proc.wait() |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
980 |
return (ret, None) |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
981 |
|
19262
7864e8f274fe
run-tests: add env dict to isolate test environment
Matt Mackall <mpm@selenic.com>
parents:
19252
diff
changeset
|
982 |
proc = Popen4(cmd, wd, options.timeout, env) |
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
983 |
def cleanup(): |
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
984 |
terminate(proc) |
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
985 |
ret = proc.wait() |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
986 |
if ret == 0: |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
987 |
ret = signal.SIGTERM << 8 |
19263
062c0a0a5549
run-tests: use env dict to kill daemons
Matt Mackall <mpm@selenic.com>
parents:
19262
diff
changeset
|
988 |
killdaemons(env['DAEMON_PIDS']) |
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
989 |
return ret |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
990 |
|
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
991 |
output = '' |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
992 |
proc.tochild.close() |
10336
bc9a3bb267fa
run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents:
10300
diff
changeset
|
993 |
|
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
994 |
try: |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
995 |
output = proc.fromchild.read() |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
996 |
except KeyboardInterrupt: |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
997 |
vlog('# Handling keyboard interrupt') |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
998 |
cleanup() |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
999 |
raise |
10336
bc9a3bb267fa
run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents:
10300
diff
changeset
|
1000 |
|
19413
a4de0d3dc35a
run-tests: lock popen wait/poll
Brendan Cully <brendan@kublai.com>
parents:
19407
diff
changeset
|
1001 |
ret = proc.wait() |
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
1002 |
if wifexited(ret): |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
1003 |
ret = os.WEXITSTATUS(ret) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
1004 |
|
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
1005 |
if proc.timeout: |
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
1006 |
ret = 'timeout' |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
1007 |
|
14338
862f8cd87546
run-tests: use the common test path on Windows and Java
Patrick Mezard <pmezard@gmail.com>
parents:
14337
diff
changeset
|
1008 |
if ret: |
19263
062c0a0a5549
run-tests: use env dict to kill daemons
Matt Mackall <mpm@selenic.com>
parents:
19262
diff
changeset
|
1009 |
killdaemons(env['DAEMON_PIDS']) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
1010 |
|
19273 | 1011 |
if abort: |
1012 |
raise KeyboardInterrupt() |
|
1013 |
||
12639
236058a65cb4
tests: replace test tmp directory with $TESTTMP in test output
Mads Kiilerich <mads@kiilerich.com>
parents:
12621
diff
changeset
|
1014 |
for s, r in replacements: |
12895
53cfde2b3cf9
run-tests: use regex when searching for $HGPORT in test output
Martin Geisler <mg@aragost.com>
parents:
12721
diff
changeset
|
1015 |
output = re.sub(s, r, output) |
17742
405b6bd015df
run-tests: allow test output lines to be terminated with \r in addition to \n
Mads Kiilerich <mads@kiilerich.com>
parents:
17741
diff
changeset
|
1016 |
return ret, output.splitlines(True) |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1017 |
|
19274
6f666780f846
run-tests: introduce threadtmp directory
Matt Mackall <mpm@selenic.com>
parents:
19273
diff
changeset
|
1018 |
def runone(options, test, count): |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1019 |
'''returns a result element: (code, test, msg)''' |
2710
e475fe2a6029
run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2705
diff
changeset
|
1020 |
|
5470
8374f3f081f2
tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents:
5388
diff
changeset
|
1021 |
def skip(msg): |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1022 |
if options.verbose: |
19251
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
1023 |
log("\nSkipping %s: %s" % (testpath, msg)) |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1024 |
return 's', test, msg |
5470
8374f3f081f2
tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents:
5388
diff
changeset
|
1025 |
|
13988
994ad067ac6e
run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents:
13918
diff
changeset
|
1026 |
def fail(msg, ret): |
20508
91d4f82c2d3b
run-tests: add possibility for test-runners to report a "warned" test result
Simon Heimberg <simohe@besonet.ch>
parents:
20507
diff
changeset
|
1027 |
warned = ret is False |
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
1028 |
if not options.nodiff: |
20508
91d4f82c2d3b
run-tests: add possibility for test-runners to report a "warned" test result
Simon Heimberg <simohe@besonet.ch>
parents:
20507
diff
changeset
|
1029 |
log("\n%s: %s %s" % (warned and 'Warning' or 'ERROR', test, msg)) |
13999
8f9478be9a94
run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents:
13995
diff
changeset
|
1030 |
if (not ret and options.interactive |
8f9478be9a94
run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents:
13995
diff
changeset
|
1031 |
and os.path.exists(testpath + ".err")): |
14003
ba734ff5cadd
run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents:
14002
diff
changeset
|
1032 |
iolock.acquire() |
13988
994ad067ac6e
run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents:
13918
diff
changeset
|
1033 |
print "Accept this change? [n] ", |
994ad067ac6e
run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents:
13918
diff
changeset
|
1034 |
answer = sys.stdin.readline().strip() |
14003
ba734ff5cadd
run-tests: fix some missing i/o locks
Matt Mackall <mpm@selenic.com>
parents:
14002
diff
changeset
|
1035 |
iolock.release() |
13988
994ad067ac6e
run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents:
13918
diff
changeset
|
1036 |
if answer.lower() in "y yes".split(): |
994ad067ac6e
run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents:
13918
diff
changeset
|
1037 |
if test.endswith(".t"): |
13999
8f9478be9a94
run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents:
13995
diff
changeset
|
1038 |
rename(testpath + ".err", testpath) |
13988
994ad067ac6e
run-tests: move interactive handling into runone
Matt Mackall <mpm@selenic.com>
parents:
13918
diff
changeset
|
1039 |
else: |
13999
8f9478be9a94
run-tests: fix --interactive (after 994ad067ac6e)
Patrick Mezard <pmezard@gmail.com>
parents:
13995
diff
changeset
|
1040 |
rename(testpath + ".err", testpath + ".out") |
19249
de45df2688a9
run-tests: unify marks and result codes
Matt Mackall <mpm@selenic.com>
parents:
19248
diff
changeset
|
1041 |
return '.', test, '' |
20508
91d4f82c2d3b
run-tests: add possibility for test-runners to report a "warned" test result
Simon Heimberg <simohe@besonet.ch>
parents:
20507
diff
changeset
|
1042 |
return warned and '~' or '!', test, msg |
13994
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1043 |
|
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1044 |
def success(): |
19249
de45df2688a9
run-tests: unify marks and result codes
Matt Mackall <mpm@selenic.com>
parents:
19248
diff
changeset
|
1045 |
return '.', test, '' |
13994
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1046 |
|
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1047 |
def ignore(msg): |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1048 |
return 'i', test, msg |
6244
b36774d0fce1
run-tests.py: add a summary of failed tests at the end
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
6212
diff
changeset
|
1049 |
|
19244
eee43d763f9f
run-tests: regroup nested functions
Matt Mackall <mpm@selenic.com>
parents:
19243
diff
changeset
|
1050 |
def describe(ret): |
eee43d763f9f
run-tests: regroup nested functions
Matt Mackall <mpm@selenic.com>
parents:
19243
diff
changeset
|
1051 |
if ret < 0: |
eee43d763f9f
run-tests: regroup nested functions
Matt Mackall <mpm@selenic.com>
parents:
19243
diff
changeset
|
1052 |
return 'killed by signal %d' % -ret |
eee43d763f9f
run-tests: regroup nested functions
Matt Mackall <mpm@selenic.com>
parents:
19243
diff
changeset
|
1053 |
return 'returned error code %d' % ret |
eee43d763f9f
run-tests: regroup nested functions
Matt Mackall <mpm@selenic.com>
parents:
19243
diff
changeset
|
1054 |
|
19245
dcb05a1470bd
run-tests: regroup some variable initialization
Matt Mackall <mpm@selenic.com>
parents:
19244
diff
changeset
|
1055 |
testpath = os.path.join(TESTDIR, test) |
dcb05a1470bd
run-tests: regroup some variable initialization
Matt Mackall <mpm@selenic.com>
parents:
19244
diff
changeset
|
1056 |
err = os.path.join(TESTDIR, test + ".err") |
dcb05a1470bd
run-tests: regroup some variable initialization
Matt Mackall <mpm@selenic.com>
parents:
19244
diff
changeset
|
1057 |
lctest = test.lower() |
dcb05a1470bd
run-tests: regroup some variable initialization
Matt Mackall <mpm@selenic.com>
parents:
19244
diff
changeset
|
1058 |
|
19246
29ddf9d93e35
run-tests: fix a path existence check
Matt Mackall <mpm@selenic.com>
parents:
19245
diff
changeset
|
1059 |
if not os.path.exists(testpath): |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1060 |
return skip("doesn't exist") |
13989
55ba68a4dd28
run-tests: move existence/name format check into runone
Matt Mackall <mpm@selenic.com>
parents:
13988
diff
changeset
|
1061 |
|
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1062 |
if not (options.whitelisted and test in options.whitelisted): |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1063 |
if options.blacklist and test in options.blacklist: |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1064 |
return skip("blacklisted") |
13993
174d0a113757
run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents:
13992
diff
changeset
|
1065 |
|
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1066 |
if options.retest and not os.path.exists(test + ".err"): |
19311 | 1067 |
return ignore("not retesting") |
13993
174d0a113757
run-tests: move blacklist and retest filtering to runone
Matt Mackall <mpm@selenic.com>
parents:
13992
diff
changeset
|
1068 |
|
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1069 |
if options.keywords: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1070 |
fp = open(test) |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1071 |
t = fp.read().lower() + test.lower() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1072 |
fp.close() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1073 |
for k in options.keywords.lower().split(): |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1074 |
if k in t: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1075 |
break |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
1076 |
else: |
19311 | 1077 |
return ignore("doesn't match keyword") |
13991
8cfe191e2ce4
run-tests: move keyword checking into runone
Matt Mackall <mpm@selenic.com>
parents:
13990
diff
changeset
|
1078 |
|
21009
990f5392c018
run-tests: allow test paths in other directories
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21008
diff
changeset
|
1079 |
if not os.path.basename(lctest).startswith("test-"): |
19527
534cdbe87cad
run-tests: only check the common criteria once per test
Simon Heimberg <simohe@besonet.ch>
parents:
19460
diff
changeset
|
1080 |
return skip("not a test file") |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1081 |
for ext, cls, out in testtypes: |
19527
534cdbe87cad
run-tests: only check the common criteria once per test
Simon Heimberg <simohe@besonet.ch>
parents:
19460
diff
changeset
|
1082 |
if lctest.endswith(ext): |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1083 |
runner = cls |
19239
db978c792b02
run-tests: make a table of test types
Matt Mackall <mpm@selenic.com>
parents:
19238
diff
changeset
|
1084 |
ref = os.path.join(TESTDIR, test + out) |
db978c792b02
run-tests: make a table of test types
Matt Mackall <mpm@selenic.com>
parents:
19238
diff
changeset
|
1085 |
break |
2710
e475fe2a6029
run-tests.py: skip tests that should not run.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2705
diff
changeset
|
1086 |
else: |
17801
03554dfc7ced
run-tests: remove dead code for supporting old test scripts
Mads Kiilerich <mads@kiilerich.com>
parents:
17800
diff
changeset
|
1087 |
return skip("unknown test type") |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1088 |
|
19247
b43ed416bc2d
run-tests: regroup some initialization checks
Matt Mackall <mpm@selenic.com>
parents:
19246
diff
changeset
|
1089 |
vlog("# Test", test) |
b43ed416bc2d
run-tests: regroup some initialization checks
Matt Mackall <mpm@selenic.com>
parents:
19246
diff
changeset
|
1090 |
|
b43ed416bc2d
run-tests: regroup some initialization checks
Matt Mackall <mpm@selenic.com>
parents:
19246
diff
changeset
|
1091 |
if os.path.exists(err): |
b43ed416bc2d
run-tests: regroup some initialization checks
Matt Mackall <mpm@selenic.com>
parents:
19246
diff
changeset
|
1092 |
os.remove(err) # Remove any previous output files |
b43ed416bc2d
run-tests: regroup some initialization checks
Matt Mackall <mpm@selenic.com>
parents:
19246
diff
changeset
|
1093 |
|
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
1094 |
t = runner(testpath, options, count, ref) |
21306
cbf5475827da
run-tests: pass TestResult into run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21305
diff
changeset
|
1095 |
res = TestResult() |
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
1096 |
t.run(res) |
21310
af9a04951c69
run-tests: remove threadtmp in Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21309
diff
changeset
|
1097 |
t.cleanup() |
19268
36dc45b1f427
run-tests: move HGRCPATH to env
Matt Mackall <mpm@selenic.com>
parents:
19267
diff
changeset
|
1098 |
|
21305
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1099 |
if res.interrupted: |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1100 |
log('INTERRUPTED: %s (after %d seconds)' % (test, res.duration)) |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1101 |
raise KeyboardInterrupt() |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1102 |
|
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1103 |
if res.exception: |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1104 |
return fail('Exception during execution: %s' % res.exception, 255) |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1105 |
|
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1106 |
ret = res.ret |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1107 |
out = res.out |
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1108 |
|
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1109 |
times.append((test, res.duration)) |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1110 |
vlog("# Ret was:", ret) |
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1111 |
|
21307
cd4fd7b3c3c4
run-tests: give TestResult a skipped attribute
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21306
diff
changeset
|
1112 |
skipped = res.skipped |
21308
935ade207253
run-tests: capture reference output in TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21307
diff
changeset
|
1113 |
refout = res.refout |
9707
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
1114 |
|
11040
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1115 |
if (ret != 0 or out != refout) and not skipped and not options.debug: |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1116 |
# Save errors to a file for diagnosis |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1117 |
f = open(err, "wb") |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1118 |
for line in out: |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1119 |
f.write(line) |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1120 |
f.close() |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1121 |
|
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
1122 |
if skipped: |
9707
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
1123 |
if out is None: # debug mode: nothing to parse |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
1124 |
missing = ['unknown'] |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
1125 |
failed = None |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
1126 |
else: |
38deec407f8d
run-tests: add "debug" mode: don't capture child output, just show it.
Greg Ward <greg-hg@gerg.ca>
parents:
9706
diff
changeset
|
1127 |
missing, failed = parsehghaveoutput(out) |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
1128 |
if not missing: |
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
1129 |
missing = ['irrelevant'] |
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
1130 |
if failed: |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1131 |
result = fail("hghave failed checking for %s" % failed[-1], ret) |
8060
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
1132 |
skipped = False |
84d0fe34427b
run-tests: detect when hghave fails to check for a feature and fail test
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
7813
diff
changeset
|
1133 |
else: |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1134 |
result = skip(missing[-1]) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
1135 |
elif ret == 'timeout': |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1136 |
result = fail("timed out", ret) |
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
1137 |
elif out != refout: |
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1138 |
info = {} |
14006
a395575691a6
run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents:
14003
diff
changeset
|
1139 |
if not options.nodiff: |
14002
a738c30d4b18
run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents:
14001
diff
changeset
|
1140 |
iolock.acquire() |
11040
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1141 |
if options.view: |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1142 |
os.system("%s %s %s" % (options.view, ref, err)) |
8f951ed6c63c
run-tests: add --view switch to use external diff viewer
Matt Mackall <mpm@selenic.com>
parents:
11039
diff
changeset
|
1143 |
else: |
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1144 |
info = showdiff(refout, out, ref, err) |
14002
a738c30d4b18
run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents:
14001
diff
changeset
|
1145 |
iolock.release() |
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1146 |
msg = "" |
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1147 |
if info.get('servefail'): msg += "serve failed and " |
14006
a395575691a6
run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents:
14003
diff
changeset
|
1148 |
if ret: |
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1149 |
msg += "output changed and " + describe(ret) |
14006
a395575691a6
run-tests: display diff before prompting with --interactive
Patrick Mezard <pmezard@gmail.com>
parents:
14003
diff
changeset
|
1150 |
else: |
21022
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1151 |
msg += "output changed" |
52e9e63f1495
run-tests: test result shows when a failed test could not start a server
Simon Heimberg <simohe@besonet.ch>
parents:
21009
diff
changeset
|
1152 |
result = fail(msg, ret) |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
1153 |
elif ret: |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1154 |
result = fail(describe(ret), ret) |
14037
4ab1e987941b
run-tests: don't count test as succeeded if it failed
Idan Kamara <idankk86@gmail.com>
parents:
14019
diff
changeset
|
1155 |
else: |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1156 |
result = success() |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1157 |
|
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
1158 |
if not options.verbose: |
14002
a738c30d4b18
run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents:
14001
diff
changeset
|
1159 |
iolock.acquire() |
19249
de45df2688a9
run-tests: unify marks and result codes
Matt Mackall <mpm@selenic.com>
parents:
19248
diff
changeset
|
1160 |
sys.stdout.write(result[0]) |
5470
8374f3f081f2
tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents:
5388
diff
changeset
|
1161 |
sys.stdout.flush() |
14002
a738c30d4b18
run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents:
14001
diff
changeset
|
1162 |
iolock.release() |
5470
8374f3f081f2
tests: tidy up reporting of skipped tests
Matt Mackall <mpm@selenic.com>
parents:
5388
diff
changeset
|
1163 |
|
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1164 |
return result |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
1165 |
|
8672
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1166 |
_hgpath = None |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1167 |
|
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1168 |
def _gethgpath(): |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1169 |
"""Return the path to the mercurial package that is actually found by |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1170 |
the current Python interpreter.""" |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1171 |
global _hgpath |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1172 |
if _hgpath is not None: |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1173 |
return _hgpath |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1174 |
|
19759
1b8054b98d68
run-tests: find mercurial path with syntax valid on both py2 and py3
Augie Fackler <raf@durin42.com>
parents:
19758
diff
changeset
|
1175 |
cmd = '%s -c "import mercurial; print (mercurial.__path__[0])"' |
8672
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1176 |
pipe = os.popen(cmd % PYTHON) |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1177 |
try: |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1178 |
_hgpath = pipe.read().strip() |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1179 |
finally: |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1180 |
pipe.close() |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1181 |
return _hgpath |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1182 |
|
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1183 |
def _checkhglib(verb): |
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1184 |
"""Ensure that the 'mercurial' package imported by python is |
8673
a8066f2fd1aa
run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents:
8672
diff
changeset
|
1185 |
the one we expect it to be. If not, print a warning to stderr.""" |
a8066f2fd1aa
run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents:
8672
diff
changeset
|
1186 |
expecthg = os.path.join(PYTHONDIR, 'mercurial') |
8672
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1187 |
actualhg = _gethgpath() |
14263
7352ff757a48
run-tests: compare absolute paths in _checkhglib
Idan Kamara <idankk86@gmail.com>
parents:
14202
diff
changeset
|
1188 |
if os.path.abspath(actualhg) != os.path.abspath(expecthg): |
8673
a8066f2fd1aa
run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents:
8672
diff
changeset
|
1189 |
sys.stderr.write('warning: %s with unexpected mercurial lib: %s\n' |
a8066f2fd1aa
run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents:
8672
diff
changeset
|
1190 |
' (expected %s)\n' |
a8066f2fd1aa
run-tests: fix _checkhglib() so it's correct when using --with-hg.
Greg Ward <greg-hg@gerg.ca>
parents:
8672
diff
changeset
|
1191 |
% (verb, actualhg, expecthg)) |
8672
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1192 |
|
20506
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1193 |
results = {'.':[], '!':[], '~': [], 's':[], 'i':[]} |
17921
4ac9cf3d810c
run-tests: add --time option to log times for each test
Siddharth Agarwal <sid0@fb.com>
parents:
17920
diff
changeset
|
1194 |
times = [] |
14002
a738c30d4b18
run-tests: add a lock for console I/O
Matt Mackall <mpm@selenic.com>
parents:
14001
diff
changeset
|
1195 |
iolock = threading.Lock() |
19273 | 1196 |
abort = False |
14000
636a6f5aa2cd
run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents:
13999
diff
changeset
|
1197 |
|
19276
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1198 |
def scheduletests(options, tests): |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1199 |
jobs = options.jobs |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1200 |
done = queue.Queue() |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1201 |
running = 0 |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1202 |
count = 0 |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1203 |
global abort |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1204 |
|
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1205 |
def job(test, count): |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1206 |
try: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1207 |
done.put(runone(options, test, count)) |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1208 |
except KeyboardInterrupt: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1209 |
pass |
20258
3cd441353d6b
run-tests: report tests as failed when run-test raises an error
Simon Heimberg <simohe@besonet.ch>
parents:
20219
diff
changeset
|
1210 |
except: # re-raises |
3cd441353d6b
run-tests: report tests as failed when run-test raises an error
Simon Heimberg <simohe@besonet.ch>
parents:
20219
diff
changeset
|
1211 |
done.put(('!', test, 'run-test raised an error, see traceback')) |
3cd441353d6b
run-tests: report tests as failed when run-test raises an error
Simon Heimberg <simohe@besonet.ch>
parents:
20219
diff
changeset
|
1212 |
raise |
19248
6a127fa5de23
run-tests: change return code of runone
Matt Mackall <mpm@selenic.com>
parents:
19247
diff
changeset
|
1213 |
|
19276
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1214 |
try: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1215 |
while tests or running: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1216 |
if not done.empty() or running == jobs or not tests: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1217 |
try: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1218 |
code, test, msg = done.get(True, 1) |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1219 |
results[code].append((test, msg)) |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1220 |
if options.first and code not in '.si': |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1221 |
break |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1222 |
except queue.Empty: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1223 |
continue |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1224 |
running -= 1 |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1225 |
if tests and not running == jobs: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1226 |
test = tests.pop(0) |
19283
8300adf9ca33
run-tests: add --loop support
Matt Mackall <mpm@selenic.com>
parents:
19282
diff
changeset
|
1227 |
if options.loop: |
8300adf9ca33
run-tests: add --loop support
Matt Mackall <mpm@selenic.com>
parents:
19282
diff
changeset
|
1228 |
tests.append(test) |
20259
bb4aac9b048c
run-tests: set the thread name to the test name for info on error
Simon Heimberg <simohe@besonet.ch>
parents:
20258
diff
changeset
|
1229 |
t = threading.Thread(target=job, name=test, args=(test, count)) |
19276
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1230 |
t.start() |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1231 |
running += 1 |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1232 |
count += 1 |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1233 |
except KeyboardInterrupt: |
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1234 |
abort = True |
13995
b29b7cbc252f
run-tests: move test loop into a helper function
Matt Mackall <mpm@selenic.com>
parents:
13994
diff
changeset
|
1235 |
|
8672
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1236 |
def runtests(options, tests): |
2258
7e43d68f3900
catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2247
diff
changeset
|
1237 |
try: |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1238 |
if INST: |
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
1239 |
installhg(options) |
8672
d6b243731763
run-tests: factor out _checkhglib() to check import path of 'mercurial'.
Greg Ward <greg-hg@gerg.ca>
parents:
8671
diff
changeset
|
1240 |
_checkhglib("Testing") |
18048
9b7288fc7bf2
run-tests: use correct python when run with --local
Bryan O'Sullivan <bryano@fb.com>
parents:
17967
diff
changeset
|
1241 |
else: |
9b7288fc7bf2
run-tests: use correct python when run with --local
Bryan O'Sullivan <bryano@fb.com>
parents:
17967
diff
changeset
|
1242 |
usecorrectpython() |
6982
9fc5bf4adbcf
imported patch test-check
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
6681
diff
changeset
|
1243 |
|
3625 | 1244 |
if options.restart: |
1245 |
orig = list(tests) |
|
1246 |
while tests: |
|
1247 |
if os.path.exists(tests[0] + ".err"): |
|
1248 |
break |
|
1249 |
tests.pop(0) |
|
1250 |
if not tests: |
|
1251 |
print "running all tests" |
|
1252 |
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
|
1253 |
|
19276
e55751963889
run-tests: introduce thread scheduler
Matt Mackall <mpm@selenic.com>
parents:
19275
diff
changeset
|
1254 |
scheduletests(options, tests) |
3625 | 1255 |
|
19249
de45df2688a9
run-tests: unify marks and result codes
Matt Mackall <mpm@selenic.com>
parents:
19248
diff
changeset
|
1256 |
failed = len(results['!']) |
20506
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1257 |
warned = len(results['~']) |
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1258 |
tested = len(results['.']) + failed + warned |
13994
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1259 |
skipped = len(results['s']) |
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1260 |
ignored = len(results['i']) |
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1261 |
|
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1262 |
|
19294
3c3f6b83f8cb
run-tests: make --noskips work
Matt Mackall <mpm@selenic.com>
parents:
19283
diff
changeset
|
1263 |
if not options.noskips: |
3c3f6b83f8cb
run-tests: make --noskips work
Matt Mackall <mpm@selenic.com>
parents:
19283
diff
changeset
|
1264 |
for s in results['s']: |
3c3f6b83f8cb
run-tests: make --noskips work
Matt Mackall <mpm@selenic.com>
parents:
19283
diff
changeset
|
1265 |
print "Skipped %s: %s" % s |
20506
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1266 |
for s in results['~']: |
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1267 |
print "Warned %s: %s" % s |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1268 |
for s in results['!']: |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1269 |
print "Failed %s: %s" % s |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1270 |
_checkhglib("Tested") |
20506
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1271 |
print "# Ran %d tests, %d skipped, %d warned, %d failed." % ( |
a46c9fea6c73
run-tests: introduce 'warned' as test result
Simon Heimberg <simohe@besonet.ch>
parents:
20505
diff
changeset
|
1272 |
tested, skipped + ignored, warned, failed) |
20046
6a03695fa72a
tests: python hash seed is only relevant after failures - otherwise keep quiet
Mads Kiilerich <madski@unity3d.com>
parents:
20019
diff
changeset
|
1273 |
if results['!']: |
6a03695fa72a
tests: python hash seed is only relevant after failures - otherwise keep quiet
Mads Kiilerich <madski@unity3d.com>
parents:
20019
diff
changeset
|
1274 |
print 'python hash seed:', os.environ['PYTHONHASHSEED'] |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1275 |
if options.time: |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1276 |
outputtimes(options) |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
1277 |
|
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
1278 |
if options.anycoverage: |
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
1279 |
outputcoverage(options) |
2258
7e43d68f3900
catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2247
diff
changeset
|
1280 |
except KeyboardInterrupt: |
7e43d68f3900
catch KeyboardInterrupt in run-tests
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2247
diff
changeset
|
1281 |
failed = True |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1282 |
print "\ninterrupted!" |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
1283 |
|
13994
f31a5b7f5c07
run-tests: use a results dict
Matt Mackall <mpm@selenic.com>
parents:
13993
diff
changeset
|
1284 |
if failed: |
20505
eca34583cd87
run-tests: handle sys.exit in main function
Simon Heimberg <simohe@besonet.ch>
parents:
20504
diff
changeset
|
1285 |
return 1 |
20507
38444739a69f
run-tests: separate exit code when no failed tests but warned ones
Simon Heimberg <simohe@besonet.ch>
parents:
20506
diff
changeset
|
1286 |
if warned: |
38444739a69f
run-tests: separate exit code when no failed tests but warned ones
Simon Heimberg <simohe@besonet.ch>
parents:
20506
diff
changeset
|
1287 |
return 80 |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
1288 |
|
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1289 |
testtypes = [('.py', PythonTest, '.out'), |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1290 |
('.t', TTest, '')] |
19239
db978c792b02
run-tests: make a table of test types
Matt Mackall <mpm@selenic.com>
parents:
19238
diff
changeset
|
1291 |
|
21008
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
1292 |
def main(args, parser=None): |
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
1293 |
parser = parser or getparser() |
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
1294 |
(options, args) = parseargs(args, parser) |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1295 |
os.umask(022) |
8093
70d8f70264c4
run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents:
8092
diff
changeset
|
1296 |
|
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1297 |
checktools() |
8093
70d8f70264c4
run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents:
8092
diff
changeset
|
1298 |
|
20793
60c175c1e708
tests: small refactoring of run-tests' handling of tests list
Mads Kiilerich <madski@unity3d.com>
parents:
20680
diff
changeset
|
1299 |
if not args: |
20821
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1300 |
if options.changed: |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1301 |
proc = Popen4('hg st --rev "%s" -man0 .' % options.changed, |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1302 |
None, 0) |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1303 |
stdout, stderr = proc.communicate() |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1304 |
args = stdout.strip('\0').split('\0') |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1305 |
else: |
3d1d16b19e7d
tests: add run-tests --changed option for running tests changed in revisions
Mads Kiilerich <madski@unity3d.com>
parents:
20793
diff
changeset
|
1306 |
args = os.listdir(".") |
12677
9848a94e2ad6
run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12643
diff
changeset
|
1307 |
|
20793
60c175c1e708
tests: small refactoring of run-tests' handling of tests list
Mads Kiilerich <madski@unity3d.com>
parents:
20680
diff
changeset
|
1308 |
tests = [t for t in args |
21009
990f5392c018
run-tests: allow test paths in other directories
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21008
diff
changeset
|
1309 |
if os.path.basename(t).startswith("test-") |
990f5392c018
run-tests: allow test paths in other directories
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21008
diff
changeset
|
1310 |
and (t.endswith(".py") or t.endswith(".t"))] |
12677
9848a94e2ad6
run-tests.py: do not install hg when the tests do no exist
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
12643
diff
changeset
|
1311 |
|
19057
3d265e0822d3
run-tests: introduce --random for running tests in random error
Mads Kiilerich <madski@unity3d.com>
parents:
18788
diff
changeset
|
1312 |
if options.random: |
3d265e0822d3
run-tests: introduce --random for running tests in random error
Mads Kiilerich <madski@unity3d.com>
parents:
18788
diff
changeset
|
1313 |
random.shuffle(tests) |
19277
09e1c148e847
run-tests: schedule largest tests first
Matt Mackall <mpm@selenic.com>
parents:
19276
diff
changeset
|
1314 |
else: |
19281
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1315 |
# keywords for slow tests |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1316 |
slow = 'svn gendoc check-code-hg'.split() |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1317 |
def sortkey(f): |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1318 |
# run largest tests first, as they tend to take the longest |
19315
401b3ad26e66
run-tests: sort missing files first instead of raising an error
simon@laptop-tosh
parents:
19312
diff
changeset
|
1319 |
try: |
401b3ad26e66
run-tests: sort missing files first instead of raising an error
simon@laptop-tosh
parents:
19312
diff
changeset
|
1320 |
val = -os.stat(f).st_size |
401b3ad26e66
run-tests: sort missing files first instead of raising an error
simon@laptop-tosh
parents:
19312
diff
changeset
|
1321 |
except OSError, e: |
401b3ad26e66
run-tests: sort missing files first instead of raising an error
simon@laptop-tosh
parents:
19312
diff
changeset
|
1322 |
if e.errno != errno.ENOENT: |
401b3ad26e66
run-tests: sort missing files first instead of raising an error
simon@laptop-tosh
parents:
19312
diff
changeset
|
1323 |
raise |
401b3ad26e66
run-tests: sort missing files first instead of raising an error
simon@laptop-tosh
parents:
19312
diff
changeset
|
1324 |
return -1e9 # file does not exist, tell early |
19281
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1325 |
for kw in slow: |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1326 |
if kw in f: |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1327 |
val *= 10 |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1328 |
return val |
0a5e19007cd1
run-tests: sort certain slow tests earlier by keyword
Matt Mackall <mpm@selenic.com>
parents:
19280
diff
changeset
|
1329 |
tests.sort(key=sortkey) |
19057
3d265e0822d3
run-tests: introduce --random for running tests in random error
Mads Kiilerich <madski@unity3d.com>
parents:
18788
diff
changeset
|
1330 |
|
18616
35b4affe6fdd
test: display used python hash seed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18565
diff
changeset
|
1331 |
if 'PYTHONHASHSEED' not in os.environ: |
35b4affe6fdd
test: display used python hash seed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18565
diff
changeset
|
1332 |
# use a random python hash seed all the time |
35b4affe6fdd
test: display used python hash seed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18565
diff
changeset
|
1333 |
# we do the randomness ourself to know what seed is used |
35b4affe6fdd
test: display used python hash seed
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
18565
diff
changeset
|
1334 |
os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32)) |
8093
70d8f70264c4
run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents:
8092
diff
changeset
|
1335 |
|
20541
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
1336 |
global TESTDIR, HGTMP, INST, BINDIR, TMPBINDIR, PYTHONDIR, COVERAGE_FILE |
16897
2774576dee4d
tests/run-tests: avoid C:/ in arguments
Adrian Buehlmann <adrian@cadifra.com>
parents:
16890
diff
changeset
|
1337 |
TESTDIR = os.environ["TESTDIR"] = os.getcwd() |
9706
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1338 |
if options.tmpdir: |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1339 |
options.keep_tmpdir = True |
9706
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1340 |
tmpdir = options.tmpdir |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1341 |
if os.path.exists(tmpdir): |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1342 |
# Meaning of tmpdir has changed since 1.3: we used to create |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1343 |
# HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1344 |
# tmpdir already exists. |
21007
57179a4bf77a
run-tests: use return values instead of sys.exit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21006
diff
changeset
|
1345 |
print "error: temp dir %r already exists" % tmpdir |
57179a4bf77a
run-tests: use return values instead of sys.exit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21006
diff
changeset
|
1346 |
return 1 |
9706
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1347 |
|
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1348 |
# Automatically removing tmpdir sounds convenient, but could |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1349 |
# really annoy anyone in the habit of using "--tmpdir=/tmp" |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1350 |
# or "--tmpdir=$HOME". |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1351 |
#vlog("# Removing temp dir", tmpdir) |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1352 |
#shutil.rmtree(tmpdir) |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1353 |
os.makedirs(tmpdir) |
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1354 |
else: |
16890
4d95878712ad
tests/run-tests: use $TMP on Windows (issue3490)
Adrian Buehlmann <adrian@cadifra.com>
parents:
16842
diff
changeset
|
1355 |
d = None |
4d95878712ad
tests/run-tests: use $TMP on Windows (issue3490)
Adrian Buehlmann <adrian@cadifra.com>
parents:
16842
diff
changeset
|
1356 |
if os.name == 'nt': |
4d95878712ad
tests/run-tests: use $TMP on Windows (issue3490)
Adrian Buehlmann <adrian@cadifra.com>
parents:
16842
diff
changeset
|
1357 |
# without this, we get the default temp dir location, but |
4d95878712ad
tests/run-tests: use $TMP on Windows (issue3490)
Adrian Buehlmann <adrian@cadifra.com>
parents:
16842
diff
changeset
|
1358 |
# in all lowercase, which causes troubles with paths (issue3490) |
4d95878712ad
tests/run-tests: use $TMP on Windows (issue3490)
Adrian Buehlmann <adrian@cadifra.com>
parents:
16842
diff
changeset
|
1359 |
d = os.getenv('TMP') |
4d95878712ad
tests/run-tests: use $TMP on Windows (issue3490)
Adrian Buehlmann <adrian@cadifra.com>
parents:
16842
diff
changeset
|
1360 |
tmpdir = tempfile.mkdtemp('', 'hgtests.', d) |
9706
f8b4df4b033d
run-tests: make --tmpdir option more useful.
Greg Ward <greg-hg@gerg.ca>
parents:
9582
diff
changeset
|
1361 |
HGTMP = os.environ['HGTMP'] = os.path.realpath(tmpdir) |
8093
70d8f70264c4
run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents:
8092
diff
changeset
|
1362 |
|
8094
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1363 |
if options.with_hg: |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1364 |
INST = None |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1365 |
BINDIR = os.path.dirname(os.path.realpath(options.with_hg)) |
20541
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
1366 |
TMPBINDIR = os.path.join(HGTMP, 'install', 'bin') |
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
1367 |
os.makedirs(TMPBINDIR) |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1368 |
|
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1369 |
# This looks redundant with how Python initializes sys.path from |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1370 |
# the location of the script being executed. Needed because the |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1371 |
# "hg" specified by --with-hg is not the only Python script |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1372 |
# executed in the test suite that needs to import 'mercurial' |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1373 |
# ... which means it's not really redundant at all. |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1374 |
PYTHONDIR = BINDIR |
8094
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1375 |
else: |
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1376 |
INST = os.path.join(HGTMP, "install") |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1377 |
BINDIR = os.environ["BINDIR"] = os.path.join(INST, "bin") |
20541
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
1378 |
TMPBINDIR = BINDIR |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1379 |
PYTHONDIR = os.path.join(INST, "lib", "python") |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1380 |
|
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1381 |
os.environ["BINDIR"] = BINDIR |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1382 |
os.environ["PYTHON"] = PYTHON |
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1383 |
|
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1384 |
path = [BINDIR] + os.environ["PATH"].split(os.pathsep) |
20541
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
1385 |
if TMPBINDIR != BINDIR: |
44dcca9be1d5
run-tests.py: work when --with-hg is set to system hg
Siddharth Agarwal <sid0@fb.com>
parents:
20513
diff
changeset
|
1386 |
path = [TMPBINDIR] + path |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1387 |
os.environ["PATH"] = os.pathsep.join(path) |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1388 |
|
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1389 |
# Include TESTDIR in PYTHONPATH so that out-of-tree extensions |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1390 |
# can run .../tests/run-tests.py test-foo where test-foo |
20513
dcd3bebf4786
run-tests: fix heredoctest for out-of-tree extensions
Patrick Mezard <patrick@mezard.eu>
parents:
20510
diff
changeset
|
1391 |
# adds an extension to HGRC. Also include run-test.py directory to import |
dcd3bebf4786
run-tests: fix heredoctest for out-of-tree extensions
Patrick Mezard <patrick@mezard.eu>
parents:
20510
diff
changeset
|
1392 |
# modules like heredoctest. |
dcd3bebf4786
run-tests: fix heredoctest for out-of-tree extensions
Patrick Mezard <patrick@mezard.eu>
parents:
20510
diff
changeset
|
1393 |
pypath = [PYTHONDIR, TESTDIR, os.path.abspath(os.path.dirname(__file__))] |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1394 |
# We have to augment PYTHONPATH, rather than simply replacing |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1395 |
# it, in case external libraries are only available via current |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1396 |
# PYTHONPATH. (In particular, the Subversion bindings on OS X |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1397 |
# are in /opt/subversion.) |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1398 |
oldpypath = os.environ.get(IMPL_PATH) |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1399 |
if oldpypath: |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1400 |
pypath.append(oldpypath) |
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
1401 |
os.environ[IMPL_PATH] = os.pathsep.join(pypath) |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1402 |
|
8094
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1403 |
COVERAGE_FILE = os.path.join(TESTDIR, ".coverage") |
8093
70d8f70264c4
run-tests: move bits of main program so it's all at the bottom.
Greg Ward <greg-hg@gerg.ca>
parents:
8092
diff
changeset
|
1404 |
|
8094
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1405 |
vlog("# Using TESTDIR", TESTDIR) |
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1406 |
vlog("# Using HGTMP", HGTMP) |
8674
0941ee76489e
run-tests: redefine --with-hg so it takes the 'hg' script to run.
Greg Ward <greg-hg@gerg.ca>
parents:
8673
diff
changeset
|
1407 |
vlog("# Using PATH", os.environ["PATH"]) |
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
1408 |
vlog("# Using", IMPL_PATH, os.environ[IMPL_PATH]) |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
1409 |
|
8094
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1410 |
try: |
21007
57179a4bf77a
run-tests: use return values instead of sys.exit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21006
diff
changeset
|
1411 |
return runtests(options, tests) or 0 |
8094
60a9e3cf0cf4
run-tests: factor out main(); reduce use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8093
diff
changeset
|
1412 |
finally: |
16346
48692b416fbc
tests: shorten post-test sleeps
Matt Mackall <mpm@selenic.com>
parents:
15942
diff
changeset
|
1413 |
time.sleep(.1) |
8097
eea3c1a8fba8
run-tests: removed some underscores (coding style)
Martin Geisler <mg@lazybytes.net>
parents:
8096
diff
changeset
|
1414 |
cleanup(options) |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
1415 |
|
13347
ce07defe7d9f
run-tests: loadable as module
Simon Heimberg <simohe@besonet.ch>
parents:
13031
diff
changeset
|
1416 |
if __name__ == '__main__': |
21007
57179a4bf77a
run-tests: use return values instead of sys.exit
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21006
diff
changeset
|
1417 |
sys.exit(main(sys.argv[1:])) |