Mercurial > hg
annotate tests/run-tests.py @ 52288:7f8d0c2c3692
run-tests: add a 4th `HGPORT` value
I want to add tls1.3 support, and test-https.t already uses the existing ports
to test tls1.0 through 1.2. It doesn't look to me like it can easily be
converted to a bunch of #testcases, because this also tests downgrades to prior
versions for the given client version.
This partially reverts bc010fcd836b.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 21 Dec 2020 13:50:25 -0500 |
parents | 763817eca85e |
children | d49144a1422f |
rev | line source |
---|---|
45830
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
45826
diff
changeset
|
1 #!/usr/bin/env python3 |
2110
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 # |
46819
d4ba4d51f85f
contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents:
46754
diff
changeset
|
5 # Copyright 2006 Olivia Mackall <olivia@selenic.com> |
2110
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 |
26158
342ab95a1f4b
run-tests: use $HGTEST_RUN_TESTS_PURE
timeless@mozdev.org
parents:
26109
diff
changeset
|
38 # 10) parallel, pure, tests that call run-tests: |
342ab95a1f4b
run-tests: use $HGTEST_RUN_TESTS_PURE
timeless@mozdev.org
parents:
26109
diff
changeset
|
39 # ./run-tests.py --pure `grep -l run-tests.py *.t` |
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
|
40 # |
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 # (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
|
42 # 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
|
43 # 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
|
44 # 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
|
45 |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
46 |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
47 import argparse |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
48 import collections |
45955
064449f9fdc2
run-tests: use a context manager when looking for available ports
Matt Harbison <matt_harbison@yahoo.com>
parents:
45942
diff
changeset
|
49 import contextlib |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
50 import difflib |
49496
35bf7f23b84c
run-tests: deal with distutil deprecation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49306
diff
changeset
|
51 |
2571
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 errno |
48859
f928dec9add7
tests: unconditionalize _unified_diff
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48858
diff
changeset
|
53 import functools |
28126
562a073a2a1b
tests: load json with no fallback
Yuya Nishihara <yuya@tcha.org>
parents:
28099
diff
changeset
|
54 import json |
40245
e7e70c033783
run-tests: run tests with as many processes as cores by default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40244
diff
changeset
|
55 import multiprocessing |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
56 import os |
44489
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
57 import platform |
48867
f547a5dee234
tests: unconditionalize some imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48866
diff
changeset
|
58 import queue |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
59 import random |
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
60 import re |
48867
f547a5dee234
tests: unconditionalize some imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48866
diff
changeset
|
61 import shlex |
10905
13a1b2fb7ef2
pylint, pyflakes: remove unused or duplicate imports
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
10903
diff
changeset
|
62 import shutil |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
63 import signal |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
64 import socket |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
65 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
|
66 import sys |
32302
8627cf4de929
run-tests: drop fallback for sysconfig for pre-py2.7
Martin von Zweigbergk <martinvonz@google.com>
parents:
31950
diff
changeset
|
67 import sysconfig |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
68 import tempfile |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
69 import threading |
2571
83cfd95eafb5
tests: add timeouts, make run-tests.py clean up dead daemon processes
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2570
diff
changeset
|
70 import time |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
71 import unittest |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
72 import uuid |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
73 import xml.dom.minidom as minidom |
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
74 |
49496
35bf7f23b84c
run-tests: deal with distutil deprecation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49306
diff
changeset
|
75 |
51951
737423ae03c2
run-tests: bump the minimum python to 3.8
Matt Harbison <matt_harbison@yahoo.com>
parents:
51837
diff
changeset
|
76 if sys.version_info < (3, 8, 0): |
48880
431084a68c4a
tests: move Python 3.5 check higher in file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
77 print( |
51951
737423ae03c2
run-tests: bump the minimum python to 3.8
Matt Harbison <matt_harbison@yahoo.com>
parents:
51837
diff
changeset
|
78 '%s is only supported on Python 3.8+, not %s' |
48880
431084a68c4a
tests: move Python 3.5 check higher in file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
79 % (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])) |
431084a68c4a
tests: move Python 3.5 check higher in file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
80 ) |
431084a68c4a
tests: move Python 3.5 check higher in file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
81 sys.exit(70) # EX_SOFTWARE from `man 3 sysexit` |
431084a68c4a
tests: move Python 3.5 check higher in file
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
82 |
49832
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
83 MACOS = sys.platform == 'darwin' |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
84 WINDOWS = os.name == r'nt' |
48867
f547a5dee234
tests: unconditionalize some imports
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48866
diff
changeset
|
85 shellquote = shlex.quote |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
86 |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
87 |
14019
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
88 processlock = threading.Lock() |
19413
a4de0d3dc35a
run-tests: lock popen wait/poll
Brendan Cully <brendan@kublai.com>
parents:
19407
diff
changeset
|
89 |
33552
754569f5e999
run-tests: make sure to check if pygments is installed before using it
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33500
diff
changeset
|
90 pygmentspresent = False |
47308
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
91 try: # is pygments installed |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
92 import pygments |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
93 import pygments.lexers as lexers |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
94 import pygments.lexer as lexer |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
95 import pygments.formatters as formatters |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
96 import pygments.token as token |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
97 import pygments.style as style |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
98 |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
99 if WINDOWS: |
47308
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
100 hgpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
101 sys.path.append(hgpath) |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
102 try: |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
103 from mercurial import win32 # pytype: disable=import-error |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
104 |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
105 # Don't check the result code because it fails on heptapod, but |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
106 # something is able to convert to color anyway. |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
107 win32.enablevtmode() |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
108 finally: |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
109 sys.path = sys.path[:-1] |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
110 |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
111 pygmentspresent = True |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
112 difflexer = lexers.DiffLexer() |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
113 terminal256formatter = formatters.Terminal256Formatter() |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
114 except ImportError: |
bb4606f35d37
run-tests: enable color on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47233
diff
changeset
|
115 pass |
33420
e80041832eec
run-tests: add color to output if pygments is available
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33203
diff
changeset
|
116 |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
117 progress_type = {} |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
118 |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
119 if pygmentspresent: |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
120 _T_ERROR = token.string_to_tokentype("Token.Generic.Error") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
121 _T_FAILED = token.string_to_tokentype("Token.Generic.Failed") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
122 _T_FNAME = token.string_to_tokentype("Token.Generic.FName") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
123 _T_IGNORED = token.string_to_tokentype("Token.Generic.Ignored") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
124 _T_SKIPPED = token.string_to_tokentype("Token.Generic.Skipped") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
125 _T_SNAME = token.string_to_tokentype("Token.Generic.SName") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
126 _T_SKIPPED_DOT = token.string_to_tokentype("Token.Generic.SkippedDot") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
127 _T_SUCCESS = token.string_to_tokentype("Token.Generic.Success") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
128 _T_TIMEDOUT = token.string_to_tokentype("Token.Generic.TimedOut") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
129 |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
130 class TestRunnerStyle(style.Style): |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
131 default_style = "" |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
132 styles = { |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
133 _T_ERROR: '#cd00cd', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
134 _T_FAILED: '#7f0000', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
135 _T_FNAME: '#ff0000', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
136 _T_IGNORED: '#cdcd00', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
137 _T_SKIPPED: '#e5e5e5', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
138 _T_SNAME: '#00ffff', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
139 _T_SKIPPED_DOT: '#00ffff', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
140 _T_SUCCESS: '#00cd00', |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
141 _T_TIMEDOUT: '#ff00ff', |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
142 } |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
143 |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
144 class TestRunnerLexer(lexer.RegexLexer): |
38290
b5651ae53127
run-tests: restrict the test cases allowed characters
Boris Feld <boris.feld@octobus.net>
parents:
38251
diff
changeset
|
145 testpattern = r'[\w-]+\.(t|py)(#[a-zA-Z0-9_\-\.]+)?' |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
146 tokens = { |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
147 'root': [ |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
148 (r'^Skipped', _T_SKIPPED, 'skipped'), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
149 (r'^Failed ', _T_FAILED, 'failed'), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
150 (r'^ERROR: ', _T_FAILED, 'failed'), |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
151 ], |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
152 'skipped': [ |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
153 (testpattern, _T_SNAME), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
154 (r':.*', _T_SKIPPED), |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
155 ], |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
156 'failed': [ |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
157 (testpattern, _T_FNAME), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
158 (r'(:| ).*', _T_FAILED), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
159 ], |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
160 } |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
161 |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
162 progress_type['.'] = _T_SUCCESS |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
163 progress_type['s'] = _T_SKIPPED_DOT |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
164 progress_type['i'] = _T_IGNORED |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
165 progress_type['!'] = _T_FAILED |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
166 progress_type['E'] = _T_ERROR |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
167 progress_type['t'] = _T_TIMEDOUT |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
168 |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
169 class progressLexer(lexer.RegexLexer): |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
170 testpattern = r'[\w-]+\.(t|py)(#[a-zA-Z0-9_\-\.]+)?' |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
171 tokens = { |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
172 'root': [ |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
173 (r'^Skipped', _T_SKIPPED, 'skipped'), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
174 (r'^Failed ', _T_FAILED, 'failed'), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
175 (r'^ERROR: ', _T_FAILED, 'failed'), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
176 ], |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
177 'skipped': [ |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
178 (testpattern, _T_SNAME), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
179 (r':.*', _T_SKIPPED), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
180 ], |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
181 'failed': [ |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
182 (testpattern, _T_FNAME), |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
183 (r'(:| ).*', _T_FAILED), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
184 ], |
33814
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
185 } |
81b12f69ef5b
run-tests: also color the summary messages (skipped, failed...)
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33710
diff
changeset
|
186 |
33866
4e8a46c25fac
run-tests: pre instantiate pygments objects
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33814
diff
changeset
|
187 runnerformatter = formatters.Terminal256Formatter(style=TestRunnerStyle) |
4e8a46c25fac
run-tests: pre instantiate pygments objects
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33814
diff
changeset
|
188 runnerlexer = TestRunnerLexer() |
4e8a46c25fac
run-tests: pre instantiate pygments objects
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33814
diff
changeset
|
189 |
39645
13179f97f697
py3: ensure run-tests.osenvironb is actually bytes
Matt Harbison <matt_harbison@yahoo.com>
parents:
39589
diff
changeset
|
190 origenviron = os.environ.copy() |
13179f97f697
py3: ensure run-tests.osenvironb is actually bytes
Matt Harbison <matt_harbison@yahoo.com>
parents:
39589
diff
changeset
|
191 |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
192 |
48856
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
193 def _sys2bytes(p): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
194 if p is None: |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
195 return p |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
196 return p.encode('utf-8') |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
197 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
198 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
199 def _bytes2sys(p): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
200 if p is None: |
25161
4d30467d944e
run-tests: move unicode-to-bytes operations on paths to a helper (issue4667)
Augie Fackler <augie@google.com>
parents:
25160
diff
changeset
|
201 return p |
48856
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
202 return p.decode('utf-8') |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
203 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
204 |
50931
a4ec7a92d2c5
tests: avoid test environment affecting setup.py
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents:
50335
diff
changeset
|
205 original_env = os.environ.copy() |
48856
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
206 osenvironb = getattr(os, 'environb', None) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
207 if osenvironb is None: |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
208 # Windows lacks os.environb, for instance. A proxy over the real thing |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
209 # instead of a copy allows the environment to be updated via bytes on |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
210 # all platforms. |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48880
diff
changeset
|
211 class environbytes: |
48856
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
212 def __init__(self, strenv): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
213 self.__len__ = strenv.__len__ |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
214 self.clear = strenv.clear |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
215 self._strenv = strenv |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
216 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
217 def __getitem__(self, k): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
218 v = self._strenv.__getitem__(_bytes2sys(k)) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
219 return _sys2bytes(v) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
220 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
221 def __setitem__(self, k, v): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
222 self._strenv.__setitem__(_bytes2sys(k), _bytes2sys(v)) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
223 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
224 def __delitem__(self, k): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
225 self._strenv.__delitem__(_bytes2sys(k)) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
226 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
227 def __contains__(self, k): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
228 return self._strenv.__contains__(_bytes2sys(k)) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
229 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
230 def __iter__(self): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
231 return iter([_sys2bytes(k) for k in iter(self._strenv)]) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
232 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
233 def get(self, k, default=None): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
234 v = self._strenv.get(_bytes2sys(k), _bytes2sys(default)) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
235 return _sys2bytes(v) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
236 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
237 def pop(self, k, default=None): |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
238 v = self._strenv.pop(_bytes2sys(k), _bytes2sys(default)) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
239 return _sys2bytes(v) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
240 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
241 osenvironb = environbytes(os.environ) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
242 |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
243 getcwdb = getattr(os, 'getcwdb') |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
244 if not getcwdb or WINDOWS: |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
245 getcwdb = lambda: _sys2bytes(os.getcwd()) |
078e1e1cc7da
tests: require Python 3.5+ in run-tests.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48735
diff
changeset
|
246 |
25162
153b9c5235c2
run-tests: replace open-coded .decode()s on paths with a helper (issue4667)
Augie Fackler <augie@google.com>
parents:
25161
diff
changeset
|
247 |
47619
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
248 if WINDOWS: |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
249 _getcwdb = getcwdb |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
250 |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
251 def getcwdb(): |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
252 cwd = _getcwdb() |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
253 if re.match(b'^[a-z]:', cwd): |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
254 # os.getcwd() is inconsistent on the capitalization of the drive |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
255 # letter, so adjust it. see https://bugs.python.org/issue40368 |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
256 cwd = cwd[0:1].upper() + cwd[1:] |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
257 return cwd |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
258 |
f0fbe8f4faa6
run-tests: enforce the drive letter from `getcwd` to upper case
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47588
diff
changeset
|
259 |
25177
c3459555318e
run-tests: resurrect the wifexited polyfill (backout 6ab5a1c9ea3c)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25162
diff
changeset
|
260 # For Windows support |
c3459555318e
run-tests: resurrect the wifexited polyfill (backout 6ab5a1c9ea3c)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25162
diff
changeset
|
261 wifexited = getattr(os, "WIFEXITED", lambda x: False) |
c3459555318e
run-tests: resurrect the wifexited polyfill (backout 6ab5a1c9ea3c)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25162
diff
changeset
|
262 |
51958
16574ca8b155
test: preserve the existing module policy config for testrepohg resuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51916
diff
changeset
|
263 |
30984
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
264 # Whether to use IPv6 |
31002 | 265 def checksocketfamily(name, port=20058): |
266 """return true if we can listen on localhost using family=name | |
267 | |
268 name should be either 'AF_INET', or 'AF_INET6'. | |
269 port being used is okay - EADDRINUSE is considered as successful. | |
270 """ | |
271 family = getattr(socket, name, None) | |
30984
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
272 if family is None: |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
273 return False |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
274 try: |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
275 s = socket.socket(family, socket.SOCK_STREAM) |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
276 s.bind(('localhost', port)) |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
277 s.close() |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
278 return True |
48956
c194e93d1ebc
tests: support another error case when detecting ipv4/ipv6 support
Kyle Lippincott <spectral@google.com>
parents:
48946
diff
changeset
|
279 except (socket.error, OSError) as exc: |
30984
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
280 if exc.errno == errno.EADDRINUSE: |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
281 return True |
48963
7e18fc0bc46c
tests: fix formatting issue in run-tests.py after c194e93d1ebc
Kyle Lippincott <spectral@google.com>
parents:
48956
diff
changeset
|
282 elif exc.errno in ( |
7e18fc0bc46c
tests: fix formatting issue in run-tests.py after c194e93d1ebc
Kyle Lippincott <spectral@google.com>
parents:
48956
diff
changeset
|
283 errno.EADDRNOTAVAIL, |
7e18fc0bc46c
tests: fix formatting issue in run-tests.py after c194e93d1ebc
Kyle Lippincott <spectral@google.com>
parents:
48956
diff
changeset
|
284 errno.EPROTONOSUPPORT, |
7e18fc0bc46c
tests: fix formatting issue in run-tests.py after c194e93d1ebc
Kyle Lippincott <spectral@google.com>
parents:
48956
diff
changeset
|
285 errno.EAFNOSUPPORT, |
7e18fc0bc46c
tests: fix formatting issue in run-tests.py after c194e93d1ebc
Kyle Lippincott <spectral@google.com>
parents:
48956
diff
changeset
|
286 ): |
30984
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
287 return False |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
288 else: |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
289 raise |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
290 else: |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
291 return False |
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
292 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
293 |
31011
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
294 # useipv6 will be set by parseargs |
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
295 useipv6 = None |
30984
15f9084a9a0c
runtests: add a function to test if IPv6 is available
Jun Wu <quark@fb.com>
parents:
30896
diff
changeset
|
296 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
297 |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
298 def checkportisavailable(port): |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
299 """return true if a port seems free to bind on localhost""" |
30985
1f803482844a
runtests: checkportisavailable should only check one family
Jun Wu <quark@fb.com>
parents:
30984
diff
changeset
|
300 if useipv6: |
1f803482844a
runtests: checkportisavailable should only check one family
Jun Wu <quark@fb.com>
parents:
30984
diff
changeset
|
301 family = socket.AF_INET6 |
1f803482844a
runtests: checkportisavailable should only check one family
Jun Wu <quark@fb.com>
parents:
30984
diff
changeset
|
302 else: |
1f803482844a
runtests: checkportisavailable should only check one family
Jun Wu <quark@fb.com>
parents:
30984
diff
changeset
|
303 family = socket.AF_INET |
30987
1ee685defe80
runtests: unindent an "if True" block
Jun Wu <quark@fb.com>
parents:
30986
diff
changeset
|
304 try: |
45955
064449f9fdc2
run-tests: use a context manager when looking for available ports
Matt Harbison <matt_harbison@yahoo.com>
parents:
45942
diff
changeset
|
305 with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s: |
064449f9fdc2
run-tests: use a context manager when looking for available ports
Matt Harbison <matt_harbison@yahoo.com>
parents:
45942
diff
changeset
|
306 s.bind(('localhost', port)) |
30987
1ee685defe80
runtests: unindent an "if True" block
Jun Wu <quark@fb.com>
parents:
30986
diff
changeset
|
307 return True |
49875
a77c1375c316
run-tests: drop a workaround for python2
Matt Harbison <matt_harbison@yahoo.com>
parents:
49833
diff
changeset
|
308 except PermissionError: |
a77c1375c316
run-tests: drop a workaround for python2
Matt Harbison <matt_harbison@yahoo.com>
parents:
49833
diff
changeset
|
309 return False |
30987
1ee685defe80
runtests: unindent an "if True" block
Jun Wu <quark@fb.com>
parents:
30986
diff
changeset
|
310 except socket.error as exc: |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
311 if WINDOWS and exc.errno == errno.WSAEACCES: |
46327
85c0c7145f8e
run-tests: catch a Windows specific error when testing for a free socket
Matt Harbison <matt_harbison@yahoo.com>
parents:
46326
diff
changeset
|
312 return False |
47181
6e0af81c43b2
run-tests: ignore PermissionError when checking available ports
Matt Harbison <matt_harbison@yahoo.com>
parents:
47040
diff
changeset
|
313 if exc.errno not in ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
314 errno.EADDRINUSE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
315 errno.EADDRNOTAVAIL, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
316 errno.EPROTONOSUPPORT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
317 ): |
30987
1ee685defe80
runtests: unindent an "if True" block
Jun Wu <quark@fb.com>
parents:
30986
diff
changeset
|
318 raise |
30886
2aaa8bfc7bd9
runtests: check ports on IPv6 address
Jun Wu <quark@fb.com>
parents:
30716
diff
changeset
|
319 return False |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
320 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
321 |
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
322 closefds = os.name == 'posix' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
323 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
324 |
19262
7864e8f274fe
run-tests: add env dict to isolate test environment
Matt Mackall <mpm@selenic.com>
parents:
19252
diff
changeset
|
325 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
|
326 processlock.acquire() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
327 p = subprocess.Popen( |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
328 _bytes2sys(cmd), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
329 shell=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
330 bufsize=-1, |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
331 cwd=_bytes2sys(wd), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
332 env=env, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
333 close_fds=closefds, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
334 stdin=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
335 stdout=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
336 stderr=subprocess.STDOUT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
337 ) |
14019
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
338 processlock.release() |
fbbd5f91d5e1
run-tests: do chdir for tests under a lock for thread safety
Matt Mackall <mpm@selenic.com>
parents:
14018
diff
changeset
|
339 |
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
340 p.fromchild = p.stdout |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
341 p.tochild = p.stdin |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
342 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
|
343 |
14337
439ed4721a6d
run-tests: ignore timeout when Popen.terminate is unavailable
Patrick Mezard <pmezard@gmail.com>
parents:
14336
diff
changeset
|
344 p.timeout = False |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
345 if timeout: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
346 |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
347 def t(): |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
348 start = time.time() |
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
349 while time.time() - start < timeout and p.returncode is None: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
350 time.sleep(0.1) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
351 p.timeout = True |
46918
248cbe173203
run-test: make it clearer why we terminating process
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46870
diff
changeset
|
352 vlog('# Timout reached for process %d' % p.pid) |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
353 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
|
354 terminate(p) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
355 |
14001
9c4da6ab4e5a
run-tests: switch timeout handling from alarm to helper thread
Matt Mackall <mpm@selenic.com>
parents:
14000
diff
changeset
|
356 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
|
357 |
8280
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
358 return p |
0b02d98d44d0
util: always use subprocess
Martin Geisler <mg@lazybytes.net>
parents:
8258
diff
changeset
|
359 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
360 |
42523
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
361 if sys.executable: |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
362 sysexecutable = sys.executable |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
363 elif os.environ.get('PYTHONEXECUTABLE'): |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
364 sysexecutable = os.environ['PYTHONEXECUTABLE'] |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
365 elif os.environ.get('PYTHON'): |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
366 sysexecutable = os.environ['PYTHON'] |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
367 else: |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
368 raise AssertionError('Could not find Python interpreter') |
49998d5ba66a
pycompat: make fewer assumptions about sys.executable
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42512
diff
changeset
|
369 |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
370 PYTHON = _sys2bytes(sysexecutable.replace('\\', '/')) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
371 IMPL_PATH = b'PYTHONPATH' |
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
372 if 'java' in sys.platform: |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
373 IMPL_PATH = b'JYTHONPATH' |
4881
c51c9bc4579d
Add hghave utility and run-tests.py support.
Patrick Mezard <pmezard@gmail.com>
parents:
4880
diff
changeset
|
374 |
44632
82543879b48e
testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44615
diff
changeset
|
375 default_defaults = { |
40245
e7e70c033783
run-tests: run tests with as many processes as cores by default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
40244
diff
changeset
|
376 'jobs': ('HGTEST_JOBS', multiprocessing.cpu_count()), |
51952
f4c038081561
run-tests: bump the default timeout on Windows to 4x the normal value
Matt Harbison <matt_harbison@yahoo.com>
parents:
51951
diff
changeset
|
377 'timeout': ('HGTEST_TIMEOUT', 360 if not WINDOWS else 360 * 4), |
41801
9f53a4e2e193
tests: increase timeout for slow test
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41759
diff
changeset
|
378 'slowtimeout': ('HGTEST_SLOWTIMEOUT', 1500), |
6366
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
379 '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
|
380 '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
|
381 } |
07c3cd695b48
run-tests.py: Allow environment variables to set jobs/timeout/port.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
6343
diff
changeset
|
382 |
44632
82543879b48e
testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44615
diff
changeset
|
383 defaults = default_defaults.copy() |
82543879b48e
testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44615
diff
changeset
|
384 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
385 |
28644
2e50eb6304bd
run-tests: add canonpath function
timeless <timeless@mozdev.org>
parents:
28620
diff
changeset
|
386 def canonpath(path): |
2e50eb6304bd
run-tests: add canonpath function
timeless <timeless@mozdev.org>
parents:
28620
diff
changeset
|
387 return os.path.realpath(os.path.expanduser(path)) |
2e50eb6304bd
run-tests: add canonpath function
timeless <timeless@mozdev.org>
parents:
28620
diff
changeset
|
388 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
389 |
47588
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
390 def which(exe): |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
391 # shutil.which only accept bytes from 3.8 |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
392 cmd = _bytes2sys(exe) |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
393 real_exec = shutil.which(cmd) |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
394 return _sys2bytes(real_exec) |
47588
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
395 |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
396 |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
397 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
|
398 entries = dict() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
399 for filename in files: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
400 try: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
401 path = os.path.expanduser(os.path.expandvars(filename)) |
21916
792ebd7dc5f6
run-tests: write out scripts in binary mode
Augie Fackler <raf@durin42.com>
parents:
21763
diff
changeset
|
402 f = open(path, "rb") |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
403 except FileNotFoundError: |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
404 if warn: |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
405 print("warning: no such %s file: %s" % (listtype, filename)) |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
406 continue |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
407 |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
408 for line in f.readlines(): |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
409 line = line.split(b'#', 1)[0].strip() |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
410 if line: |
47182
dff19fe2973c
run-tests: fix whitelist/blacklist with directories on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47181
diff
changeset
|
411 # Ensure path entries are compatible with os.path.relpath() |
dff19fe2973c
run-tests: fix whitelist/blacklist with directories on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
47181
diff
changeset
|
412 entries[os.path.normpath(line)] = filename |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
413 |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
414 f.close() |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
415 return entries |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
416 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
417 |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
418 def parsettestcases(path): |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
419 """read a .t test file, return a set of test case names |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
420 |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
421 If path does not exist, return an empty set. |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
422 """ |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
423 cases = [] |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
424 try: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
425 with open(path, 'rb') as f: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
426 for l in f: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
427 if l.startswith(b'#testcases '): |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
428 cases.append(sorted(l[11:].split())) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
429 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
430 pass |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
431 return cases |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
432 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
433 |
21008
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
434 def getparser(): |
21383
772ed56e2519
run-tests: add some docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21382
diff
changeset
|
435 """Obtain the OptionParser used by the CLI.""" |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
436 parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]') |
11039 | 437 |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
438 selection = parser.add_argument_group('Test Selection') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
439 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
440 '--allow-slow-tests', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
441 action='store_true', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
442 help='allow extremely slow tests', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
443 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
444 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
445 "--blacklist", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
446 action="append", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
447 help="skip tests listed in the specified blacklist file", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
448 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
449 selection.add_argument( |
52215
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
450 "--shard-total", |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
451 type=int, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
452 default=None, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
453 help="total number of shard to use (enable sharding)", |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
454 ) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
455 selection.add_argument( |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
456 "--shard-index", |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
457 type=int, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
458 default=None, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
459 help="index of this shard [1-N]", |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
460 ) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
461 selection.add_argument( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
462 "--changed", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
463 help="run tests that are changed in parent rev or working directory", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
464 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
465 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
466 "-k", "--keywords", help="run tests matching keywords" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
467 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
468 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
469 "-r", "--retest", action="store_true", help="retest failed tests" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
470 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
471 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
472 "--test-list", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
473 action="append", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
474 help="read tests to run from the specified file", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
475 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
476 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
477 "--whitelist", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
478 action="append", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
479 help="always run tests listed in the specified whitelist file", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
480 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
481 selection.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
482 'tests', metavar='TESTS', nargs='*', help='Tests to run' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
483 ) |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
484 |
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
485 harness = parser.add_argument_group('Test Harness Behavior') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
486 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
487 '--bisect-repo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
488 metavar='bisect_repo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
489 help=( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
490 "Path of a repo to bisect. Use together with " "--known-good-rev" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
491 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
492 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
493 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
494 "-d", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
495 "--debug", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
496 action="store_true", |
11039 | 497 help="debug mode: write output of test scripts to console" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
498 " rather than capturing and diffing it (disables timeout)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
499 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
500 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
501 "-f", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
502 "--first", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
503 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
504 help="exit on the first test failure", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
505 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
506 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
507 "-i", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
508 "--interactive", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
509 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
510 help="prompt to accept changed output", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
511 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
512 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
513 "-j", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
514 "--jobs", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
515 type=int, |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
516 help="number of jobs to run in parallel" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
517 " (default: $%s or %d)" % defaults['jobs'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
518 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
519 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
520 "--keep-tmpdir", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
521 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
522 help="keep temporary directory after running tests", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
523 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
524 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
525 '--known-good-rev', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
526 metavar="known_good_rev", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
527 help=( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
528 "Automatically bisect any failures using this " |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
529 "revision as a known-good revision." |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
530 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
531 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
532 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
533 "--list-tests", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
534 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
535 help="list tests instead of running them", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
536 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
537 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
538 "--loop", action="store_true", help="loop tests repeatedly" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
539 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
540 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
541 '--random', action="store_true", help='run tests in random order' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
542 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
543 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
544 '--order-by-runtime', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
545 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
546 help='run slowest tests first, according to .testtimes', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
547 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
548 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
549 "-p", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
550 "--port", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
551 type=int, |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
552 help="port on which servers should listen" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
553 " (default: $%s or %d)" % defaults['port'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
554 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
555 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
556 '--profile-runner', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
557 action='store_true', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
558 help='run statprof on run-tests', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
559 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
560 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
561 "-R", "--restart", action="store_true", help="restart at last error" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
562 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
563 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
564 "--runs-per-test", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
565 type=int, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
566 dest="runs_per_test", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
567 help="run each test N times (default=1)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
568 default=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
569 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
570 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
571 "--shell", help="shell to use (default: $%s or %s)" % defaults['shell'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
572 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
573 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
574 '--showchannels', action='store_true', help='show scheduling channels' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
575 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
576 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
577 "--slowtimeout", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
578 type=int, |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
579 help="kill errant slow tests after SLOWTIMEOUT seconds" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
580 " (default: $%s or %d)" % defaults['slowtimeout'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
581 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
582 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
583 "-t", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
584 "--timeout", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
585 type=int, |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
586 help="kill errant tests after TIMEOUT seconds" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
587 " (default: $%s or %d)" % defaults['timeout'], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
588 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
589 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
590 "--tmpdir", |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
591 help="run tests in the given temporary directory" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
592 " (implies --keep-tmpdir)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
593 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
594 harness.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
595 "-v", "--verbose", action="store_true", help="output verbose messages" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
596 ) |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
597 |
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
598 hgconf = parser.add_argument_group('Mercurial Configuration') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
599 hgconf.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
600 "--chg", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
601 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
602 help="install and use chg wrapper in place of hg", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
603 ) |
44615
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
604 hgconf.add_argument( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
605 "--chg-debug", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
606 action="store_true", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
607 help="show chg debug logs", |
44615
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
608 ) |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
609 hgconf.add_argument( |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
610 "--rhg", |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
611 action="store_true", |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
612 help="install and use rhg Rust implementation in place of hg", |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
613 ) |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
614 hgconf.add_argument( |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
615 "--pyoxidized", |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
616 action="store_true", |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
617 help="build the hg binary using pyoxidizer", |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
618 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
619 hgconf.add_argument("--compiler", help="compiler to build with") |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
620 hgconf.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
621 '--extra-config-opt', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
622 action="append", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
623 default=[], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
624 help='set the given config opt in the test hgrc', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
625 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
626 hgconf.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
627 "-l", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
628 "--local", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
629 action="store_true", |
29583
6ce870dba6fa
run-tests: make --local set --with-chg if --chg is used
Jun Wu <quark@fb.com>
parents:
29582
diff
changeset
|
630 help="shortcut for --with-hg=<testdir>/../hg, " |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
631 "--with-rhg=<testdir>/../rust/target/release/rhg if --rhg is set, " |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
632 "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
633 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
634 hgconf.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
635 "--ipv6", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
636 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
637 help="prefer IPv6 to IPv4 for network related tests", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
638 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
639 hgconf.add_argument( |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
640 "--hg-wheel", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
641 default=None, |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
642 metavar="WHEEL_PATH", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
643 dest="wheel", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
644 help="install mercurial from the given wheel", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
645 ) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
646 hgconf.add_argument( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
647 "--pure", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
648 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
649 help="use pure Python code instead of C extensions", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
650 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
651 hgconf.add_argument( |
44489
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
652 "--rust", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
653 action="store_true", |
44489
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
654 help="use Rust code alongside C extensions", |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
655 ) |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
656 hgconf.add_argument( |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
657 "--no-rust", |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
658 action="store_true", |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
659 help="do not use Rust code even if compiled", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
660 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
661 hgconf.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
662 "--with-chg", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
663 metavar="CHG", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
664 help="use specified chg wrapper in place of hg", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
665 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
666 hgconf.add_argument( |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
667 "--with-rhg", |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
668 metavar="RHG", |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
669 help="use specified rhg Rust implementation in place of hg", |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
670 ) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
671 hgconf.add_argument( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
672 "--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
|
673 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
|
674 help="test using specified hg script rather than a " |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
675 "temporary installation", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
676 ) |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
677 |
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
678 reporting = parser.add_argument_group('Results Reporting') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
679 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
680 "-C", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
681 "--annotate", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
682 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
683 help="output files annotated with coverage", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
684 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
685 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
686 "--color", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
687 choices=["always", "auto", "never"], |
35188
d997b82152e8
run-tests: organize options into argument groups
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35187
diff
changeset
|
688 default=os.environ.get('HGRUNTESTSCOLOR', 'auto'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
689 help="colorisation: always|auto|never (default: auto)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
690 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
691 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
692 "-c", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
693 "--cover", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
694 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
695 help="print a test coverage report", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
696 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
697 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
698 '--exceptions', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
699 action='store_true', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
700 help='log all exceptions and generate an exception report', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
701 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
702 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
703 "-H", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
704 "--htmlcov", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
705 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
706 help="create an HTML report of the coverage of the files", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
707 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
708 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
709 "--json", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
710 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
711 help="store test result data in 'report.json' file", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
712 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
713 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
714 "--outputdir", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
715 help="directory to write error logs to (default=test directory)", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
716 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
717 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
718 "-n", "--nodiff", action="store_true", help="skip showing test changes" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
719 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
720 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
721 "-S", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
722 "--noskips", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
723 action="store_true", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
724 help="don't report skip tests verbosely", |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
725 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
726 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
727 "--time", action="store_true", help="time how long each test takes" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
728 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
729 reporting.add_argument("--view", help="external diff viewer") |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
730 reporting.add_argument( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
731 "--xunit", help="record xunit results at specified path" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
732 ) |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
733 |
14201
57e04ded3da4
run-tests: use type of default to convert environment variable
Martin Geisler <mg@lazybytes.net>
parents:
14192
diff
changeset
|
734 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
|
735 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
|
736 parser.set_defaults(**defaults) |
21008
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
737 |
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
738 return parser |
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
739 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
740 |
21008
c1dd04be3d9a
run-tests: allow option parser to be extended
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21007
diff
changeset
|
741 def parseargs(args, parser): |
21383
772ed56e2519
run-tests: add some docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21382
diff
changeset
|
742 """Parse arguments with our OptionParser and validate results.""" |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
743 options = 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
|
744 |
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
745 # 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
|
746 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
|
747 options.pure = True |
10758
2ed667a9dfcb
tests: adapt the test runner to work with jython
Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
parents:
10750
diff
changeset
|
748 |
44489
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
749 if platform.python_implementation() != 'CPython' and options.rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
750 parser.error('Rust extensions are only available with CPython') |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
751 |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
752 if options.pure and options.rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
753 parser.error('--rust cannot be used with --pure') |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
754 |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
755 if options.rust and options.no_rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
756 parser.error('--rust cannot be used with --no-rust') |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
757 |
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
|
758 if options.local: |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
759 if options.with_hg or options.with_rhg or options.with_chg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
760 parser.error( |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
761 '--local cannot be used with --with-hg or --with-rhg or --with-chg' |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
762 ) |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
763 if options.pyoxidized: |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
764 parser.error('--pyoxidized does not work with --local (yet)') |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
765 testdir = os.path.dirname(_sys2bytes(canonpath(sys.argv[0]))) |
29582
ee96d95e81a4
run-tests: allow --local to set multiple attributes
Jun Wu <quark@fb.com>
parents:
29518
diff
changeset
|
766 reporootdir = os.path.dirname(testdir) |
ee96d95e81a4
run-tests: allow --local to set multiple attributes
Jun Wu <quark@fb.com>
parents:
29518
diff
changeset
|
767 pathandattrs = [(b'hg', 'with_hg')] |
29583
6ce870dba6fa
run-tests: make --local set --with-chg if --chg is used
Jun Wu <quark@fb.com>
parents:
29582
diff
changeset
|
768 if options.chg: |
6ce870dba6fa
run-tests: make --local set --with-chg if --chg is used
Jun Wu <quark@fb.com>
parents:
29582
diff
changeset
|
769 pathandattrs.append((b'contrib/chg/chg', 'with_chg')) |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
770 if options.rhg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
771 pathandattrs.append((b'rust/target/release/rhg', 'with_rhg')) |
29582
ee96d95e81a4
run-tests: allow --local to set multiple attributes
Jun Wu <quark@fb.com>
parents:
29518
diff
changeset
|
772 for relpath, attr in pathandattrs: |
ee96d95e81a4
run-tests: allow --local to set multiple attributes
Jun Wu <quark@fb.com>
parents:
29518
diff
changeset
|
773 binpath = os.path.join(reporootdir, relpath) |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
774 if not (WINDOWS or os.access(binpath, os.X_OK)): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
775 parser.error( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
776 '--local specified, but %r not found or ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
777 'not executable' % binpath |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
778 ) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
779 setattr(options, attr, _bytes2sys(binpath)) |
42817
69506e1b3214
run-tests: handle --local before --with-hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
42816
diff
changeset
|
780 |
69506e1b3214
run-tests: handle --local before --with-hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
42816
diff
changeset
|
781 if options.with_hg: |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
782 options.with_hg = canonpath(_sys2bytes(options.with_hg)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
783 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
784 os.path.isfile(options.with_hg) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
785 and os.access(options.with_hg, os.X_OK) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
786 ): |
42817
69506e1b3214
run-tests: handle --local before --with-hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
42816
diff
changeset
|
787 parser.error('--with-hg must specify an executable hg script') |
69506e1b3214
run-tests: handle --local before --with-hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
42816
diff
changeset
|
788 if os.path.basename(options.with_hg) not in [b'hg', b'hg.exe']: |
47583
05abe1ff1edd
run-test: clarify the error with a bad --with-hg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47577
diff
changeset
|
789 msg = 'warning: --with-hg should specify an hg script, not: %s\n' |
05abe1ff1edd
run-test: clarify the error with a bad --with-hg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47577
diff
changeset
|
790 msg %= _bytes2sys(os.path.basename(options.with_hg)) |
05abe1ff1edd
run-test: clarify the error with a bad --with-hg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47577
diff
changeset
|
791 sys.stderr.write(msg) |
42817
69506e1b3214
run-tests: handle --local before --with-hg
Martin von Zweigbergk <martinvonz@google.com>
parents:
42816
diff
changeset
|
792 sys.stderr.flush() |
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
|
793 |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
794 if (options.chg or options.with_chg) and WINDOWS: |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
795 parser.error('chg does not work on %s' % os.name) |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
796 if (options.rhg or options.with_rhg) and WINDOWS: |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
797 parser.error('rhg does not work on %s' % os.name) |
49832
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
798 if options.pyoxidized and not (MACOS or WINDOWS): |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
799 parser.error('--pyoxidized is currently macOS and Windows only') |
28142
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
800 if options.with_chg: |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
801 options.chg = False # no installation to temporary location |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
802 options.with_chg = canonpath(_sys2bytes(options.with_chg)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
803 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
804 os.path.isfile(options.with_chg) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
805 and os.access(options.with_chg, os.X_OK) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
806 ): |
28142
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
807 parser.error('--with-chg must specify a chg executable') |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
808 if options.with_rhg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
809 options.rhg = False # no installation to temporary location |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
810 options.with_rhg = canonpath(_sys2bytes(options.with_rhg)) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
811 if not ( |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
812 os.path.isfile(options.with_rhg) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
813 and os.access(options.with_rhg, os.X_OK) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
814 ): |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
815 parser.error('--with-rhg must specify a rhg executable') |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
816 if options.chg and options.with_hg: |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
817 # chg shares installation location with hg |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
818 parser.error( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
819 '--chg does not work when --with-hg is specified ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
820 '(use --with-chg instead)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
821 ) |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
822 if options.rhg and options.with_hg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
823 # rhg shares installation location with hg |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
824 parser.error( |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
825 '--rhg does not work when --with-hg is specified ' |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
826 '(use --with-rhg instead)' |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
827 ) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
828 if options.rhg and options.chg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
829 parser.error('--rhg and --chg do not work together') |
28142
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
830 |
33567
d9677e2ed16a
run-tests: warn if --color=always and no pygments installed
Martin von Zweigbergk <martinvonz@google.com>
parents:
33566
diff
changeset
|
831 if options.color == 'always' and not pygmentspresent: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
832 sys.stderr.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
833 'warning: --color=always ignored because ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
834 'pygments is not installed\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
835 ) |
33567
d9677e2ed16a
run-tests: warn if --color=always and no pygments installed
Martin von Zweigbergk <martinvonz@google.com>
parents:
33566
diff
changeset
|
836 |
34041
40313c63da87
run-tests: allow bisecting a different repo
Jun Wu <quark@fb.com>
parents:
34040
diff
changeset
|
837 if options.bisect_repo and not options.known_good_rev: |
40313c63da87
run-tests: allow bisecting a different repo
Jun Wu <quark@fb.com>
parents:
34040
diff
changeset
|
838 parser.error("--bisect-repo cannot be used without --known-good-rev") |
40313c63da87
run-tests: allow bisecting a different repo
Jun Wu <quark@fb.com>
parents:
34040
diff
changeset
|
839 |
31011
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
840 global useipv6 |
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
841 if options.ipv6: |
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
842 useipv6 = checksocketfamily('AF_INET6') |
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
843 else: |
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
844 # only use IPv6 if IPv4 is unavailable and IPv6 is available |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
845 useipv6 = (not checksocketfamily('AF_INET')) and checksocketfamily( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
846 'AF_INET6' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
847 ) |
31011
01eebb65a61d
runtests: add an IPv6 command line flag
Jun Wu <quark@fb.com>
parents:
31010
diff
changeset
|
848 |
15859
44a371823f83
tests: add htmlcov option
Markus Zapke-Gründemann <info@keimlink.de>
parents:
15858
diff
changeset
|
849 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
|
850 if options.anycoverage: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
851 try: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
852 import coverage |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
853 |
50335
787e7caf887a
run-tests: remove obsolete coverage check and packaging import (issue6805)
pacien <pacien.trangirard@pacien.net>
parents:
50275
diff
changeset
|
854 coverage.__version__ # silence unused import warning |
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
855 except ImportError: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
856 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
|
857 |
10648
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
858 if options.anycoverage and options.local: |
58128004cca1
tests: use external coverage, mandate newer version
Dirkjan Ochtman <djc.ochtman@kentyde.com>
parents:
10413
diff
changeset
|
859 # this needs some path mangling somewhere, I guess |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
860 parser.error( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
861 "sorry, coverage options do not work when --local " "is specified" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
862 ) |
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
|
863 |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
864 if options.anycoverage and options.with_hg: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
865 parser.error( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
866 "sorry, coverage options do not work when --with-hg " "is specified" |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
867 ) |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
868 |
19250
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
869 global verbose |
8095
f5428d4ffd97
run-tests: reduce global variables set by parse_args().
Greg Ward <greg-hg@gerg.ca>
parents:
8094
diff
changeset
|
870 if options.verbose: |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
871 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
|
872 |
9394
31203db1b2ac
run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9031
diff
changeset
|
873 if options.tmpdir: |
28644
2e50eb6304bd
run-tests: add canonpath function
timeless <timeless@mozdev.org>
parents:
28620
diff
changeset
|
874 options.tmpdir = canonpath(options.tmpdir) |
9394
31203db1b2ac
run-tests: expand --tmpdir and create it if needed
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9031
diff
changeset
|
875 |
8091
e85cc856d2e1
run-tests: factor out parse_args(). Clarify use of globals a bit.
Greg Ward <greg-hg@gerg.ca>
parents:
8060
diff
changeset
|
876 if options.jobs < 1: |
9408
70bf7f853adc
run-tests: standardize on --foo instead of -f/--foo
Martin Geisler <mg@lazybytes.net>
parents:
9407
diff
changeset
|
877 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
|
878 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
|
879 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
|
880 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
|
881 if options.timeout != defaults['timeout']: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
882 sys.stderr.write('warning: --timeout option ignored with --debug\n') |
27141
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
883 if options.slowtimeout != defaults['slowtimeout']: |
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
884 sys.stderr.write( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
885 'warning: --slowtimeout option ignored with --debug\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
886 ) |
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
|
887 options.timeout = 0 |
27141
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
888 options.slowtimeout = 0 |
28582
cdbc25306696
run-tests: add --with-python3 to define a Python 3 interpreter
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28569
diff
changeset
|
889 |
9959
b37b060d84c7
run-tests: add a "--blacklist target" option to skip predefined test lists
Nicolas Dumazet <nicdumz.commits@gmail.com>
parents:
9958
diff
changeset
|
890 if options.blacklist: |
14493
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
891 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
|
892 if options.whitelist: |
19279
3868c9ab4bf8
run-tests: drop options.child and users
Matt Mackall <mpm@selenic.com>
parents:
19278
diff
changeset
|
893 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
|
894 else: |
5cc7905bccc9
run-tests: allow whitelisting tests that should always run
Augie Fackler <durin42@gmail.com>
parents:
14454
diff
changeset
|
895 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
|
896 |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
897 if options.showchannels: |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
898 options.nodiff = True |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
899 |
52215
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
900 if options.shard_total is not None: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
901 if options.shard_index is None: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
902 parser.error("--shard-total requires --shard-index to be set") |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
903 |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
904 if options.shard_index is not None: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
905 if options.shard_total is None: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
906 parser.error("--shard-index requires --shard-total to be set") |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
907 elif options.shard_index <= 0: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
908 msg = "--shard-index must be > 0 (%d)" |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
909 msg %= options.shard_index |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
910 parser.error(msg) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
911 elif options.shard_index > options.shard_total: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
912 msg = ( |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
913 "--shard-index must be <= than --shard-total (%d not in [1,%d])" |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
914 ) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
915 msg %= (options.shard_index, options.shard_total) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
916 parser.error(msg) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
917 |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
918 if options.shard_total is not None and options.order_by_runtime: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
919 msg = "cannot use --order-by-runtime when sharding" |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
920 parser.error(msg) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
921 |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
922 if options.shard_total is not None and options.random: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
923 msg = "cannot use --random when sharding" |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
924 parser.error(msg) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
925 |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
926 return options |
5384
e3a0c092b4e2
Allow tests to run in parallel.
Bryan O'Sullivan <bos@serpentine.com>
parents:
5383
diff
changeset
|
927 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
928 |
5800
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
929 def rename(src, dst): |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
930 """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
|
931 for existing destination support. |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
932 """ |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
933 shutil.copy(src, dst) |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
934 os.remove(src) |
2f597243e1d7
Make run-tests.py --interactive work on Windows
Patrick Mezard <pmezard@gmail.com>
parents:
5524
diff
changeset
|
935 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
936 |
40987
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
937 def makecleanable(path): |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
938 """Try to fix directory permission recursively so that the entire tree |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
939 can be deleted""" |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
940 for dirpath, dirnames, _filenames in os.walk(path, topdown=True): |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
941 for d in dirnames: |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
942 p = os.path.join(dirpath, d) |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
943 try: |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
944 os.chmod(p, os.stat(p).st_mode & 0o777 | 0o700) # chmod u+rwx |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
945 except OSError: |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
946 pass |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
947 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
948 |
48859
f928dec9add7
tests: unconditionalize _unified_diff
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48858
diff
changeset
|
949 _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff) |
25045
8a425c2eef5d
run-tests: use difflib.diff_bytes on Python 3
Augie Fackler <augie@google.com>
parents:
25044
diff
changeset
|
950 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
951 |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
952 def getdiff(expected, output, ref, err): |
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
|
953 servefail = False |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
954 lines = [] |
25045
8a425c2eef5d
run-tests: use difflib.diff_bytes on Python 3
Augie Fackler <augie@google.com>
parents:
25044
diff
changeset
|
955 for line in _unified_diff(expected, output, ref, err): |
8a425c2eef5d
run-tests: use difflib.diff_bytes on Python 3
Augie Fackler <augie@google.com>
parents:
25044
diff
changeset
|
956 if line.startswith(b'+++') or line.startswith(b'---'): |
8a425c2eef5d
run-tests: use difflib.diff_bytes on Python 3
Augie Fackler <augie@google.com>
parents:
25044
diff
changeset
|
957 line = line.replace(b'\\', b'/') |
8a425c2eef5d
run-tests: use difflib.diff_bytes on Python 3
Augie Fackler <augie@google.com>
parents:
25044
diff
changeset
|
958 if line.endswith(b' \n'): |
8a425c2eef5d
run-tests: use difflib.diff_bytes on Python 3
Augie Fackler <augie@google.com>
parents:
25044
diff
changeset
|
959 line = line[:-2] + b'\n' |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
960 lines.append(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
|
961 if not servefail and line.startswith( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
962 b'+ abort: child process failed to start' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
963 ): |
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
|
964 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
|
965 |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
966 return servefail, lines |
2110
25a8d116ab6a
Add a pure python version of run-tests.
Stephen Darnell <stephen@darnell.plus.com>
parents:
diff
changeset
|
967 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
968 |
19250
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
969 verbose = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
970 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
971 |
19250
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
972 def vlog(*msg): |
21535
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
973 """Log only when in verbose mode.""" |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
974 if verbose is False: |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
975 return |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
976 |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
977 return log(*msg) |
19250
5fa946330970
run-tests: make vlog a proper function
Matt Mackall <mpm@selenic.com>
parents:
19249
diff
changeset
|
978 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
979 |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
980 # Bytes that break XML even in a CDATA block: control characters 0-31 |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
981 # sans \t, \n and \r |
25051
9c28f3236677
run-tests: do cdata escaping using bytes instead of str
Augie Fackler <augie@google.com>
parents:
25050
diff
changeset
|
982 CDATA_EVIL = re.compile(br"[\000-\010\013\014\016-\037]") |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
983 |
31829
4eec2f04a672
run-tests: support per-line conditional output in tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
31827
diff
changeset
|
984 # Match feature conditionalized output lines in the form, capturing the feature |
4eec2f04a672
run-tests: support per-line conditional output in tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
31827
diff
changeset
|
985 # list in group 2, and the preceeding line output in group 1: |
4eec2f04a672
run-tests: support per-line conditional output in tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
31827
diff
changeset
|
986 # |
4eec2f04a672
run-tests: support per-line conditional output in tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
31827
diff
changeset
|
987 # output..output (feature !)\n |
41540
17a6e063c886
run-tests: use raw strings for regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41495
diff
changeset
|
988 optline = re.compile(br'(.*) \((.+?) !\)\n$') |
31829
4eec2f04a672
run-tests: support per-line conditional output in tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
31827
diff
changeset
|
989 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
990 |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
991 def cdatasafe(data): |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
992 """Make a string safe to include in a CDATA block. |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
993 |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
994 Certain control characters are illegal in a CDATA block, and |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
995 there's no way to include a ]]> in a CDATA either. This function |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
996 replaces illegal bytes with ? and adds a space between the ]] so |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
997 that it won't break the CDATA block. |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
998 """ |
25051
9c28f3236677
run-tests: do cdata escaping using bytes instead of str
Augie Fackler <augie@google.com>
parents:
25050
diff
changeset
|
999 return CDATA_EVIL.sub(b'?', data).replace(b']]>', b'] ]>') |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
1000 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1001 |
19251
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
1002 def log(*msg): |
21535
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
1003 """Log something to stdout. |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
1004 |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
1005 Arguments are strings to print. |
ab7e224bc089
run-tests: avoid duplicate code in vlog()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21534
diff
changeset
|
1006 """ |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1007 with iolock: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1008 if verbose: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1009 print(verbose, end=' ') |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1010 for m in msg: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1011 print(m, end=' ') |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1012 print() |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
1013 sys.stdout.flush() |
19251
6857f53456f2
run-tests: add a log function
Matt Mackall <mpm@selenic.com>
parents:
19250
diff
changeset
|
1014 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1015 |
33930
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1016 def highlightdiff(line, color): |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1017 if not color: |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1018 return line |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1019 assert pygmentspresent |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1020 return pygments.highlight( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1021 line.decode('latin1'), difflexer, terminal256formatter |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1022 ).encode('latin1') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1023 |
33930
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1024 |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1025 def highlightmsg(msg, color): |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1026 if not color: |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1027 return msg |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1028 assert pygmentspresent |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1029 return pygments.highlight(msg, runnerlexer, runnerformatter) |
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
1030 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1031 |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1032 def highlight_progress(progress, color): |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1033 if not color: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1034 return progress |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1035 assert pygmentspresent |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1036 token = progress_type.get(progress) |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1037 if token is None: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1038 return progress |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1039 style = runnerformatter.style_string.get(str(token)) |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1040 if style is None: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1041 return progress |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1042 else: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1043 return style[0] + progress + style[1] |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1044 |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
1045 |
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
1046 def terminate(proc): |
32303
dc131b9772f2
run-tests: drop fallback for proc.terminate() for pre-py2.6
Martin von Zweigbergk <martinvonz@google.com>
parents:
32302
diff
changeset
|
1047 """Terminate subprocess""" |
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
1048 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
|
1049 try: |
32303
dc131b9772f2
run-tests: drop fallback for proc.terminate() for pre-py2.6
Martin von Zweigbergk <martinvonz@google.com>
parents:
32302
diff
changeset
|
1050 proc.terminate() |
14821
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
1051 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
|
1052 pass |
2017495bd552
run-tests: fallback to SIGTERM if subprocess.Popen does not have terminate()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
14598
diff
changeset
|
1053 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1054 |
19263
062c0a0a5549
run-tests: use env dict to kill daemons
Matt Mackall <mpm@selenic.com>
parents:
19262
diff
changeset
|
1055 def killdaemons(pidfile): |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
1056 import killdaemons as killmod |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1057 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1058 return killmod.killdaemons(pidfile, tryhard=False, remove=True, logfn=vlog) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1059 |
10336
bc9a3bb267fa
run-tests: kill daemons on ^C with -j.
Brendan Cully <brendan@kublai.com>
parents:
10300
diff
changeset
|
1060 |
49234
9dad328434c7
tests: work around non-thread-safeness of sysconfig.get_config_var()
Manuel Jacob <me@manueljacob.de>
parents:
49215
diff
changeset
|
1061 # sysconfig is not thread-safe (https://github.com/python/cpython/issues/92452) |
9dad328434c7
tests: work around non-thread-safeness of sysconfig.get_config_var()
Manuel Jacob <me@manueljacob.de>
parents:
49215
diff
changeset
|
1062 sysconfiglock = threading.Lock() |
9dad328434c7
tests: work around non-thread-safeness of sysconfig.get_config_var()
Manuel Jacob <me@manueljacob.de>
parents:
49215
diff
changeset
|
1063 |
9dad328434c7
tests: work around non-thread-safeness of sysconfig.get_config_var()
Manuel Jacob <me@manueljacob.de>
parents:
49215
diff
changeset
|
1064 |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1065 class Test(unittest.TestCase): |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
1066 """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
|
1067 |
21497
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1068 While this class conforms to the unittest.TestCase API, it differs in that |
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1069 instances need to be instantiated manually. (Typically, unittest.TestCase |
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1070 classes are instantiated automatically by scanning modules.) |
21309
0b123e6a318c
run-tests: allow Test.run() to run multiple times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21308
diff
changeset
|
1071 """ |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1072 |
21380
de6ea36ca9f7
run-tests: move SKIPPED_STATUS into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21379
diff
changeset
|
1073 # Status code reserved for skipped tests (used by hghave). |
de6ea36ca9f7
run-tests: move SKIPPED_STATUS into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21379
diff
changeset
|
1074 SKIPPED_STATUS = 80 |
de6ea36ca9f7
run-tests: move SKIPPED_STATUS into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21379
diff
changeset
|
1075 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1076 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1077 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1078 path, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1079 outputdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1080 tmpdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1081 keeptmpdir=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1082 debug=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1083 first=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1084 timeout=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1085 startport=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1086 extraconfigopts=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1087 shell=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1088 hgcommand=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1089 slowtimeout=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1090 usechg=False, |
44615
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
1091 chgdebug=False, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1092 useipv6=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1093 ): |
21502
f8515564d617
run-tests: pass a full test path into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21501
diff
changeset
|
1094 """Create a test from parameters. |
f8515564d617
run-tests: pass a full test path into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21501
diff
changeset
|
1095 |
f8515564d617
run-tests: pass a full test path into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21501
diff
changeset
|
1096 path is the full path to the file defining the test. |
21338
3cd2d2de4060
run-tests: move computation of test paths into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21337
diff
changeset
|
1097 |
21504
888a5dfe1569
run-tests: pass temp dir into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21502
diff
changeset
|
1098 tmpdir is the main temporary directory to use for this test. |
21505
3a1881dbf860
run-tests: pass abort into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21504
diff
changeset
|
1099 |
21509
d21d53ee0d7a
run-tests: factor options.keep_tmpdir into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21508
diff
changeset
|
1100 keeptmpdir determines whether to keep the test's temporary directory |
d21d53ee0d7a
run-tests: factor options.keep_tmpdir into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21508
diff
changeset
|
1101 after execution. It defaults to removal (False). |
21510
97127c4ce460
run-tests: move debug into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21509
diff
changeset
|
1102 |
97127c4ce460
run-tests: move debug into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21509
diff
changeset
|
1103 debug mode will make the test execute verbosely, with unfiltered |
97127c4ce460
run-tests: move debug into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21509
diff
changeset
|
1104 output. |
21511
3ec3e81a4110
run-tests: move diff options into arguments of Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21510
diff
changeset
|
1105 |
21513
acfd19f3e79c
run-tests: move timeout into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21512
diff
changeset
|
1106 timeout controls the maximum run time of the test. It is ignored when |
27141
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
1107 debug is True. See slowtimeout for tests with #require slow. |
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
1108 |
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
1109 slowtimeout overrides timeout if the test has #require slow. |
21514
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1110 |
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1111 startport controls the starting port number to use for this test. Each |
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1112 test will reserve 3 port numbers for execution. It is the caller's |
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1113 responsibility to allocate a non-overlapping port range to Test |
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1114 instances. |
21515
9978ff48b1e8
run-tests: move extra config options to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21514
diff
changeset
|
1115 |
9978ff48b1e8
run-tests: move extra config options to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21514
diff
changeset
|
1116 extraconfigopts is an iterable of extra hgrc config options. Values |
9978ff48b1e8
run-tests: move extra config options to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21514
diff
changeset
|
1117 must have the form "key=value" (something understood by hgrc). Values |
9978ff48b1e8
run-tests: move extra config options to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21514
diff
changeset
|
1118 of the form "foo.key=value" will result in "[foo] key=value". |
21516
1e275c09242e
run-tests: move py3kwarnings to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21515
diff
changeset
|
1119 |
21517
af7d3a5c330b
run-tests: move shell to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21516
diff
changeset
|
1120 shell is the shell to execute tests in. |
21502
f8515564d617
run-tests: pass a full test path into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21501
diff
changeset
|
1121 """ |
34264
8999851a503f
tests: fix run-tests default values in Test constructor
Augie Fackler <augie@google.com>
parents:
34263
diff
changeset
|
1122 if timeout is None: |
8999851a503f
tests: fix run-tests default values in Test constructor
Augie Fackler <augie@google.com>
parents:
34263
diff
changeset
|
1123 timeout = defaults['timeout'] |
8999851a503f
tests: fix run-tests default values in Test constructor
Augie Fackler <augie@google.com>
parents:
34263
diff
changeset
|
1124 if startport is None: |
8999851a503f
tests: fix run-tests default values in Test constructor
Augie Fackler <augie@google.com>
parents:
34263
diff
changeset
|
1125 startport = defaults['port'] |
8999851a503f
tests: fix run-tests default values in Test constructor
Augie Fackler <augie@google.com>
parents:
34263
diff
changeset
|
1126 if slowtimeout is None: |
8999851a503f
tests: fix run-tests default values in Test constructor
Augie Fackler <augie@google.com>
parents:
34263
diff
changeset
|
1127 slowtimeout = defaults['slowtimeout'] |
25039
8505eb1bafb1
run-tests: be more judicious about bytes vs string on test attrs
Augie Fackler <augie@google.com>
parents:
25038
diff
changeset
|
1128 self.path = path |
45513
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
1129 self.relpath = os.path.relpath(path) |
25039
8505eb1bafb1
run-tests: be more judicious about bytes vs string on test attrs
Augie Fackler <augie@google.com>
parents:
25038
diff
changeset
|
1130 self.bname = os.path.basename(path) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1131 self.name = _bytes2sys(self.bname) |
21502
f8515564d617
run-tests: pass a full test path into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21501
diff
changeset
|
1132 self._testdir = os.path.dirname(path) |
32716
2146f01a2577
run-tests: allow specifying an output dir to write .errs to
Siddharth Agarwal <sid0@fb.com>
parents:
32715
diff
changeset
|
1133 self._outputdir = outputdir |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1134 self._tmpname = os.path.basename(path) |
32716
2146f01a2577
run-tests: allow specifying an output dir to write .errs to
Siddharth Agarwal <sid0@fb.com>
parents:
32715
diff
changeset
|
1135 self.errpath = os.path.join(self._outputdir, b'%s.err' % self.bname) |
21435
f376f56a354e
run-tests: rename Test._test to Test.name
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21434
diff
changeset
|
1136 |
25039
8505eb1bafb1
run-tests: be more judicious about bytes vs string on test attrs
Augie Fackler <augie@google.com>
parents:
25038
diff
changeset
|
1137 self._threadtmp = tmpdir |
21509
d21d53ee0d7a
run-tests: factor options.keep_tmpdir into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21508
diff
changeset
|
1138 self._keeptmpdir = keeptmpdir |
21510
97127c4ce460
run-tests: move debug into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21509
diff
changeset
|
1139 self._debug = debug |
35541
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1140 self._first = first |
21513
acfd19f3e79c
run-tests: move timeout into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21512
diff
changeset
|
1141 self._timeout = timeout |
27141
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
1142 self._slowtimeout = slowtimeout |
21514
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1143 self._startport = startport |
21515
9978ff48b1e8
run-tests: move extra config options to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21514
diff
changeset
|
1144 self._extraconfigopts = extraconfigopts or [] |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1145 self._shell = _sys2bytes(shell) |
28099
a5f0c0aab2bb
run-tests: allow to specify executable of any name by --with-hg
Yuya Nishihara <yuya@tcha.org>
parents:
28098
diff
changeset
|
1146 self._hgcommand = hgcommand or b'hg' |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1147 self._usechg = usechg |
44615
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
1148 self._chgdebug = chgdebug |
31003
225f574e0645
runtests: export HGIPV6 to hint test scripts whether to use IPv6
Jun Wu <quark@fb.com>
parents:
31002
diff
changeset
|
1149 self._useipv6 = useipv6 |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1150 |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1151 self._aborted = False |
21319
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
1152 self._daemonpids = [] |
21447
f8c5b8a288c5
run-tests: keep track of test execution state in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21446
diff
changeset
|
1153 self._finished = None |
21449
aedf18bcde11
run-tests: store test return code and output in Test instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21448
diff
changeset
|
1154 self._ret = None |
aedf18bcde11
run-tests: store test return code and output in Test instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21448
diff
changeset
|
1155 self._out = None |
21453
aaf52b78327e
run-tests: store skipped state on Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21452
diff
changeset
|
1156 self._skipped = None |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1157 self._testtmp = None |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1158 self._chgsockdir = None |
21447
f8c5b8a288c5
run-tests: keep track of test execution state in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21446
diff
changeset
|
1159 |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1160 self._refout = self.readrefout() |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1161 |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1162 def readrefout(self): |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1163 """read reference output""" |
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
1164 # 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
|
1165 # check test output against it. |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1166 if self._debug: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1167 return None # to match "out is None" |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1168 elif os.path.exists(self.refpath): |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1169 with open(self.refpath, 'rb') as f: |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1170 return f.read().splitlines(True) |
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
1171 else: |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
1172 return [] |
21318
6b3d66e4d3be
run-tests: capture reference output in Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21317
diff
changeset
|
1173 |
24965
cecbe207cebd
run-tests: implement Test._testMethodName
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24926
diff
changeset
|
1174 # needed to get base class __repr__ running |
cecbe207cebd
run-tests: implement Test._testMethodName
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24926
diff
changeset
|
1175 @property |
cecbe207cebd
run-tests: implement Test._testMethodName
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24926
diff
changeset
|
1176 def _testMethodName(self): |
cecbe207cebd
run-tests: implement Test._testMethodName
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24926
diff
changeset
|
1177 return self.name |
cecbe207cebd
run-tests: implement Test._testMethodName
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24926
diff
changeset
|
1178 |
21463
c908ff887589
run-tests: implement Test.__str__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21462
diff
changeset
|
1179 def __str__(self): |
c908ff887589
run-tests: implement Test.__str__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21462
diff
changeset
|
1180 return self.name |
c908ff887589
run-tests: implement Test.__str__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21462
diff
changeset
|
1181 |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1182 def shortDescription(self): |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1183 return self.name |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1184 |
21446
9a3b4f795f62
run-tests: support setUp() and tearDown() in TestCase wrapper
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21445
diff
changeset
|
1185 def setUp(self): |
9a3b4f795f62
run-tests: support setUp() and tearDown() in TestCase wrapper
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21445
diff
changeset
|
1186 """Tasks to perform before run().""" |
21447
f8c5b8a288c5
run-tests: keep track of test execution state in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21446
diff
changeset
|
1187 self._finished = False |
21449
aedf18bcde11
run-tests: store test return code and output in Test instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21448
diff
changeset
|
1188 self._ret = None |
aedf18bcde11
run-tests: store test return code and output in Test instance
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21448
diff
changeset
|
1189 self._out = None |
21453
aaf52b78327e
run-tests: store skipped state on Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21452
diff
changeset
|
1190 self._skipped = None |
21446
9a3b4f795f62
run-tests: support setUp() and tearDown() in TestCase wrapper
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21445
diff
changeset
|
1191 |
21497
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1192 try: |
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1193 os.mkdir(self._threadtmp) |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
1194 except FileExistsError: |
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
1195 pass |
21497
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1196 |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1197 name = self._tmpname |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1198 self._testtmp = os.path.join(self._threadtmp, name) |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1199 os.mkdir(self._testtmp) |
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1200 |
21457
12dd94e32102
run-tests: move errpath deletion to setUp()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21456
diff
changeset
|
1201 # Remove any previous output files. |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
1202 if os.path.exists(self.errpath): |
24332
9612b96730d7
run-tests: ignore ENOENT failures when removing old .err results
Augie Fackler <augie@google.com>
parents:
24331
diff
changeset
|
1203 try: |
9612b96730d7
run-tests: ignore ENOENT failures when removing old .err results
Augie Fackler <augie@google.com>
parents:
24331
diff
changeset
|
1204 os.remove(self.errpath) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
1205 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
1206 # We might have raced another test to clean up a .err file, |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
1207 # so ignore FileNotFoundError when removing a previous .err |
24332
9612b96730d7
run-tests: ignore ENOENT failures when removing old .err results
Augie Fackler <augie@google.com>
parents:
24331
diff
changeset
|
1208 # file. |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
1209 pass |
21457
12dd94e32102
run-tests: move errpath deletion to setUp()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21456
diff
changeset
|
1210 |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1211 if self._usechg: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1212 self._chgsockdir = os.path.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1213 self._threadtmp, b'%s.chgsock' % name |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1214 ) |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1215 os.mkdir(self._chgsockdir) |
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1216 |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1217 def run(self, result): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1218 """Run this test and report results against a TestResult instance.""" |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1219 # This function is extremely similar to unittest.TestCase.run(). Once |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1220 # we require Python 2.7 (or at least its version of unittest), this |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1221 # function can largely go away. |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1222 self._result = result |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1223 result.startTest(self) |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1224 try: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1225 try: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1226 self.setUp() |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1227 except (KeyboardInterrupt, SystemExit): |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1228 self._aborted = True |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1229 raise |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1230 except Exception: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1231 result.addError(self, sys.exc_info()) |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1232 return |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1233 |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1234 success = False |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1235 try: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1236 self.runTest() |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1237 except KeyboardInterrupt: |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1238 self._aborted = True |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1239 raise |
32932
240183a04429
tests: use unittest.SkipTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32907
diff
changeset
|
1240 except unittest.SkipTest as e: |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1241 result.addSkip(self, str(e)) |
21997
93c3b3f55d59
run-tests: fix test result counts with --keyword specified or skips occurring
Augie Fackler <raf@durin42.com>
parents:
21993
diff
changeset
|
1242 # The base class will have already counted this as a |
93c3b3f55d59
run-tests: fix test result counts with --keyword specified or skips occurring
Augie Fackler <raf@durin42.com>
parents:
21993
diff
changeset
|
1243 # test we "ran", but we want to exclude skipped tests |
93c3b3f55d59
run-tests: fix test result counts with --keyword specified or skips occurring
Augie Fackler <raf@durin42.com>
parents:
21993
diff
changeset
|
1244 # from those we count towards those run. |
93c3b3f55d59
run-tests: fix test result counts with --keyword specified or skips occurring
Augie Fackler <raf@durin42.com>
parents:
21993
diff
changeset
|
1245 result.testsRun -= 1 |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
1246 except self.failureException as e: |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1247 # This differs from unittest in that we don't capture |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1248 # the stack trace. This is for historical reasons and |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23077
diff
changeset
|
1249 # this decision could be revisited in the future, |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1250 # especially for PythonTest instances. |
21753
b7baef94a333
run-tests: checks behaviour of test on failure while testing
anuraggoel <anurag.dsps@gmail.com>
parents:
21740
diff
changeset
|
1251 if result.addFailure(self, str(e)): |
b7baef94a333
run-tests: checks behaviour of test on failure while testing
anuraggoel <anurag.dsps@gmail.com>
parents:
21740
diff
changeset
|
1252 success = True |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1253 except Exception: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1254 result.addError(self, sys.exc_info()) |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1255 else: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1256 success = True |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1257 |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1258 try: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1259 self.tearDown() |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1260 except (KeyboardInterrupt, SystemExit): |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1261 self._aborted = True |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1262 raise |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1263 except Exception: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1264 result.addError(self, sys.exc_info()) |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1265 success = False |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1266 |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1267 if success: |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1268 result.addSuccess(self) |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1269 finally: |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1270 result.stopTest(self, interrupted=self._aborted) |
21488
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1271 |
feb8ad2d57ee
run-tests: merge MercurialTest into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21464
diff
changeset
|
1272 def runTest(self): |
21383
772ed56e2519
run-tests: add some docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21382
diff
changeset
|
1273 """Run this test instance. |
772ed56e2519
run-tests: add some docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21382
diff
changeset
|
1274 |
772ed56e2519
run-tests: add some docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21382
diff
changeset
|
1275 This will return a tuple describing the result of the test. |
772ed56e2519
run-tests: add some docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21382
diff
changeset
|
1276 """ |
21514
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1277 env = self._getenv() |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1278 self._genrestoreenv(env) |
21319
44c96e2bab20
run-tests: kill daemons during Test.cleanup()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21318
diff
changeset
|
1279 self._daemonpids.append(env['DAEMON_PIDS']) |
21382
4b8ffe3abdd2
run-tests: move createhgrc into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21381
diff
changeset
|
1280 self._createhgrc(env['HGRCPATH']) |
21300
a2774731a51a
run-tests: move createhgrc() call into Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21299
diff
changeset
|
1281 |
21435
f376f56a354e
run-tests: rename Test._test to Test.name
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21434
diff
changeset
|
1282 vlog('# Test', self.name) |
21337
79930515604f
run-tests: move logging of test start into Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21336
diff
changeset
|
1283 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1284 ret, out = self._run(env) |
21500
130cc0d7bfde
run-tests: don't trap exceptions in Test.runTest()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21499
diff
changeset
|
1285 self._finished = True |
130cc0d7bfde
run-tests: don't trap exceptions in Test.runTest()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21499
diff
changeset
|
1286 self._ret = ret |
130cc0d7bfde
run-tests: don't trap exceptions in Test.runTest()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21499
diff
changeset
|
1287 self._out = out |
21305
d7a7825ff2cf
run-tests: capture execution results in a TestResult class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21304
diff
changeset
|
1288 |
21326
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1289 def describe(ret): |
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1290 if ret < 0: |
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1291 return 'killed by signal: %d' % -ret |
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1292 return 'returned error code %d' % ret |
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1293 |
21453
aaf52b78327e
run-tests: store skipped state on Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21452
diff
changeset
|
1294 self._skipped = False |
21336
45ab0668d1b2
run-tests: remove remaining uses of TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21335
diff
changeset
|
1295 |
21380
de6ea36ca9f7
run-tests: move SKIPPED_STATUS into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21379
diff
changeset
|
1296 if ret == self.SKIPPED_STATUS: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1297 if out is None: # Debug mode, nothing to parse. |
21324
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1298 missing = ['unknown'] |
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1299 failed = None |
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1300 else: |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
1301 missing, failed = TTest.parsehghaveoutput(out) |
21324
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1302 |
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1303 if not missing: |
22292
102f0e926668
run-tests: report skipped tests as "skipped" - they might still be "relevant"
Mads Kiilerich <madski@unity3d.com>
parents:
22165
diff
changeset
|
1304 missing = ['skipped'] |
21324
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1305 |
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1306 if failed: |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
1307 self.fail('hg have failed checking for %s' % failed[-1]) |
21324
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1308 else: |
21453
aaf52b78327e
run-tests: store skipped state on Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21452
diff
changeset
|
1309 self._skipped = True |
32932
240183a04429
tests: use unittest.SkipTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32907
diff
changeset
|
1310 raise unittest.SkipTest(missing[-1]) |
21325
0e66eb57e42a
run-tests: generate timeout result in Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21324
diff
changeset
|
1311 elif ret == 'timeout': |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
1312 self.fail('timed out') |
21522
eeaec308ad5f
run-tests: raise WarnTest outside of Test.fail()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21521
diff
changeset
|
1313 elif ret is False: |
32934
6123a5267119
tests: remove WarnTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32933
diff
changeset
|
1314 self.fail('no result code from test') |
21326
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1315 elif out != self._refout: |
21614
609a642dff61
run-tests: write .err files earlier
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21613
diff
changeset
|
1316 # Diff generation may rely on written .err file. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1317 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1318 (ret != 0 or out != self._refout) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1319 and not self._skipped |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1320 and not self._debug |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1321 ): |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1322 with open(self.errpath, 'wb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1323 for line in out: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1324 f.write(line) |
21614
609a642dff61
run-tests: write .err files earlier
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21613
diff
changeset
|
1325 |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1326 # The result object handles diff calculation for us. |
35541
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1327 with firstlock: |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1328 if self._result.addOutputMismatch(self, ret, out, self._refout): |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1329 # change was accepted, skip failing |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1330 return |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1331 if self._first: |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1332 global firsterror |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
1333 firsterror = True |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1334 |
21326
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1335 if ret: |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1336 msg = 'output changed and ' + describe(ret) |
21326
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1337 else: |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1338 msg = 'output changed' |
21326
04e04766065f
run-tests: move output difference processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21325
diff
changeset
|
1339 |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
1340 self.fail(msg) |
21327
206814c9072a
run-tests: move remaining result processing to Test.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21326
diff
changeset
|
1341 elif ret: |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
1342 self.fail(describe(ret)) |
21324
6454ddaee991
run-tests: add skip processing to Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21323
diff
changeset
|
1343 |
21446
9a3b4f795f62
run-tests: support setUp() and tearDown() in TestCase wrapper
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21445
diff
changeset
|
1344 def tearDown(self): |
9a3b4f795f62
run-tests: support setUp() and tearDown() in TestCase wrapper
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21445
diff
changeset
|
1345 """Tasks to perform after run().""" |
21456
a06a4142ad1f
run-tests: kill daemons during tearDown()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21455
diff
changeset
|
1346 for entry in self._daemonpids: |
a06a4142ad1f
run-tests: kill daemons during tearDown()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21455
diff
changeset
|
1347 killdaemons(entry) |
a06a4142ad1f
run-tests: kill daemons during tearDown()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21455
diff
changeset
|
1348 self._daemonpids = [] |
a06a4142ad1f
run-tests: kill daemons during tearDown()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21455
diff
changeset
|
1349 |
26422
41436beaf463
run-tests: report paths saved by --keep-tmpdir
timeless@mozdev.org
parents:
26158
diff
changeset
|
1350 if self._keeptmpdir: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1351 log( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1352 '\nKeeping testtmp dir: %s\nKeeping threadtmp dir: %s' |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
1353 % ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
1354 _bytes2sys(self._testtmp), |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
1355 _bytes2sys(self._threadtmp), |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
1356 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1357 ) |
26422
41436beaf463
run-tests: report paths saved by --keep-tmpdir
timeless@mozdev.org
parents:
26158
diff
changeset
|
1358 else: |
40987
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1359 try: |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1360 shutil.rmtree(self._testtmp) |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1361 except OSError: |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1362 # unreadable directory may be left in $TESTTMP; fix permission |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1363 # and try again |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1364 makecleanable(self._testtmp) |
bb5d74a35477
run-tests: fix permission to clean up unreadable directories
Yuya Nishihara <yuya@tcha.org>
parents:
40270
diff
changeset
|
1365 shutil.rmtree(self._testtmp, True) |
21497
798c81e32b5e
run-tests: refactor temporary directories in Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21496
diff
changeset
|
1366 shutil.rmtree(self._threadtmp, True) |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1367 |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1368 if self._usechg: |
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1369 # chgservers will stop automatically after they find the socket |
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1370 # files are deleted |
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1371 shutil.rmtree(self._chgsockdir, True) |
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1372 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1373 if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1374 (self._ret != 0 or self._out != self._refout) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1375 and not self._skipped |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1376 and not self._debug |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1377 and self._out |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1378 ): |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1379 with open(self.errpath, 'wb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1380 for line in self._out: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1381 f.write(line) |
21455
0f0bace82149
run-tests: move err file writing to tearDown()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21454
diff
changeset
|
1382 |
24926
3fe1e07f1a32
run-test: include test name in the return vlog
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24811
diff
changeset
|
1383 vlog("# Ret was:", self._ret, '(%s)' % self.name) |
21452
1517c0461b75
run-tests: move some functionality to Test.tearDown()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21451
diff
changeset
|
1384 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1385 def _run(self, env): |
21339
de25e968b4d8
run-tests: refactor runone() into gettest() and scheduletests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21338
diff
changeset
|
1386 # This should be implemented in child classes to run tests. |
32932
240183a04429
tests: use unittest.SkipTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32907
diff
changeset
|
1387 raise unittest.SkipTest('unknown test type') |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1388 |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1389 def abort(self): |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1390 """Terminate execution of this test.""" |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1391 self._aborted = True |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1392 |
28169
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1393 def _portmap(self, i): |
28284
0fe00bdb2f4f
run-tests: fix Python 3 incompatibilities
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28180
diff
changeset
|
1394 offset = b'' if i == 0 else b'%d' % i |
28169
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1395 return (br':%d\b' % (self._startport + i), b':$HGPORT%s' % offset) |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1396 |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1397 def _getreplacements(self): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1398 """Obtain a mapping of text replacements to apply to test output. |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1399 |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1400 Test output needs to be normalized so it can be compared to expected |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1401 output. This function defines how some of that normalization will |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1402 occur. |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1403 """ |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
1404 r = [ |
28169
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1405 # This list should be parallel to defineport in _getenv |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1406 self._portmap(0), |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1407 self._portmap(1), |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1408 self._portmap(2), |
52288
7f8d0c2c3692
run-tests: add a 4th `HGPORT` value
Matt Harbison <matt_harbison@yahoo.com>
parents:
52232
diff
changeset
|
1409 self._portmap(3), |
31008 | 1410 (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'), |
31741
728d37353e1e
run-tests: auto-replace 'TXNID' output
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31673
diff
changeset
|
1411 (br'\bHG_TXNID=TXN:[a-f0-9]{40}\b', br'HG_TXNID=TXN:$ID$'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1412 ] |
28055
92e8e3f20a6f
run-tests: factor out _escapepath
timeless <timeless@mozdev.org>
parents:
28037
diff
changeset
|
1413 r.append((self._escapepath(self._testtmp), b'$TESTTMP')) |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
1414 if WINDOWS: |
47571
e9c5c368be17
run-tests: also catch double-escapes for $TESTTMP
Raphaël Gomès <rgomes@octobus.net>
parents:
47500
diff
changeset
|
1415 # JSON output escapes backslashes in Windows paths, so also catch a |
e9c5c368be17
run-tests: also catch double-escapes for $TESTTMP
Raphaël Gomès <rgomes@octobus.net>
parents:
47500
diff
changeset
|
1416 # double-escape. |
e9c5c368be17
run-tests: also catch double-escapes for $TESTTMP
Raphaël Gomès <rgomes@octobus.net>
parents:
47500
diff
changeset
|
1417 replaced = self._testtmp.replace(b'\\', br'\\') |
e9c5c368be17
run-tests: also catch double-escapes for $TESTTMP
Raphaël Gomès <rgomes@octobus.net>
parents:
47500
diff
changeset
|
1418 r.append((self._escapepath(replaced), b'$STR_REPR_TESTTMP')) |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
1419 |
35194
779c6cf2967b
run-tests: avoid calculating _testdir again
Martin von Zweigbergk <martinvonz@google.com>
parents:
35193
diff
changeset
|
1420 replacementfile = os.path.join(self._testdir, b'common-pattern.py') |
35069
4fb489a998c9
run-tests: allow to register any arbitrary pattern for replacement
Boris Feld <boris.feld@octobus.net>
parents:
35066
diff
changeset
|
1421 |
4fb489a998c9
run-tests: allow to register any arbitrary pattern for replacement
Boris Feld <boris.feld@octobus.net>
parents:
35066
diff
changeset
|
1422 if os.path.exists(replacementfile): |
4fb489a998c9
run-tests: allow to register any arbitrary pattern for replacement
Boris Feld <boris.feld@octobus.net>
parents:
35066
diff
changeset
|
1423 data = {} |
35092
1ac4c0887de4
run-test: drop 'execfile' usage for 'common-pattern.py' file
Boris Feld <boris.feld@octobus.net>
parents:
35091
diff
changeset
|
1424 with open(replacementfile, mode='rb') as source: |
1ac4c0887de4
run-test: drop 'execfile' usage for 'common-pattern.py' file
Boris Feld <boris.feld@octobus.net>
parents:
35091
diff
changeset
|
1425 # the intermediate 'compile' step help with debugging |
1ac4c0887de4
run-test: drop 'execfile' usage for 'common-pattern.py' file
Boris Feld <boris.feld@octobus.net>
parents:
35091
diff
changeset
|
1426 code = compile(source.read(), replacementfile, 'exec') |
1ac4c0887de4
run-test: drop 'execfile' usage for 'common-pattern.py' file
Boris Feld <boris.feld@octobus.net>
parents:
35091
diff
changeset
|
1427 exec(code, data) |
35991
04304b779df1
tests: raise a better error when patterns are wrongly formatted
Boris Feld <boris.feld@octobus.net>
parents:
35855
diff
changeset
|
1428 for value in data.get('substitutions', ()): |
04304b779df1
tests: raise a better error when patterns are wrongly formatted
Boris Feld <boris.feld@octobus.net>
parents:
35855
diff
changeset
|
1429 if len(value) != 2: |
04304b779df1
tests: raise a better error when patterns are wrongly formatted
Boris Feld <boris.feld@octobus.net>
parents:
35855
diff
changeset
|
1430 msg = 'malformatted substitution in %s: %r' |
04304b779df1
tests: raise a better error when patterns are wrongly formatted
Boris Feld <boris.feld@octobus.net>
parents:
35855
diff
changeset
|
1431 msg %= (replacementfile, value) |
04304b779df1
tests: raise a better error when patterns are wrongly formatted
Boris Feld <boris.feld@octobus.net>
parents:
35855
diff
changeset
|
1432 raise ValueError(msg) |
04304b779df1
tests: raise a better error when patterns are wrongly formatted
Boris Feld <boris.feld@octobus.net>
parents:
35855
diff
changeset
|
1433 r.append(value) |
28055
92e8e3f20a6f
run-tests: factor out _escapepath
timeless <timeless@mozdev.org>
parents:
28037
diff
changeset
|
1434 return r |
92e8e3f20a6f
run-tests: factor out _escapepath
timeless <timeless@mozdev.org>
parents:
28037
diff
changeset
|
1435 |
92e8e3f20a6f
run-tests: factor out _escapepath
timeless <timeless@mozdev.org>
parents:
28037
diff
changeset
|
1436 def _escapepath(self, p): |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
1437 if WINDOWS: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1438 return b''.join( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1439 c.isalpha() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1440 and b'[%s%s]' % (c.lower(), c.upper()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1441 or c in b'/\\' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1442 and br'[/\\]' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1443 or c.isdigit() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1444 and c |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1445 or b'\\' + c |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1446 for c in [p[i : i + 1] for i in range(len(p))] |
28055
92e8e3f20a6f
run-tests: factor out _escapepath
timeless <timeless@mozdev.org>
parents:
28037
diff
changeset
|
1447 ) |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
1448 else: |
28055
92e8e3f20a6f
run-tests: factor out _escapepath
timeless <timeless@mozdev.org>
parents:
28037
diff
changeset
|
1449 return re.escape(p) |
21298
ba4750352180
run-tests: move replacements generation into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21297
diff
changeset
|
1450 |
31006 | 1451 def _localip(self): |
1452 if self._useipv6: | |
1453 return b'::1' | |
1454 else: | |
1455 return b'127.0.0.1' | |
1456 | |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1457 def _genrestoreenv(self, testenv): |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1458 """Generate a script that can be used by tests to restore the original |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1459 environment.""" |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1460 # Put the restoreenv script inside self._threadtmp |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1461 scriptpath = os.path.join(self._threadtmp, b'restoreenv.sh') |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1462 testenv['HGTEST_RESTOREENV'] = _bytes2sys(scriptpath) |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1463 |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1464 # Only restore environment variable names that the shell allows |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1465 # us to export. |
33140
f458a6701983
tests: fix variable name regular expression in _genrestoreenv()
Adam Simpkins <simpkins@fb.com>
parents:
33126
diff
changeset
|
1466 name_regex = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$') |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1467 |
33203
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1468 # Do not restore these variables; otherwise tests would fail. |
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1469 reqnames = {'PYTHON', 'TESTDIR', 'TESTTMP'} |
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1470 |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1471 with open(scriptpath, 'w') as envf: |
33203
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1472 for name, value in origenviron.items(): |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1473 if not name_regex.match(name): |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1474 # Skip environment variables with unusual names not |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1475 # allowed by most shells. |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1476 continue |
33203
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1477 if name in reqnames: |
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1478 continue |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1479 envf.write('%s=%s\n' % (name, shellquote(value))) |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1480 |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1481 for name in testenv: |
33203
cf826b9e9ea4
tests: actually restore the original environment before running syshg
Yuya Nishihara <yuya@tcha.org>
parents:
33140
diff
changeset
|
1482 if name in origenviron or name in reqnames: |
33126
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1483 continue |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1484 envf.write('unset %s\n' % (name,)) |
98e2c78e309c
tests: more completely restore the environment in syshgenv
Adam Simpkins <simpkins@fb.com>
parents:
33115
diff
changeset
|
1485 |
21514
59fe123dbb00
run-tests: refactor port number declaration
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21513
diff
changeset
|
1486 def _getenv(self): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1487 """Obtain environment variables to use during test execution.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1488 |
28169
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1489 def defineport(i): |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1490 offset = '' if i == 0 else '%s' % i |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1491 env["HGPORT%s" % offset] = '%s' % (self._startport + i) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1492 |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1493 env = os.environ.copy() |
49234
9dad328434c7
tests: work around non-thread-safeness of sysconfig.get_config_var()
Manuel Jacob <me@manueljacob.de>
parents:
49215
diff
changeset
|
1494 with sysconfiglock: |
9dad328434c7
tests: work around non-thread-safeness of sysconfig.get_config_var()
Manuel Jacob <me@manueljacob.de>
parents:
49215
diff
changeset
|
1495 env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or '' |
31950
cc70c6dbac30
util: add a way to issue deprecation warning without a UI object
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31829
diff
changeset
|
1496 env['HGEMITWARNINGS'] = '1' |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1497 env['TESTTMP'] = _bytes2sys(self._testtmp) |
49047
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
1498 # the FORWARD_SLASH version is useful when running `sh` on non unix |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
1499 # system (e.g. Windows) |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
1500 env['TESTTMP_FORWARD_SLASH'] = env['TESTTMP'].replace(os.sep, '/') |
47312
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47310
diff
changeset
|
1501 uid_file = os.path.join(_bytes2sys(self._testtmp), 'UID') |
7ea39d633cf3
docket: move the uid logic in the `revlogutils.docket` module
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47310
diff
changeset
|
1502 env['HGTEST_UUIDFILE'] = uid_file |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
1503 env['TESTNAME'] = self.name |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1504 env['HOME'] = _bytes2sys(self._testtmp) |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
1505 if WINDOWS: |
46870
41d43d12c2c4
tests: restore the ability to run `black` on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
46819
diff
changeset
|
1506 env['REALUSERPROFILE'] = env['USERPROFILE'] |
46092
08fd76a553c9
run-tests: configure the environment to expand `~` properly with Windows py38+
Matt Harbison <matt_harbison@yahoo.com>
parents:
46091
diff
changeset
|
1507 # py3.8+ ignores HOME: https://bugs.python.org/issue36264 |
08fd76a553c9
run-tests: configure the environment to expand `~` properly with Windows py38+
Matt Harbison <matt_harbison@yahoo.com>
parents:
46091
diff
changeset
|
1508 env['USERPROFILE'] = env['HOME'] |
44632
82543879b48e
testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44615
diff
changeset
|
1509 formated_timeout = _bytes2sys(b"%d" % default_defaults['timeout'][1]) |
82543879b48e
testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44615
diff
changeset
|
1510 env['HGTEST_TIMEOUT_DEFAULT'] = formated_timeout |
82543879b48e
testlib: adjust wait-on-file timeout according to the global test timeout
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44615
diff
changeset
|
1511 env['HGTEST_TIMEOUT'] = _bytes2sys(b"%d" % self._timeout) |
28169
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1512 # This number should match portneeded in _getport |
52288
7f8d0c2c3692
run-tests: add a 4th `HGPORT` value
Matt Harbison <matt_harbison@yahoo.com>
parents:
52232
diff
changeset
|
1513 for port in range(4): |
28169
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1514 # This list should be parallel to _portmap in _getreplacements |
1b07331f5900
run-tests: refactor port allocation into functions
timeless <timeless@mozdev.org>
parents:
28143
diff
changeset
|
1515 defineport(port) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1516 env["HGRCPATH"] = _bytes2sys(os.path.join(self._threadtmp, b'.hgrc')) |
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1517 env["DAEMON_PIDS"] = _bytes2sys( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1518 os.path.join(self._threadtmp, b'daemon.pids') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1519 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1520 env["HGEDITOR"] = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1521 '"' + sysexecutable + '"' + ' -c "import sys; sys.exit(0)"' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1522 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1523 env["HGUSER"] = "test" |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1524 env["HGENCODING"] = "ascii" |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1525 env["HGENCODINGMODE"] = "strict" |
39119
1f987f7c832b
tests: force a stable hostname in patchbomb tests
Augie Fackler <raf@durin42.com>
parents:
38934
diff
changeset
|
1526 env["HGHOSTNAME"] = "test-hostname" |
31003
225f574e0645
runtests: export HGIPV6 to hint test scripts whether to use IPv6
Jun Wu <quark@fb.com>
parents:
31002
diff
changeset
|
1527 env['HGIPV6'] = str(int(self._useipv6)) |
40491
c311424ea579
catapult: add a bit more documentation on how to use catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40490
diff
changeset
|
1528 # See contrib/catapipe.py for how to use this functionality. |
40490
889424be7ad2
catapult: introduce HGTESTCATAPULTSERVERPIPE to control run-tests' tracing
Kyle Lippincott <spectral@google.com>
parents:
40489
diff
changeset
|
1529 if 'HGTESTCATAPULTSERVERPIPE' not in env: |
889424be7ad2
catapult: introduce HGTESTCATAPULTSERVERPIPE to control run-tests' tracing
Kyle Lippincott <spectral@google.com>
parents:
40489
diff
changeset
|
1530 # If we don't have HGTESTCATAPULTSERVERPIPE explicitly set, pull the |
889424be7ad2
catapult: introduce HGTESTCATAPULTSERVERPIPE to control run-tests' tracing
Kyle Lippincott <spectral@google.com>
parents:
40489
diff
changeset
|
1531 # non-test one in as a default, otherwise set to devnull |
41759
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41758
diff
changeset
|
1532 env['HGTESTCATAPULTSERVERPIPE'] = env.get( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1533 'HGCATAPULTSERVERPIPE', os.devnull |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1534 ) |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1535 |
37342
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1536 extraextensions = [] |
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1537 for opt in self._extraconfigopts: |
46091
af3a6900f893
run-tests: fix `HGTESTEXTRAEXTENSIONS` with py3
Matt Harbison <matt_harbison@yahoo.com>
parents:
46068
diff
changeset
|
1538 section, key = opt.split('.', 1) |
37342
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1539 if section != 'extensions': |
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1540 continue |
46091
af3a6900f893
run-tests: fix `HGTESTEXTRAEXTENSIONS` with py3
Matt Harbison <matt_harbison@yahoo.com>
parents:
46068
diff
changeset
|
1541 name = key.split('=', 1)[0] |
37342
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1542 extraextensions.append(name) |
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1543 |
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1544 if extraextensions: |
46091
af3a6900f893
run-tests: fix `HGTESTEXTRAEXTENSIONS` with py3
Matt Harbison <matt_harbison@yahoo.com>
parents:
46068
diff
changeset
|
1545 env['HGTESTEXTRAEXTENSIONS'] = ' '.join(extraextensions) |
37342
4e6a6d0dccee
tests: conditionalize tests based on presence of custom extensions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
37009
diff
changeset
|
1546 |
31006 | 1547 # LOCALIP could be ::1 or 127.0.0.1. Useful for tests that require raw |
1548 # IP addresses. | |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1549 env['LOCALIP'] = _bytes2sys(self._localip()) |
31006 | 1550 |
40981
08f5482a6755
py3: spawn all python instances with legacy stdio enabled on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40976
diff
changeset
|
1551 # This has the same effect as Py_LegacyWindowsStdioFlag in exewrapper.c, |
08f5482a6755
py3: spawn all python instances with legacy stdio enabled on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40976
diff
changeset
|
1552 # but this is needed for testing python instances like dummyssh, |
08f5482a6755
py3: spawn all python instances with legacy stdio enabled on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40976
diff
changeset
|
1553 # dummysmtpd.py, and dumbhttp.py. |
48866
2ccd5e71bcd3
tests: remove last references to PYTHON3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48865
diff
changeset
|
1554 if WINDOWS: |
40981
08f5482a6755
py3: spawn all python instances with legacy stdio enabled on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40976
diff
changeset
|
1555 env['PYTHONLEGACYWINDOWSSTDIO'] = '1' |
08f5482a6755
py3: spawn all python instances with legacy stdio enabled on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40976
diff
changeset
|
1556 |
43819
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1557 # Modified HOME in test environment can confuse Rust tools. So set |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1558 # CARGO_HOME and RUSTUP_HOME automatically if a Rust toolchain is |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1559 # present and these variables aren't already defined. |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1560 cargo_home_path = os.path.expanduser('~/.cargo') |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1561 rustup_home_path = os.path.expanduser('~/.rustup') |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1562 |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1563 if os.path.exists(cargo_home_path) and b'CARGO_HOME' not in osenvironb: |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1564 env['CARGO_HOME'] = cargo_home_path |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1565 if ( |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1566 os.path.exists(rustup_home_path) |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1567 and b'RUSTUP_HOME' not in osenvironb |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1568 ): |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1569 env['RUSTUP_HOME'] = rustup_home_path |
e8a3bbffdc7d
tests: add test for Rust formatting
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43801
diff
changeset
|
1570 |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1571 # 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
|
1572 # the tests produce repeatable output. |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1573 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
|
1574 env['TZ'] = 'GMT' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1575 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
|
1576 env['COLUMNS'] = '80' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1577 env['TERM'] = 'xterm' |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1578 |
40469
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1579 dropped = [ |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1580 'CDPATH', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1581 'CHGDEBUG', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1582 'EDITOR', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1583 'GREP_OPTIONS', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1584 'HG', |
40470
d6b6f1b441cf
run-tests: define the default merge tool through configuration
Boris Feld <boris.feld@octobus.net>
parents:
40469
diff
changeset
|
1585 'HGMERGE', |
40469
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1586 'HGPLAIN', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1587 'HGPLAINEXCEPT', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1588 'HGPROF', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1589 'http_proxy', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1590 'no_proxy', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1591 'NO_PROXY', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1592 'PAGER', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1593 'VISUAL', |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1594 ] |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1595 |
f8154ddaaed3
run-tests: explicitly declare the list of dropped environment variable
Boris Feld <boris.feld@octobus.net>
parents:
40270
diff
changeset
|
1596 for k in dropped: |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1597 if k in env: |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1598 del env[k] |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1599 |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1600 # unset env related to hooks |
36522
c3df20906689
tests: fix run-tests environment cleanup on Python 3
Augie Fackler <augie@google.com>
parents:
36462
diff
changeset
|
1601 for k in list(env): |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1602 if k.startswith('HG_'): |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1603 del env[k] |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1604 |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1605 if self._usechg: |
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1606 env['CHGSOCKNAME'] = os.path.join(self._chgsockdir, b'server') |
44615
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
1607 if self._chgdebug: |
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
1608 env['CHGDEBUG'] = 'true' |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
1609 |
21299
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1610 return env |
7861de61583b
run-tests: move createenv() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21298
diff
changeset
|
1611 |
21382
4b8ffe3abdd2
run-tests: move createhgrc into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21381
diff
changeset
|
1612 def _createhgrc(self, path): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
1613 """Create an hgrc file for this test.""" |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1614 with open(path, 'wb') as hgrc: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1615 hgrc.write(b'[ui]\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1616 hgrc.write(b'slash = True\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1617 hgrc.write(b'interactive = False\n') |
45826
21733e8c924f
errors: add config that lets user get more detailed exit codes
Martin von Zweigbergk <martinvonz@google.com>
parents:
45513
diff
changeset
|
1618 hgrc.write(b'detailed-exit-code = True\n') |
40470
d6b6f1b441cf
run-tests: define the default merge tool through configuration
Boris Feld <boris.feld@octobus.net>
parents:
40469
diff
changeset
|
1619 hgrc.write(b'merge = internal:merge\n') |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1620 hgrc.write(b'mergemarkers = detailed\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1621 hgrc.write(b'promptecho = True\n') |
47919
a28a7dcb9158
tests: setup dummyssh as the default ssh
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47834
diff
changeset
|
1622 dummyssh = os.path.join(self._testdir, b'dummyssh') |
a28a7dcb9158
tests: setup dummyssh as the default ssh
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents:
47834
diff
changeset
|
1623 hgrc.write(b'ssh = "%s" "%s"\n' % (PYTHON, dummyssh)) |
46015
f44b9c72f061
run-tests: allow some slack about 'waiting on lock' message
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
45955
diff
changeset
|
1624 hgrc.write(b'timeout.warn=15\n') |
47776
036b9b3cc79a
run-tests: use a small timeout for chg instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47775
diff
changeset
|
1625 hgrc.write(b'[chgserver]\n') |
036b9b3cc79a
run-tests: use a small timeout for chg instance
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47775
diff
changeset
|
1626 hgrc.write(b'idletimeout=60\n') |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1627 hgrc.write(b'[defaults]\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1628 hgrc.write(b'[devel]\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1629 hgrc.write(b'all-warnings = true\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1630 hgrc.write(b'default-date = 0 0\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1631 hgrc.write(b'[largefiles]\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1632 hgrc.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1633 b'usercache = %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1634 % (os.path.join(self._testtmp, b'.cache/largefiles')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1635 ) |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1636 hgrc.write(b'[lfs]\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1637 hgrc.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1638 b'usercache = %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1639 % (os.path.join(self._testtmp, b'.cache/lfs')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1640 ) |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1641 hgrc.write(b'[web]\n') |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1642 hgrc.write(b'address = localhost\n') |
44446
109322cd322a
tests: avoid implicit conversion of str to unicode
Manuel Jacob <me@manueljacob.de>
parents:
44144
diff
changeset
|
1643 hgrc.write(b'ipv6 = %r\n' % self._useipv6) |
37009
5890e5872f36
hgweb: allow defining Server response header for HTTP server
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36677
diff
changeset
|
1644 hgrc.write(b'server-header = testing stub value\n') |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1645 |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1646 for opt in self._extraconfigopts: |
44449
ff72bd52d56a
tests: avoid implicit conversion of str to unicode
Manuel Jacob <me@manueljacob.de>
parents:
44448
diff
changeset
|
1647 section, key = _sys2bytes(opt).split(b'.', 1) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1648 assert b'=' in key, ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1649 'extra config opt %s must ' 'have an = for assignment' % opt |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1650 ) |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1651 hgrc.write(b'[%s]\n%s\n' % (section, key)) |
21382
4b8ffe3abdd2
run-tests: move createhgrc into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21381
diff
changeset
|
1652 |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
1653 def fail(self, msg): |
21522
eeaec308ad5f
run-tests: raise WarnTest outside of Test.fail()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21521
diff
changeset
|
1654 # unittest differentiates between errored and failed. |
eeaec308ad5f
run-tests: raise WarnTest outside of Test.fail()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21521
diff
changeset
|
1655 # Failed is denoted by AssertionError (by default at least). |
eeaec308ad5f
run-tests: raise WarnTest outside of Test.fail()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21521
diff
changeset
|
1656 raise AssertionError(msg) |
21323
a7c677e2f6ae
run-tests: move fail() into Test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21322
diff
changeset
|
1657 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1658 def _runcommand(self, cmd, env, normalizenewlines=False): |
24508
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1659 """Run command in a sub-process, capturing the output (stdout and |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1660 stderr). |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1661 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1662 Return a tuple (exitcode, output). output is None in debug mode. |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1663 """ |
24509
27092bb70293
run-tests: remove arguments from Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24508
diff
changeset
|
1664 if self._debug: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1665 proc = subprocess.Popen( |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1666 _bytes2sys(cmd), |
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1667 shell=True, |
47775
c405c089611a
run-tests: do not inherit file descriptor when running a command
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47639
diff
changeset
|
1668 close_fds=closefds, |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1669 cwd=_bytes2sys(self._testtmp), |
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1670 env=env, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1671 ) |
24508
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1672 ret = proc.wait() |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1673 return (ret, None) |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1674 |
24509
27092bb70293
run-tests: remove arguments from Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24508
diff
changeset
|
1675 proc = Popen4(cmd, self._testtmp, self._timeout, env) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1676 |
24508
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1677 def cleanup(): |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1678 terminate(proc) |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1679 ret = proc.wait() |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1680 if ret == 0: |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1681 ret = signal.SIGTERM << 8 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1682 killdaemons(env['DAEMON_PIDS']) |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1683 return ret |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1684 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1685 proc.tochild.close() |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1686 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1687 try: |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1688 output = proc.fromchild.read() |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1689 except KeyboardInterrupt: |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1690 vlog('# Handling keyboard interrupt') |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1691 cleanup() |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1692 raise |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1693 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1694 ret = proc.wait() |
25177
c3459555318e
run-tests: resurrect the wifexited polyfill (backout 6ab5a1c9ea3c)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25162
diff
changeset
|
1695 if wifexited(ret): |
24508
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1696 ret = os.WEXITSTATUS(ret) |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1697 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1698 if proc.timeout: |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1699 ret = 'timeout' |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1700 |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1701 if ret: |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1702 killdaemons(env['DAEMON_PIDS']) |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1703 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1704 for s, r in self._getreplacements(): |
24508
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1705 output = re.sub(s, r, output) |
24510
8d6fd0b8f622
run-tests: separate newline normalization from replacements
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24509
diff
changeset
|
1706 |
8d6fd0b8f622
run-tests: separate newline normalization from replacements
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24509
diff
changeset
|
1707 if normalizenewlines: |
39706
030d558c6456
py3: add a missing b'' for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
39663
diff
changeset
|
1708 output = output.replace(b'\r\n', b'\n') |
24510
8d6fd0b8f622
run-tests: separate newline normalization from replacements
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24509
diff
changeset
|
1709 |
24508
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1710 return ret, output.splitlines(True) |
fbe2fb71a6e6
run-tests: move run into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24507
diff
changeset
|
1711 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1712 |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1713 class PythonTest(Test): |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1714 """A Python-based test.""" |
21501
98a0c58ee200
run-tests: factor refpath into Test classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21500
diff
changeset
|
1715 |
98a0c58ee200
run-tests: factor refpath into Test classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21500
diff
changeset
|
1716 @property |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1717 def refpath(self): |
25058
caa2043cc322
run-tests: unblock running python tests in python 3
Augie Fackler <augie@google.com>
parents:
25057
diff
changeset
|
1718 return os.path.join(self._testdir, b'%s.out' % self.bname) |
21501
98a0c58ee200
run-tests: factor refpath into Test classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21500
diff
changeset
|
1719 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1720 def _run(self, env): |
40270
8783710b1d58
run-tests: restore quoting the python executable for running *.py tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
40263
diff
changeset
|
1721 # Quote the python(3) executable for Windows |
44144
bd0de73cf810
run-tests: remove --py3-warnings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44021
diff
changeset
|
1722 cmd = b'"%s" "%s"' % (PYTHON, self.path) |
43309
b4b1131187c4
py3: decode bytes before logging in run-tests.py
Denis Laxalde <denis@laxalde.org>
parents:
43283
diff
changeset
|
1723 vlog("# Running", cmd.decode("utf-8")) |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
1724 result = self._runcommand(cmd, env, normalizenewlines=WINDOWS) |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1725 if self._aborted: |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1726 raise KeyboardInterrupt() |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1727 |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1728 return result |
21311
f9a7018a35ff
run-tests: roll pytest() into PythonTest._run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21310
diff
changeset
|
1729 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1730 |
29518
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1731 # Some glob patterns apply only in some circumstances, so the script |
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1732 # might want to remove (glob) annotations that otherwise should be |
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1733 # retained. |
23352
5bd04faaa3ee
run-tests: don't warn on unnecessary globs mandated by check-code.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
23347
diff
changeset
|
1734 checkcodeglobpats = [ |
29518
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1735 # On Windows it looks like \ doesn't require a (glob), but we know |
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1736 # better. |
25059
0e0f1068b878
run-tests: fix checking a line to see if it needs globbing
Augie Fackler <augie@google.com>
parents:
25058
diff
changeset
|
1737 re.compile(br'^pushing to \$TESTTMP/.*[^)]$'), |
0e0f1068b878
run-tests: fix checking a line to see if it needs globbing
Augie Fackler <augie@google.com>
parents:
25058
diff
changeset
|
1738 re.compile(br'^moving \S+/.*[^)]$'), |
29518
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1739 re.compile(br'^pulling from \$TESTTMP/.*[^)]$'), |
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1740 # Not all platforms have 127.0.0.1 as loopback (though most do), |
348b2b9da703
run-tests: add support for using 127.0.0.1 as a glob
Augie Fackler <raf@durin42.com>
parents:
29485
diff
changeset
|
1741 # so we always glob that too. |
31673
6a2959acae1a
runtests: change local IP glob pattern from "127.0.0.1" to "$LOCALIP"
Jun Wu <quark@fb.com>
parents:
31635
diff
changeset
|
1742 re.compile(br'.*\$LOCALIP.*$'), |
23352
5bd04faaa3ee
run-tests: don't warn on unnecessary globs mandated by check-code.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
23347
diff
changeset
|
1743 ] |
5bd04faaa3ee
run-tests: don't warn on unnecessary globs mandated by check-code.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
23347
diff
changeset
|
1744 |
48860
4cea98b32d95
tests: unconditionalize bchr
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48859
diff
changeset
|
1745 bchr = lambda x: bytes([x]) |
25036
61fc2cdbc57c
run-tests: work around chr() producing unicode in Python 3
Augie Fackler <augie@google.com>
parents:
25035
diff
changeset
|
1746 |
42866
141bb77b606b
run-tests: use symbolic constant instead of arbitrary number line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42817
diff
changeset
|
1747 WARN_UNDEFINED = 1 |
141bb77b606b
run-tests: use symbolic constant instead of arbitrary number line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42817
diff
changeset
|
1748 WARN_YES = 2 |
141bb77b606b
run-tests: use symbolic constant instead of arbitrary number line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42817
diff
changeset
|
1749 WARN_NO = 3 |
141bb77b606b
run-tests: use symbolic constant instead of arbitrary number line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42817
diff
changeset
|
1750 |
42901
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
1751 MARK_OPTIONAL = b" (?)\n" |
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
1752 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1753 |
42901
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
1754 def isoptional(line): |
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
1755 return line.endswith(MARK_OPTIONAL) |
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
1756 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1757 |
21296
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1758 class TTest(Test): |
cd8776030833
run-tests: create classes for representing tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21231
diff
changeset
|
1759 """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
|
1760 |
28284
0fe00bdb2f4f
run-tests: fix Python 3 incompatibilities
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28180
diff
changeset
|
1761 SKIPPED_PREFIX = b'skipped: ' |
0fe00bdb2f4f
run-tests: fix Python 3 incompatibilities
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28180
diff
changeset
|
1762 FAILED_PREFIX = b'hghave check failed: ' |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1763 NEEDESCAPE = re.compile(br'[\x00-\x08\x0b-\x1f\x7f-\xff]').search |
21384
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
1764 |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1765 ESCAPESUB = re.compile(br'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44449
diff
changeset
|
1766 ESCAPEMAP = {bchr(i): br'\x%02x' % i for i in range(256)} |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1767 ESCAPEMAP.update({b'\\': b'\\\\', b'\r': br'\r'}) |
21381
9aa5784992d4
run-tests: move SKIPPED_PREFIX and FAILED_PREFIX into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21380
diff
changeset
|
1768 |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1769 def __init__(self, path, *args, **kwds): |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1770 # accept an extra "case" parameter |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
1771 case = kwds.pop('case', []) |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1772 self._case = case |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
1773 self._allcases = {x for y in parsettestcases(path) for x in y} |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1774 super(TTest, self).__init__(path, *args, **kwds) |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1775 if case: |
38934
35180ade80c1
tests: fix bytes/str issues in run-tests.py caught by python3
Augie Fackler <augie@google.com>
parents:
38824
diff
changeset
|
1776 casepath = b'#'.join(case) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
1777 self.name = '%s#%s' % (self.name, _bytes2sys(casepath)) |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
1778 self.errpath = b'%s#%s.err' % (self.errpath[:-4], casepath) |
45108
a659d5a4d2d5
run-tests: replace '#' with '-' in temp path of repos created for tests
Pulkit Goyal <7895pulkit@gmail.com>
parents:
45046
diff
changeset
|
1779 self._tmpname += b'-%s' % casepath.replace(b'#', b'-') |
36462
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1780 self._have = {} |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1781 |
21501
98a0c58ee200
run-tests: factor refpath into Test classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21500
diff
changeset
|
1782 @property |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
1783 def refpath(self): |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1784 return os.path.join(self._testdir, self.bname) |
21501
98a0c58ee200
run-tests: factor refpath into Test classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21500
diff
changeset
|
1785 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1786 def _run(self, env): |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1787 with open(self.path, 'rb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1788 lines = f.readlines() |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1789 |
32981
02bca6dc5f41
run-tests: update .t reference output after reading the test
Jun Wu <quark@fb.com>
parents:
32980
diff
changeset
|
1790 # .t file is both reference output and the test input, keep reference |
02bca6dc5f41
run-tests: update .t reference output after reading the test
Jun Wu <quark@fb.com>
parents:
32980
diff
changeset
|
1791 # output updated with the the test input. This avoids some race |
02bca6dc5f41
run-tests: update .t reference output after reading the test
Jun Wu <quark@fb.com>
parents:
32980
diff
changeset
|
1792 # conditions where the reference output does not match the actual test. |
02bca6dc5f41
run-tests: update .t reference output after reading the test
Jun Wu <quark@fb.com>
parents:
32980
diff
changeset
|
1793 if self._refout is not None: |
02bca6dc5f41
run-tests: update .t reference output after reading the test
Jun Wu <quark@fb.com>
parents:
32980
diff
changeset
|
1794 self._refout = lines |
02bca6dc5f41
run-tests: update .t reference output after reading the test
Jun Wu <quark@fb.com>
parents:
32980
diff
changeset
|
1795 |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1796 salt, script, after, expected = self._parsetest(lines) |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1797 |
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1798 # Write out the generated script. |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1799 fname = b'%s.sh' % self._testtmp |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1800 with open(fname, 'wb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1801 for l in script: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
1802 f.write(l) |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1803 |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1804 cmd = b'%s "%s"' % (self._shell, fname) |
43309
b4b1131187c4
py3: decode bytes before logging in run-tests.py
Denis Laxalde <denis@laxalde.org>
parents:
43283
diff
changeset
|
1805 vlog("# Running", cmd.decode("utf-8")) |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1806 |
24516
62fb03e0d990
run-tests: obtain replacements inside Test._runcommand
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24510
diff
changeset
|
1807 exitcode, output = self._runcommand(cmd, env) |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1808 |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1809 if self._aborted: |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1810 raise KeyboardInterrupt() |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
1811 |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1812 # 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
|
1813 # Similarly, with --debug, output is None. |
21380
de6ea36ca9f7
run-tests: move SKIPPED_STATUS into Test class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21379
diff
changeset
|
1814 if exitcode == self.SKIPPED_STATUS or output is None: |
21313
a2bd02a3b6d2
run-tests: move t test execution from tsttest() to TTest.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21312
diff
changeset
|
1815 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
|
1816 |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
1817 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
|
1818 |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1819 def _hghave(self, reqs): |
36462
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1820 allreqs = b' '.join(reqs) |
41803
bc1c1435a874
runtest: move slow timeout process earlier in the `_hghave` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41802
diff
changeset
|
1821 |
bc1c1435a874
runtest: move slow timeout process earlier in the `_hghave` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41802
diff
changeset
|
1822 self._detectslow(reqs) |
bc1c1435a874
runtest: move slow timeout process earlier in the `_hghave` method
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41802
diff
changeset
|
1823 |
36462
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1824 if allreqs in self._have: |
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1825 return self._have.get(allreqs) |
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1826 |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1827 # TODO do something smarter when all other uses of hghave are gone. |
44471
fb7da4759a18
run-tests: fix conditional when tests are run outside of `tests`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44451
diff
changeset
|
1828 runtestdir = osenvironb[b'RUNTESTDIR'] |
25728
905c32321cfb
run-tests.py: execute hghave by the path relative to run-tests.py
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25388
diff
changeset
|
1829 tdir = runtestdir.replace(b'\\', b'/') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1830 proc = Popen4( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1831 b'%s -c "%s/hghave %s"' % (self._shell, tdir, allreqs), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1832 self._testtmp, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1833 0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1834 self._getenv(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1835 ) |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1836 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
|
1837 ret = proc.wait() |
25177
c3459555318e
run-tests: resurrect the wifexited polyfill (backout 6ab5a1c9ea3c)
Matt Harbison <matt_harbison@yahoo.com>
parents:
25162
diff
changeset
|
1838 if wifexited(ret): |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1839 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
|
1840 if ret == 2: |
28699
5cc59dbd199f
py3: convert hghave output to text
timeless <timeless@mozdev.org>
parents:
28698
diff
changeset
|
1841 print(stdout.decode('utf-8')) |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1842 sys.exit(1) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1843 |
27141
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
1844 if ret != 0: |
36462
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1845 self._have[allreqs] = (False, stdout) |
27564
80b53082a353
run-tests: report missing feature for skipped tests
timeless <timeless@mozdev.org>
parents:
27396
diff
changeset
|
1846 return False, stdout |
27141
a4e3dec3010e
run-tests: add --slowtimeout and use it for slow tests
timeless <timeless@mozdev.org>
parents:
27101
diff
changeset
|
1847 |
36462
5c1cea8a3e60
run-tests: cache hghave results
Matt Harbison <matt_harbison@yahoo.com>
parents:
36461
diff
changeset
|
1848 self._have[allreqs] = (True, None) |
27564
80b53082a353
run-tests: report missing feature for skipped tests
timeless <timeless@mozdev.org>
parents:
27396
diff
changeset
|
1849 return True, None |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1850 |
41802
7eb4e62d4760
runtest: extract the logic that update timeout for slow tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41801
diff
changeset
|
1851 def _detectslow(self, reqs): |
7eb4e62d4760
runtest: extract the logic that update timeout for slow tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41801
diff
changeset
|
1852 """update the timeout of slow test when appropriate""" |
7eb4e62d4760
runtest: extract the logic that update timeout for slow tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41801
diff
changeset
|
1853 if b'slow' in reqs: |
7eb4e62d4760
runtest: extract the logic that update timeout for slow tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41801
diff
changeset
|
1854 self._timeout = self._slowtimeout |
7eb4e62d4760
runtest: extract the logic that update timeout for slow tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41801
diff
changeset
|
1855 |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1856 def _iftest(self, args): |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1857 # implements "#if" |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1858 reqs = [] |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1859 for arg in args: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1860 if arg.startswith(b'no-') and arg[3:] in self._allcases: |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
1861 if arg[3:] in self._case: |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1862 return False |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1863 elif arg in self._allcases: |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
1864 if arg not in self._case: |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1865 return False |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1866 else: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1867 reqs.append(arg) |
41804
4cbccb50df46
runtest: also update slow test timeout during `#if` clauses
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41803
diff
changeset
|
1868 self._detectslow(reqs) |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1869 return self._hghave(reqs)[0] |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
1870 |
21454
046587aa1c8a
run-tests: refactor testtmp
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21453
diff
changeset
|
1871 def _parsetest(self, lines): |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1872 # 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
|
1873 # 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
|
1874 # line number and the last return code. |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1875 salt = b"SALT%d" % time.time() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1876 |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1877 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
|
1878 if inpython: |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1879 script.append(b'%s %d 0\n' % (salt, line)) |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1880 else: |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
1881 script.append(b'echo %s %d $?\n' % (salt, line)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1882 |
40489
a9e00c48c5ef
catapult: rename 'active' to 'activetrace'; this isn't storing a boolean state
Kyle Lippincott <spectral@google.com>
parents:
40488
diff
changeset
|
1883 activetrace = [] |
48861
7265e5b1d18e
tests: always encode session
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48860
diff
changeset
|
1884 session = str(uuid.uuid4()).encode('ascii') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1885 hgcatapult = os.getenv('HGTESTCATAPULTSERVERPIPE') or os.getenv( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1886 'HGCATAPULTSERVERPIPE' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1887 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1888 |
40488
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1889 def toggletrace(cmd=None): |
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1890 if not hgcatapult or hgcatapult == os.devnull: |
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1891 return |
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1892 |
40489
a9e00c48c5ef
catapult: rename 'active' to 'activetrace'; this isn't storing a boolean state
Kyle Lippincott <spectral@google.com>
parents:
40488
diff
changeset
|
1893 if activetrace: |
40488
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1894 script.append( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1895 b'echo END %s %s >> "$HGTESTCATAPULTSERVERPIPE"\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1896 % (session, activetrace[0]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1897 ) |
40488
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1898 if cmd is None: |
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1899 return |
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1900 |
39396
f57682dca1c1
tests: avoid shellquoting bytes on Python 3
Augie Fackler <augie@google.com>
parents:
39379
diff
changeset
|
1901 if isinstance(cmd, str): |
f57682dca1c1
tests: avoid shellquoting bytes on Python 3
Augie Fackler <augie@google.com>
parents:
39379
diff
changeset
|
1902 quoted = shellquote(cmd.strip()) |
f57682dca1c1
tests: avoid shellquoting bytes on Python 3
Augie Fackler <augie@google.com>
parents:
39379
diff
changeset
|
1903 else: |
f57682dca1c1
tests: avoid shellquoting bytes on Python 3
Augie Fackler <augie@google.com>
parents:
39379
diff
changeset
|
1904 quoted = shellquote(cmd.strip().decode('utf8')).encode('utf8') |
f57682dca1c1
tests: avoid shellquoting bytes on Python 3
Augie Fackler <augie@google.com>
parents:
39379
diff
changeset
|
1905 quoted = quoted.replace(b'\\', b'\\\\') |
40488
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
1906 script.append( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1907 b'echo START %s %s >> "$HGTESTCATAPULTSERVERPIPE"\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1908 % (session, quoted) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
1909 ) |
40489
a9e00c48c5ef
catapult: rename 'active' to 'activetrace'; this isn't storing a boolean state
Kyle Lippincott <spectral@google.com>
parents:
40488
diff
changeset
|
1910 activetrace[0:] = [quoted] |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1911 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1912 script = [] |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1913 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1914 # 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
|
1915 # 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
|
1916 # 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
|
1917 # 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
|
1918 after = {} |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1919 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1920 # 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
|
1921 expected = {} |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1922 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1923 pos = prepos = -1 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1924 |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1925 # The current stack of conditionnal section. |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1926 # Each relevant conditionnal section can have the following value: |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1927 # - True: we should run this block |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1928 # - False: we should skip this block |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1929 # - None: The parent block is skipped, |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1930 # (no branch of this one will ever run) |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1931 condition_stack = [] |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1932 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1933 def run_line(): |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1934 """return True if the current line should be run""" |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1935 if not condition_stack: |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1936 return True |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1937 return bool(condition_stack[-1]) |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1938 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1939 def push_conditional_block(should_run): |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1940 """Push a new conditional context, with its initial state |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1941 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1942 i.e. entry a #if block""" |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1943 if not run_line(): |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1944 condition_stack.append(None) |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1945 else: |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1946 condition_stack.append(should_run) |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1947 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1948 def flip_conditional(): |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1949 """reverse the current condition state |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1950 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1951 i.e. enter a #else |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1952 """ |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1953 assert condition_stack |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1954 if condition_stack[-1] is not None: |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1955 condition_stack[-1] = not condition_stack[-1] |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1956 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1957 def pop_conditional(): |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1958 """exit the current skipping context |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1959 |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1960 i.e. reach the #endif""" |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1961 assert condition_stack |
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
1962 condition_stack.pop() |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1963 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1964 # 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
|
1965 # 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
|
1966 inpython = False |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1967 |
21510
97127c4ce460
run-tests: move debug into an argument to Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21509
diff
changeset
|
1968 if self._debug: |
25060
29e54fe22a3f
run-tests: make sure all script lines are bytes
Augie Fackler <augie@google.com>
parents:
25059
diff
changeset
|
1969 script.append(b'set -x\n') |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
1970 if os.getenv('MSYSTEM'): |
25060
29e54fe22a3f
run-tests: make sure all script lines are bytes
Augie Fackler <augie@google.com>
parents:
25059
diff
changeset
|
1971 script.append(b'alias pwd="pwd -W"\n') |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1972 |
39379
b64d36e5ca31
run-tests: replace '/dev/null' with os.devnull for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
39289
diff
changeset
|
1973 if hgcatapult and hgcatapult != os.devnull: |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
1974 hgcatapult = hgcatapult.encode('utf8') |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
1975 cataname = self.name.encode('utf8') |
42525
9913fffd744b
py3: make catapult usable from the test runner in py3
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42523
diff
changeset
|
1976 |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1977 # Kludge: use a while loop to keep the pipe from getting |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1978 # closed by our echo commands. The still-running file gets |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1979 # reaped at the end of the script, which causes the while |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1980 # loop to exit and closes the pipe. Sigh. |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1981 script.append( |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1982 b'rtendtracing() {\n' |
40490
889424be7ad2
catapult: introduce HGTESTCATAPULTSERVERPIPE to control run-tests' tracing
Kyle Lippincott <spectral@google.com>
parents:
40489
diff
changeset
|
1983 b' echo END %(session)s %(name)s >> %(catapult)s\n' |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1984 b' rm -f "$TESTTMP/.still-running"\n' |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1985 b'}\n' |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1986 b'trap "rtendtracing" 0\n' |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1987 b'touch "$TESTTMP/.still-running"\n' |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1988 b'while [ -f "$TESTTMP/.still-running" ]; do sleep 1; done ' |
40490
889424be7ad2
catapult: introduce HGTESTCATAPULTSERVERPIPE to control run-tests' tracing
Kyle Lippincott <spectral@google.com>
parents:
40489
diff
changeset
|
1989 b'> %(catapult)s &\n' |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1990 b'HGCATAPULTSESSION=%(session)s ; export HGCATAPULTSESSION\n' |
40490
889424be7ad2
catapult: introduce HGTESTCATAPULTSERVERPIPE to control run-tests' tracing
Kyle Lippincott <spectral@google.com>
parents:
40489
diff
changeset
|
1991 b'echo START %(session)s %(name)s >> %(catapult)s\n' |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1992 % { |
42525
9913fffd744b
py3: make catapult usable from the test runner in py3
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42523
diff
changeset
|
1993 b'name': cataname, |
9913fffd744b
py3: make catapult usable from the test runner in py3
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42523
diff
changeset
|
1994 b'session': session, |
9913fffd744b
py3: make catapult usable from the test runner in py3
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
42523
diff
changeset
|
1995 b'catapult': hgcatapult, |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1996 } |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1997 ) |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
1998 |
35536
f04d16bef2c7
tests: make #testcase available as env var in test
Martin von Zweigbergk <martinvonz@google.com>
parents:
35489
diff
changeset
|
1999 if self._case: |
38934
35180ade80c1
tests: fix bytes/str issues in run-tests.py caught by python3
Augie Fackler <augie@google.com>
parents:
38824
diff
changeset
|
2000 casestr = b'#'.join(self._case) |
44451
9803b374389a
tests: fix isinstance test of wrong variable
Manuel Jacob <me@manueljacob.de>
parents:
44021
diff
changeset
|
2001 if isinstance(casestr, str): |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
2002 quoted = shellquote(casestr) |
35823
4be991331a46
tests: get run-tests to reliably hand shellquote a string and not a bytes
Augie Fackler <augie@google.com>
parents:
35751
diff
changeset
|
2003 else: |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
2004 quoted = shellquote(casestr.decode('utf8')).encode('utf8') |
35823
4be991331a46
tests: get run-tests to reliably hand shellquote a string and not a bytes
Augie Fackler <augie@google.com>
parents:
35751
diff
changeset
|
2005 script.append(b'TESTCASE=%s\n' % quoted) |
35536
f04d16bef2c7
tests: make #testcase available as env var in test
Martin von Zweigbergk <martinvonz@google.com>
parents:
35489
diff
changeset
|
2006 script.append(b'export TESTCASE\n') |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2007 |
28812
f1de5a612a74
run-tests: handle empty tests
timeless <timeless@mozdev.org>
parents:
28701
diff
changeset
|
2008 n = 0 |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2009 for n, l in enumerate(lines): |
25035
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2010 if not l.endswith(b'\n'): |
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2011 l += b'\n' |
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2012 if l.startswith(b'#require'): |
22045
769198c6a62d
run-tests: add #require to abort full test
Matt Mackall <mpm@selenic.com>
parents:
22044
diff
changeset
|
2013 lsplit = l.split() |
25035
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2014 if len(lsplit) < 2 or lsplit[0] != b'#require': |
43408
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2015 after.setdefault(pos, []).append( |
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2016 b' !!! invalid #require\n' |
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2017 ) |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2018 if run_line(): |
36677
a247a0e82e7d
run-tests: allow #require inside #if
Jun Wu <quark@fb.com>
parents:
36665
diff
changeset
|
2019 haveresult, message = self._hghave(lsplit[1:]) |
a247a0e82e7d
run-tests: allow #require inside #if
Jun Wu <quark@fb.com>
parents:
36665
diff
changeset
|
2020 if not haveresult: |
a247a0e82e7d
run-tests: allow #require inside #if
Jun Wu <quark@fb.com>
parents:
36665
diff
changeset
|
2021 script = [b'echo "%s"\nexit 80\n' % message] |
a247a0e82e7d
run-tests: allow #require inside #if
Jun Wu <quark@fb.com>
parents:
36665
diff
changeset
|
2022 break |
22045
769198c6a62d
run-tests: add #require to abort full test
Matt Mackall <mpm@selenic.com>
parents:
22044
diff
changeset
|
2023 after.setdefault(pos, []).append(l) |
25035
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2024 elif l.startswith(b'#if'): |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2025 lsplit = l.split() |
25035
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2026 if len(lsplit) < 2 or lsplit[0] != b'#if': |
43408
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2027 after.setdefault(pos, []).append(b' !!! invalid #if\n') |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2028 push_conditional_block(self._iftest(lsplit[1:])) |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2029 after.setdefault(pos, []).append(l) |
25035
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2030 elif l.startswith(b'#else'): |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2031 if not condition_stack: |
43408
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2032 after.setdefault(pos, []).append(b' !!! missing #if\n') |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2033 flip_conditional() |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2034 after.setdefault(pos, []).append(l) |
25035
1203ca7005fa
run-tests: use bytes when constructing shell script
Augie Fackler <augie@google.com>
parents:
25034
diff
changeset
|
2035 elif l.startswith(b'#endif'): |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2036 if not condition_stack: |
43408
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2037 after.setdefault(pos, []).append(b' !!! missing #if\n') |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2038 pop_conditional() |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2039 after.setdefault(pos, []).append(l) |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2040 elif not run_line(): |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2041 after.setdefault(pos, []).append(l) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2042 elif l.startswith(b' >>> '): # python inlines |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2043 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
|
2044 prepos = pos |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2045 pos = n |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2046 if not inpython: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2047 # 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
|
2048 inpython = True |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2049 addsalt(prepos, False) # Make sure we report the exit code. |
39717
7f8b7a060584
run-tests: quote PYTHON when spawning a subprocess
Matt Harbison <matt_harbison@yahoo.com>
parents:
39714
diff
changeset
|
2050 script.append(b'"%s" -m heredoctest <<EOF\n' % PYTHON) |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2051 addsalt(n, True) |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2052 script.append(l[2:]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2053 elif l.startswith(b' ... '): # python inlines |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2054 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
|
2055 script.append(l[2:]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2056 elif l.startswith(b' $ '): # commands |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2057 if inpython: |
25060
29e54fe22a3f
run-tests: make sure all script lines are bytes
Augie Fackler <augie@google.com>
parents:
25059
diff
changeset
|
2058 script.append(b'EOF\n') |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2059 inpython = False |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2060 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
|
2061 prepos = pos |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2062 pos = n |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2063 addsalt(n, False) |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
2064 rawcmd = l[4:] |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
2065 cmd = rawcmd.split() |
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
2066 toggletrace(rawcmd) |
25060
29e54fe22a3f
run-tests: make sure all script lines are bytes
Augie Fackler <augie@google.com>
parents:
25059
diff
changeset
|
2067 if len(cmd) == 2 and cmd[0] == b'cd': |
43982
bd3fa45c0662
run-tests: ensure the script exits when it fails to change directories
Matt Harbison <matt_harbison@yahoo.com>
parents:
43819
diff
changeset
|
2068 rawcmd = b'cd %s || exit 1\n' % cmd[1] |
39253
c496e8c14b9e
tests: add support for emitting trace events to run-tests
Augie Fackler <augie@google.com>
parents:
39119
diff
changeset
|
2069 script.append(rawcmd) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2070 elif l.startswith(b' > '): # continuations |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2071 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
|
2072 script.append(l[4:]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2073 elif l.startswith(b' '): # results |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2074 # 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
|
2075 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
|
2076 else: |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2077 if inpython: |
25060
29e54fe22a3f
run-tests: make sure all script lines are bytes
Augie Fackler <augie@google.com>
parents:
25059
diff
changeset
|
2078 script.append(b'EOF\n') |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2079 inpython = False |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2080 # 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
|
2081 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
|
2082 |
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2083 if inpython: |
25060
29e54fe22a3f
run-tests: make sure all script lines are bytes
Augie Fackler <augie@google.com>
parents:
25059
diff
changeset
|
2084 script.append(b'EOF\n') |
50210
6515d9a6592d
run-tests: make it possible to nest conditionals
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49833
diff
changeset
|
2085 if condition_stack: |
43408
d9e7ac50b80a
run-tests: use byte strings for inserted output
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43346
diff
changeset
|
2086 after.setdefault(pos, []).append(b' !!! missing #endif\n') |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2087 addsalt(n + 1, False) |
40488
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
2088 # Need to end any current per-command trace |
40489
a9e00c48c5ef
catapult: rename 'active' to 'activetrace'; this isn't storing a boolean state
Kyle Lippincott <spectral@google.com>
parents:
40488
diff
changeset
|
2089 if activetrace: |
40488
d95358143ce6
catapult: fix broken run-tests catapult tracing
Kyle Lippincott <spectral@google.com>
parents:
40487
diff
changeset
|
2090 toggletrace() |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2091 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
|
2092 |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2093 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
|
2094 # Merge the script output back into a unified test. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2095 warnonly = WARN_UNDEFINED # 1: not yet; 2: yes; 3: for sure not |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2096 if exitcode != 0: |
42866
141bb77b606b
run-tests: use symbolic constant instead of arbitrary number line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42817
diff
changeset
|
2097 warnonly = WARN_NO |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2098 |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2099 pos = -1 |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2100 postout = [] |
42867
eab66266180e
run-tests: clarify "l" variable as "out_rawline"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42866
diff
changeset
|
2101 for out_rawline in output: |
42869
5ca351ba2478
run-tests: rename `lcmd` variable to `line_cmd`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42868
diff
changeset
|
2102 out_line, cmd_line = out_rawline, None |
42867
eab66266180e
run-tests: clarify "l" variable as "out_rawline"
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42866
diff
changeset
|
2103 if salt in out_rawline: |
42869
5ca351ba2478
run-tests: rename `lcmd` variable to `line_cmd`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42868
diff
changeset
|
2104 out_line, cmd_line = out_rawline.split(salt, 1) |
42868
35ef1e957a62
run-tests: rename `lout` variable to `out_line`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42867
diff
changeset
|
2105 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2106 pos, postout, warnonly = self._process_out_line( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2107 out_line, pos, postout, expected, warnonly |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2108 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2109 pos, postout = self._process_cmd_line(cmd_line, pos, postout, after) |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2110 |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2111 if pos in after: |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2112 postout += after.pop(pos) |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2113 |
42899
f461b65866e9
run-tests: extract a `process_out_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42898
diff
changeset
|
2114 if warnonly == WARN_YES: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2115 exitcode = False # Set exitcode to warned. |
21314
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2116 |
76d7967d8f3d
run-tests: finish moving tsttest() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21313
diff
changeset
|
2117 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
|
2118 |
42899
f461b65866e9
run-tests: extract a `process_out_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42898
diff
changeset
|
2119 def _process_out_line(self, out_line, pos, postout, expected, warnonly): |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2120 while out_line: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2121 if not out_line.endswith(b'\n'): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2122 out_line += b' (no-eol)\n' |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2123 |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2124 # Find the expected output at the current position. |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2125 els = [None] |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2126 if expected.get(pos, None): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2127 els = expected[pos] |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2128 |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2129 optional = [] |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2130 for i, el in enumerate(els): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2131 r = False |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2132 if el: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2133 r, exact = self.linematch(el, out_line) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2134 if isinstance(r, str): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2135 if r == '-glob': |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2136 out_line = ''.join(el.rsplit(' (glob)', 1)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2137 r = '' # Warn only this line. |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2138 elif r == "retry": |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2139 postout.append(b' ' + el) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2140 else: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2141 log('\ninfo, unknown linematch result: %r\n' % r) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2142 r = False |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2143 if r: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2144 els.pop(i) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2145 break |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2146 if el: |
42901
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2147 if isoptional(el): |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2148 optional.append(i) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2149 else: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2150 m = optline.match(el) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2151 if m: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2152 conditions = [c for c in m.group(2).split(b' ')] |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2153 |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2154 if not self._iftest(conditions): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2155 optional.append(i) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2156 if exact: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2157 # Don't allow line to be matches against a later |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2158 # line in the output |
28569
1ad0ddf8cccc
run-tests: teach _processoutput to handle multiple lines of churn
timeless <timeless@mozdev.org>
parents:
28568
diff
changeset
|
2159 els.pop(i) |
1ad0ddf8cccc
run-tests: teach _processoutput to handle multiple lines of churn
timeless <timeless@mozdev.org>
parents:
28568
diff
changeset
|
2160 break |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2161 |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2162 if r: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2163 if r == "retry": |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2164 continue |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2165 # clean up any optional leftovers |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2166 for i in optional: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2167 postout.append(b' ' + els[i]) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2168 for i in reversed(optional): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2169 del els[i] |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2170 postout.append(b' ' + el) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2171 else: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2172 if self.NEEDESCAPE(out_line): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2173 out_line = TTest._stringescape( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2174 b'%s (esc)\n' % out_line.rstrip(b'\n') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2175 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2176 postout.append(b' ' + out_line) # Let diff deal with it. |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2177 if r != '': # If line failed. |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2178 warnonly = WARN_NO |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2179 elif warnonly == WARN_UNDEFINED: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2180 warnonly = WARN_YES |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2181 break |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2182 else: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2183 # clean up any optional leftovers |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2184 while expected.get(pos, None): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2185 el = expected[pos].pop(0) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2186 if el: |
42901
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2187 if not isoptional(el): |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2188 m = optline.match(el) |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2189 if m: |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2190 conditions = [c for c in m.group(2).split(b' ')] |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2191 |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2192 if self._iftest(conditions): |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2193 # Don't append as optional line |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2194 continue |
31829
4eec2f04a672
run-tests: support per-line conditional output in tests
Matt Harbison <matt_harbison@yahoo.com>
parents:
31827
diff
changeset
|
2195 else: |
42900
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2196 continue |
8510566b2bef
run-tests: remove the artificial indentation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42899
diff
changeset
|
2197 postout.append(b' ' + el) |
42899
f461b65866e9
run-tests: extract a `process_out_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42898
diff
changeset
|
2198 return pos, postout, warnonly |
21312
986b8a58a6d3
run-tests: move t test parsing into its own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21311
diff
changeset
|
2199 |
42898
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2200 def _process_cmd_line(self, cmd_line, pos, postout, after): |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2201 """process a "command" part of a line from unified test output""" |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2202 if cmd_line: |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2203 # Add on last return code. |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2204 ret = int(cmd_line.split()[1]) |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2205 if ret != 0: |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2206 postout.append(b' [%d]\n' % ret) |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2207 if pos in after: |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2208 # Merge in non-active test bits. |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2209 postout += after.pop(pos) |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2210 pos = int(cmd_line.split()[0]) |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2211 return pos, postout |
fc8072f38fd6
run-tests: extract a `process_cmd_line` from the main function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42869
diff
changeset
|
2212 |
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
2213 @staticmethod |
21316
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2214 def rematch(el, l): |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2215 try: |
43801
3fe91bcd5199
tests: fix deprecation warning about regex flags not at beginning of expr
Kyle Lippincott <spectral@google.com>
parents:
43594
diff
changeset
|
2216 # parse any flags at the beginning of the regex. Only 'i' is |
3fe91bcd5199
tests: fix deprecation warning about regex flags not at beginning of expr
Kyle Lippincott <spectral@google.com>
parents:
43594
diff
changeset
|
2217 # supported right now, but this should be easy to extend. |
3fe91bcd5199
tests: fix deprecation warning about regex flags not at beginning of expr
Kyle Lippincott <spectral@google.com>
parents:
43594
diff
changeset
|
2218 flags, el = re.match(br'^(\(\?i\))?(.*)', el).groups()[0:2] |
3fe91bcd5199
tests: fix deprecation warning about regex flags not at beginning of expr
Kyle Lippincott <spectral@google.com>
parents:
43594
diff
changeset
|
2219 flags = flags or b'' |
3fe91bcd5199
tests: fix deprecation warning about regex flags not at beginning of expr
Kyle Lippincott <spectral@google.com>
parents:
43594
diff
changeset
|
2220 el = flags + b'(?:' + el + b')' |
21316
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2221 # use \Z to ensure that the regex matches to the end of the string |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
2222 if WINDOWS: |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2223 return re.match(el + br'\r?\n\Z', l) |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2224 return re.match(el + br'\n\Z', l) |
21316
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2225 except re.error: |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2226 # 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
|
2227 return False |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2228 |
ab9bf8a5e573
run-tests: make rematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21315
diff
changeset
|
2229 @staticmethod |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2230 def globmatch(el, l): |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2231 # 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
|
2232 # matches \ on windows. Escaping of these characters is supported. |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2233 if el + b'\n' == l: |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2234 if os.altsep: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2235 # matching on "/" is not needed for this line |
23352
5bd04faaa3ee
run-tests: don't warn on unnecessary globs mandated by check-code.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
23347
diff
changeset
|
2236 for pat in checkcodeglobpats: |
5bd04faaa3ee
run-tests: don't warn on unnecessary globs mandated by check-code.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
23347
diff
changeset
|
2237 if pat.match(el): |
5bd04faaa3ee
run-tests: don't warn on unnecessary globs mandated by check-code.py
Matt Harbison <matt_harbison@yahoo.com>
parents:
23347
diff
changeset
|
2238 return True |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2239 return b'-glob' |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2240 return True |
31673
6a2959acae1a
runtests: change local IP glob pattern from "127.0.0.1" to "$LOCALIP"
Jun Wu <quark@fb.com>
parents:
31635
diff
changeset
|
2241 el = el.replace(b'$LOCALIP', b'*') |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2242 i, n = 0, len(el) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2243 res = b'' |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2244 while i < n: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2245 c = el[i : i + 1] |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2246 i += 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2247 if c == b'\\' and i < n and el[i : i + 1] in b'*?\\/': |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2248 res += el[i - 1 : i + 1] |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2249 i += 1 |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2250 elif c == b'*': |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2251 res += b'.*' |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2252 elif c == b'?': |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2253 res += b'.' |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2254 elif c == b'/' and os.altsep: |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
2255 res += b'[/\\\\]' |
21317
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2256 else: |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2257 res += re.escape(c) |
58a599784a0c
run-tests: make globmatch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21316
diff
changeset
|
2258 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
|
2259 |
33695
eeed23508383
run-tests: drop required (feature !) style lines when the output is missing
Matt Harbison <matt_harbison@yahoo.com>
parents:
33592
diff
changeset
|
2260 def linematch(self, el, l): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2261 if el == l: # perfect match (fast) |
38554
f83600efa1ca
tests: don't allow reodering of glob/re lines across non-glob/re lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
38552
diff
changeset
|
2262 return True, True |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2263 retry = False |
42901
75bd5990d8fe
run-tests: add a dedicated 'isoptional' function
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
42900
diff
changeset
|
2264 if isoptional(el): |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2265 retry = "retry" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2266 el = el[: -len(MARK_OPTIONAL)] + b"\n" |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2267 else: |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2268 m = optline.match(el) |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2269 if m: |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2270 conditions = [c for c in m.group(2).split(b' ')] |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2271 |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2272 el = m.group(1) + b"\n" |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2273 if not self._iftest(conditions): |
42505
c1850798f995
run-tests: stop matching line for missing feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41804
diff
changeset
|
2274 # listed feature missing, should not match |
c1850798f995
run-tests: stop matching line for missing feature
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
41804
diff
changeset
|
2275 return "retry", False |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2276 |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2277 if el.endswith(b" (esc)\n"): |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
2278 el = el[:-7].decode('unicode_escape') + '\n' |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
2279 el = el.encode('latin-1') |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
2280 if el == l or WINDOWS and el[:-1] + b'\r\n' == l: |
38554
f83600efa1ca
tests: don't allow reodering of glob/re lines across non-glob/re lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
38552
diff
changeset
|
2281 return True, True |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2282 if el.endswith(b" (re)\n"): |
38554
f83600efa1ca
tests: don't allow reodering of glob/re lines across non-glob/re lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
38552
diff
changeset
|
2283 return (TTest.rematch(el[:-6], l) or retry), False |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2284 if el.endswith(b" (glob)\n"): |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2285 # ignore '(glob)' added to l by 'replacements' |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2286 if l.endswith(b" (glob)\n"): |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2287 l = l[:-8] + b"\n" |
38554
f83600efa1ca
tests: don't allow reodering of glob/re lines across non-glob/re lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
38552
diff
changeset
|
2288 return (TTest.globmatch(el[:-8], l) or retry), False |
38552
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2289 if os.altsep: |
5a20b6090a6e
tests: move handling of None "el" out of linematch()
Martin von Zweigbergk <martinvonz@google.com>
parents:
38551
diff
changeset
|
2290 _l = l.replace(b'\\', b'/') |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
2291 if el == _l or WINDOWS and el[:-1] + b'\r\n' == _l: |
38554
f83600efa1ca
tests: don't allow reodering of glob/re lines across non-glob/re lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
38552
diff
changeset
|
2292 return True, True |
f83600efa1ca
tests: don't allow reodering of glob/re lines across non-glob/re lines
Martin von Zweigbergk <martinvonz@google.com>
parents:
38552
diff
changeset
|
2293 return retry, True |
21315
56610da39b48
run-tests: make linematch a static method of TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21314
diff
changeset
|
2294 |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2295 @staticmethod |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2296 def parsehghaveoutput(lines): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
2297 """Parse hghave log lines. |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2298 |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2299 Return tuple of lists (missing, failed): |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2300 * the missing/unknown features |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
2301 * the features for which existence check failed""" |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2302 missing = [] |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2303 failed = [] |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2304 for line in lines: |
21381
9aa5784992d4
run-tests: move SKIPPED_PREFIX and FAILED_PREFIX into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21380
diff
changeset
|
2305 if line.startswith(TTest.SKIPPED_PREFIX): |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2306 line = line.splitlines()[0] |
44469
69ae64637be5
tests: use native string type for parsed hghave log lines
Manuel Jacob <me@manueljacob.de>
parents:
44468
diff
changeset
|
2307 missing.append(_bytes2sys(line[len(TTest.SKIPPED_PREFIX) :])) |
21381
9aa5784992d4
run-tests: move SKIPPED_PREFIX and FAILED_PREFIX into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21380
diff
changeset
|
2308 elif line.startswith(TTest.FAILED_PREFIX): |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2309 line = line.splitlines()[0] |
44469
69ae64637be5
tests: use native string type for parsed hghave log lines
Manuel Jacob <me@manueljacob.de>
parents:
44468
diff
changeset
|
2310 failed.append(_bytes2sys(line[len(TTest.FAILED_PREFIX) :])) |
21379
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2311 |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2312 return missing, failed |
ab1a95270a50
run-tests: move parsehghaveoutput() into TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21378
diff
changeset
|
2313 |
21384
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2314 @staticmethod |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2315 def _escapef(m): |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2316 return TTest.ESCAPEMAP[m.group(0)] |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2317 |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2318 @staticmethod |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2319 def _stringescape(s): |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2320 return TTest.ESCAPESUB(TTest._escapef, s) |
a36cc85a5b7b
run-tests: move string escaping to TTest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21383
diff
changeset
|
2321 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2322 |
22104
70bdf59d27b6
run-tests: attempt to fix iolock handling
Matt Mackall <mpm@selenic.com>
parents:
22045
diff
changeset
|
2323 iolock = threading.RLock() |
35541
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
2324 firstlock = threading.RLock() |
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
2325 firsterror = False |
14000
636a6f5aa2cd
run-tests: add locking on results struct
Matt Mackall <mpm@selenic.com>
parents:
13999
diff
changeset
|
2326 |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
2327 base_class = unittest.TextTestResult |
48273
3a95a4e660b9
python: compatibility for python 3.11 (issue6604)
Raphaël Gomès <rgomes@octobus.net>
parents:
47834
diff
changeset
|
2328 |
3a95a4e660b9
python: compatibility for python 3.11 (issue6604)
Raphaël Gomès <rgomes@octobus.net>
parents:
47834
diff
changeset
|
2329 |
3a95a4e660b9
python: compatibility for python 3.11 (issue6604)
Raphaël Gomès <rgomes@octobus.net>
parents:
47834
diff
changeset
|
2330 class TestResult(base_class): |
21429
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2331 """Holds results when executing via unittest.""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2332 |
21460
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2333 def __init__(self, options, *args, **kwargs): |
21429
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2334 super(TestResult, self).__init__(*args, **kwargs) |
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2335 |
21460
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2336 self._options = options |
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2337 |
21430
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2338 # unittest.TestResult didn't have skipped until 2.7. We need to |
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2339 # polyfill it. |
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2340 self.skipped = [] |
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2341 |
21431
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2342 # We have a custom "ignored" result that isn't present in any Python |
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2343 # unittest implementation. It is very similar to skipped. It may make |
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2344 # sense to map it into skip some day. |
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2345 self.ignored = [] |
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2346 |
51993
daeb85ebee48
run-test: add regular line break and test count in the dot output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51963
diff
changeset
|
2347 self._dot_printed = 0 |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2348 self.times = [] |
27637
b502138f5faa
cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents:
27636
diff
changeset
|
2349 self._firststarttime = None |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2350 # Data stored for the benefit of generating xunit reports. |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2351 self.successes = [] |
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2352 self.faildata = {} |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2353 |
33565
0982d900dccb
run-tests: pass color option via test case object , not global var
Martin von Zweigbergk <martinvonz@google.com>
parents:
33561
diff
changeset
|
2354 if options.color == 'auto': |
47309
af4d1a177548
run-tests: disable color in 'auto' mode on Windows if stdout is redirected
Matt Harbison <matt_harbison@yahoo.com>
parents:
47308
diff
changeset
|
2355 isatty = self.stream.isatty() |
af4d1a177548
run-tests: disable color in 'auto' mode on Windows if stdout is redirected
Matt Harbison <matt_harbison@yahoo.com>
parents:
47308
diff
changeset
|
2356 # For some reason, redirecting stdout on Windows disables the ANSI |
af4d1a177548
run-tests: disable color in 'auto' mode on Windows if stdout is redirected
Matt Harbison <matt_harbison@yahoo.com>
parents:
47308
diff
changeset
|
2357 # color processing of stderr, which is what is used to print the |
af4d1a177548
run-tests: disable color in 'auto' mode on Windows if stdout is redirected
Matt Harbison <matt_harbison@yahoo.com>
parents:
47308
diff
changeset
|
2358 # output. Therefore, both must be tty on Windows to enable color. |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
2359 if WINDOWS: |
47309
af4d1a177548
run-tests: disable color in 'auto' mode on Windows if stdout is redirected
Matt Harbison <matt_harbison@yahoo.com>
parents:
47308
diff
changeset
|
2360 isatty = isatty and sys.stdout.isatty() |
af4d1a177548
run-tests: disable color in 'auto' mode on Windows if stdout is redirected
Matt Harbison <matt_harbison@yahoo.com>
parents:
47308
diff
changeset
|
2361 self.color = pygmentspresent and isatty |
33565
0982d900dccb
run-tests: pass color option via test case object , not global var
Martin von Zweigbergk <martinvonz@google.com>
parents:
33561
diff
changeset
|
2362 elif options.color == 'never': |
0982d900dccb
run-tests: pass color option via test case object , not global var
Martin von Zweigbergk <martinvonz@google.com>
parents:
33561
diff
changeset
|
2363 self.color = False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2364 else: # 'always', for testing purposes |
33565
0982d900dccb
run-tests: pass color option via test case object , not global var
Martin von Zweigbergk <martinvonz@google.com>
parents:
33561
diff
changeset
|
2365 self.color = pygmentspresent |
33561
2893face0af5
run-tests: check if stream is a tty before using color
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
33552
diff
changeset
|
2366 |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2367 def _write_dot(self, progress): |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2368 """write an item of the "dot" progress""" |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2369 formated = highlight_progress(progress, self.color) |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2370 self.stream.write(formated) |
51993
daeb85ebee48
run-test: add regular line break and test count in the dot output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51963
diff
changeset
|
2371 self._dot_printed += 1 |
daeb85ebee48
run-test: add regular line break and test count in the dot output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51963
diff
changeset
|
2372 if not self._dot_printed % 75: |
daeb85ebee48
run-test: add regular line break and test count in the dot output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51963
diff
changeset
|
2373 self.stream.write(f' [{self._dot_printed}]\n'.rjust(8)) |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2374 self.stream.flush() |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2375 |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2376 def onStart(self, test): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
2377 """Can be overriden by custom TestResult""" |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2378 |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2379 def onEnd(self): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
2380 """Can be overriden by custom TestResult""" |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2381 |
21462
8a4ef661f08d
run-tests: make failure reporting in unittest mode equivalent to default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21461
diff
changeset
|
2382 def addFailure(self, test, reason): |
8a4ef661f08d
run-tests: make failure reporting in unittest mode equivalent to default
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21461
diff
changeset
|
2383 self.failures.append((test, reason)) |
21460
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2384 |
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2385 if self._options.first: |
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2386 self.stop() |
21735
5ee547fdb0be
run-tests: produce error on running a failing test
anuraggoel <anurag.dsps@gmail.com>
parents:
21733
diff
changeset
|
2387 else: |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2388 with iolock: |
27393
a40b623e6380
run-tests: report timeouts in a less alarming fashion
Matt Mackall <mpm@selenic.com>
parents:
27141
diff
changeset
|
2389 if reason == "timed out": |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2390 self._write_dot('t') |
27393
a40b623e6380
run-tests: report timeouts in a less alarming fashion
Matt Mackall <mpm@selenic.com>
parents:
27141
diff
changeset
|
2391 else: |
a40b623e6380
run-tests: report timeouts in a less alarming fashion
Matt Mackall <mpm@selenic.com>
parents:
27141
diff
changeset
|
2392 if not self._options.nodiff: |
34842
8bce3e51b101
run-tests: move newline out of colorized message
Martin von Zweigbergk <martinvonz@google.com>
parents:
34804
diff
changeset
|
2393 self.stream.write('\n') |
8bce3e51b101
run-tests: move newline out of colorized message
Martin von Zweigbergk <martinvonz@google.com>
parents:
34804
diff
changeset
|
2394 # Exclude the '\n' from highlighting to lex correctly |
8bce3e51b101
run-tests: move newline out of colorized message
Martin von Zweigbergk <martinvonz@google.com>
parents:
34804
diff
changeset
|
2395 formatted = 'ERROR: %s output changed\n' % test |
33930
f5d4bb8e944d
run-tests: factor out highlight functions
Yuya Nishihara <yuya@tcha.org>
parents:
33929
diff
changeset
|
2396 self.stream.write(highlightmsg(formatted, self.color)) |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2397 self._write_dot('!') |
21754
7e14d026c4c4
run-tests: fixes the '--interactive' option error
anuraggoel <anurag.dsps@gmail.com>
parents:
21753
diff
changeset
|
2398 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2399 self.stream.flush() |
21460
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2400 |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2401 def addSuccess(self, test): |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2402 with iolock: |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2403 # bypass the TextTestResult method as do deal with the output ourself |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2404 super(base_class, self).addSuccess(test) |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2405 if self.showAll: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2406 self._write_status(test, "ok") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2407 elif self.dots: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2408 self._write_dot('.') |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2409 self.successes.append(test) |
21460
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2410 |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2411 def addError(self, test, err): |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2412 super(base_class, self).addError(test, err) |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2413 if self.showAll: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2414 self._write_status(test, "ERROR") |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2415 elif self.dots: |
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2416 self._write_dot('E') |
21460
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2417 if self._options.first: |
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2418 self.stop() |
df580990507e
run-tests: abort tests after first failure in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21459
diff
changeset
|
2419 |
21430
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2420 # Polyfill. |
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2421 def addSkip(self, test, reason): |
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2422 self.skipped.append((test, reason)) |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2423 with iolock: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2424 if self.showAll: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2425 self.stream.writeln('skipped %s' % reason) |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2426 else: |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2427 self._write_dot('s') |
21430
cf2992656bf8
run-tests: teach unittest about skipped tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21429
diff
changeset
|
2428 |
21431
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2429 def addIgnore(self, test, reason): |
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2430 self.ignored.append((test, reason)) |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2431 with iolock: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2432 if self.showAll: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2433 self.stream.writeln('ignored %s' % reason) |
21997
93c3b3f55d59
run-tests: fix test result counts with --keyword specified or skips occurring
Augie Fackler <raf@durin42.com>
parents:
21993
diff
changeset
|
2434 else: |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2435 if reason not in ('not retesting', "doesn't match keyword"): |
51837
7933bcb02bfc
run-tests: add color to the progress output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51703
diff
changeset
|
2436 self._write_dot('i') |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2437 else: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2438 self.testsRun += 1 |
21431
0f12bc8aed80
run-tests: teach unittest about ignored tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21430
diff
changeset
|
2439 |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
2440 def addOutputMismatch(self, test, ret, got, expected): |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
2441 """Record a mismatch in test output for a particular test.""" |
35541
87676e8ee056
test-run-tests: stabilize the test (issue5735)
Jun Wu <quark@fb.com>
parents:
35540
diff
changeset
|
2442 if self.shouldStop or firsterror: |
22838
9a20f53e436f
run-tests: handle --jobs and --first gracefully
Augie Fackler <raf@durin42.com>
parents:
22486
diff
changeset
|
2443 # don't print, some other test case already failed and |
9a20f53e436f
run-tests: handle --jobs and --first gracefully
Augie Fackler <raf@durin42.com>
parents:
22486
diff
changeset
|
2444 # printed, we're just stale and probably failed due to our |
9a20f53e436f
run-tests: handle --jobs and --first gracefully
Augie Fackler <raf@durin42.com>
parents:
22486
diff
changeset
|
2445 # temp dir getting cleaned up. |
9a20f53e436f
run-tests: handle --jobs and --first gracefully
Augie Fackler <raf@durin42.com>
parents:
22486
diff
changeset
|
2446 return |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
2447 |
21763
84cd5ee787ed
run-tests: hold iolock across diff/prompt when interactive
Matt Mackall <mpm@selenic.com>
parents:
21754
diff
changeset
|
2448 accepted = False |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2449 lines = [] |
21763
84cd5ee787ed
run-tests: hold iolock across diff/prompt when interactive
Matt Mackall <mpm@selenic.com>
parents:
21754
diff
changeset
|
2450 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2451 with iolock: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2452 if self._options.nodiff: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2453 pass |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2454 elif self._options.view: |
25056
e5f6c6ec21b8
run-tests: be more paranoid about os.system using bytes
Augie Fackler <augie@google.com>
parents:
25055
diff
changeset
|
2455 v = self._options.view |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2456 subprocess.call( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2457 r'"%s" "%s" "%s"' |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
2458 % (v, _bytes2sys(test.refpath), _bytes2sys(test.errpath)), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2459 shell=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2460 ) |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
2461 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2462 servefail, lines = getdiff( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2463 expected, got, test.refpath, test.errpath |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2464 ) |
36438
93228b2a1fc0
run-tests: don't mask errors when a server fails to start
Matt Harbison <matt_harbison@yahoo.com>
parents:
36037
diff
changeset
|
2465 self.stream.write('\n') |
93228b2a1fc0
run-tests: don't mask errors when a server fails to start
Matt Harbison <matt_harbison@yahoo.com>
parents:
36037
diff
changeset
|
2466 for line in lines: |
93228b2a1fc0
run-tests: don't mask errors when a server fails to start
Matt Harbison <matt_harbison@yahoo.com>
parents:
36037
diff
changeset
|
2467 line = highlightdiff(line, self.color) |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
2468 self.stream.flush() |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
2469 self.stream.buffer.write(line) |
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
2470 self.stream.buffer.flush() |
21521
855f092c96e5
run-tests: move diff generation into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21520
diff
changeset
|
2471 |
36461
51a9f0246931
run-tests: resume raising an exception when a server fails to start
Matt Harbison <matt_harbison@yahoo.com>
parents:
36438
diff
changeset
|
2472 if servefail: |
51a9f0246931
run-tests: resume raising an exception when a server fails to start
Matt Harbison <matt_harbison@yahoo.com>
parents:
36438
diff
changeset
|
2473 raise test.failureException( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2474 'server failed to start (HGPORT=%s)' % test._startport |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2475 ) |
36461
51a9f0246931
run-tests: resume raising an exception when a server fails to start
Matt Harbison <matt_harbison@yahoo.com>
parents:
36438
diff
changeset
|
2476 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2477 # handle interactive prompt without releasing iolock |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2478 if self._options.interactive: |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2479 if test.readrefout() != expected: |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2480 self.stream.write( |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2481 'Reference output has changed (run again to prompt ' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2482 'changes)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2483 ) |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2484 else: |
44944
617cd3b1e9cd
tests: make it clear what happen when no response entered
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
44632
diff
changeset
|
2485 self.stream.write('Accept this change? [y/N] ') |
39909
0f8ff3ff5d5c
run-tests: flush output stream before prompting to accept changes
Matt Harbison <matt_harbison@yahoo.com>
parents:
39742
diff
changeset
|
2486 self.stream.flush() |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2487 answer = sys.stdin.readline().strip() |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2488 if answer.lower() in ('y', 'yes'): |
32982
573baab2a797
run-tests: fix -i when "#testcases" is used in .t test
Jun Wu <quark@fb.com>
parents:
32981
diff
changeset
|
2489 if test.path.endswith(b'.t'): |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2490 rename(test.errpath, test.path) |
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2491 else: |
46384
7bb31c367847
run-test: avoid byte issue when replacing output file of python test
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46327
diff
changeset
|
2492 rename(test.errpath, b'%s.out' % test.path) |
32980
8dc62c97a665
run-tests: do not prompt changes (-i) if a race condition is detected
Jun Wu <quark@fb.com>
parents:
32943
diff
changeset
|
2493 accepted = True |
28127
807bc140e915
run-tests: remove useless "failed" flag from addOutputMismatch()
Yuya Nishihara <yuya@tcha.org>
parents:
28126
diff
changeset
|
2494 if not accepted: |
25052
c4217a046b62
run-tests: record faildata using bytes instead of str
Augie Fackler <augie@google.com>
parents:
25051
diff
changeset
|
2495 self.faildata[test.name] = b''.join(lines) |
21763
84cd5ee787ed
run-tests: hold iolock across diff/prompt when interactive
Matt Mackall <mpm@selenic.com>
parents:
21754
diff
changeset
|
2496 |
84cd5ee787ed
run-tests: hold iolock across diff/prompt when interactive
Matt Mackall <mpm@selenic.com>
parents:
21754
diff
changeset
|
2497 return accepted |
21523
9fb6f328576a
run-tests: move interactive test acceptance into TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21522
diff
changeset
|
2498 |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2499 def startTest(self, test): |
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2500 super(TestResult, self).startTest(test) |
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2501 |
21977
4ca4e1572022
run-tests: '--time' option provide more details to Linux users
anuraggoel <anurag.dsps@gmail.com>
parents:
21919
diff
changeset
|
2502 # os.times module computes the user time and system time spent by |
4ca4e1572022
run-tests: '--time' option provide more details to Linux users
anuraggoel <anurag.dsps@gmail.com>
parents:
21919
diff
changeset
|
2503 # child's processes along with real elapsed time taken by a process. |
4ca4e1572022
run-tests: '--time' option provide more details to Linux users
anuraggoel <anurag.dsps@gmail.com>
parents:
21919
diff
changeset
|
2504 # This module has one limitation. It can only work for Linux user |
43594
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2505 # and not for Windows. Hence why we fall back to another function |
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2506 # for wall time calculations. |
43593
ae91e4e4c9b0
tests: rename stopped and started variables to reflect times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43408
diff
changeset
|
2507 test.started_times = os.times() |
43594
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2508 # TODO use a monotonic clock once support for Python 2.7 is dropped. |
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2509 test.started_time = time.time() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2510 if self._firststarttime is None: # thread racy but irrelevant |
43594
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2511 self._firststarttime = test.started_time |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2512 |
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2513 def stopTest(self, test, interrupted=False): |
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2514 super(TestResult, self).stopTest(test) |
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2515 |
43593
ae91e4e4c9b0
tests: rename stopped and started variables to reflect times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43408
diff
changeset
|
2516 test.stopped_times = os.times() |
43594
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2517 stopped_time = time.time() |
43593
ae91e4e4c9b0
tests: rename stopped and started variables to reflect times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43408
diff
changeset
|
2518 |
ae91e4e4c9b0
tests: rename stopped and started variables to reflect times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43408
diff
changeset
|
2519 starttime = test.started_times |
ae91e4e4c9b0
tests: rename stopped and started variables to reflect times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43408
diff
changeset
|
2520 endtime = test.stopped_times |
25097
a4fce7905721
run-tests: track start and end time of tests
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25068
diff
changeset
|
2521 origin = self._firststarttime |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2522 self.times.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2523 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2524 test.name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2525 endtime[2] - starttime[2], # user space CPU time |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2526 endtime[3] - starttime[3], # sys space CPU time |
43594
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2527 stopped_time - test.started_time, # real time |
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2528 test.started_time - origin, # start date in run context |
ac140b85aae9
tests: use time.time() for relative start and stop times
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43593
diff
changeset
|
2529 stopped_time - origin, # end date in run context |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2530 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2531 ) |
21977
4ca4e1572022
run-tests: '--time' option provide more details to Linux users
anuraggoel <anurag.dsps@gmail.com>
parents:
21919
diff
changeset
|
2532 |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2533 if interrupted: |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2534 with iolock: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2535 self.stream.writeln( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2536 'INTERRUPTED: %s (after %d seconds)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2537 % (test.name, self.times[-1][3]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2538 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2539 |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2540 |
38616
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2541 def getTestResult(): |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2542 """ |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2543 Returns the relevant test result |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2544 """ |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2545 if "CUSTOM_TEST_RESULT" in os.environ: |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2546 testresultmodule = __import__(os.environ["CUSTOM_TEST_RESULT"]) |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2547 return testresultmodule.TestResult |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2548 else: |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2549 return TestResult |
c44ae5997869
run-tests: add support for external test result
Boris Feld <boris.feld@octobus.net>
parents:
38554
diff
changeset
|
2550 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2551 |
21439
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2552 class TestSuite(unittest.TestSuite): |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23077
diff
changeset
|
2553 """Custom unittest TestSuite that knows how to execute Mercurial tests.""" |
21528
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2554 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2555 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2556 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2557 testdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2558 jobs=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2559 whitelist=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2560 blacklist=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2561 keywords=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2562 loop=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2563 runs_per_test=1, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2564 loadtest=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2565 showchannels=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2566 *args, |
51993
daeb85ebee48
run-test: add regular line break and test count in the dot output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51963
diff
changeset
|
2567 **kwargs, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2568 ): |
21528
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2569 """Create a new instance that can run tests with a configuration. |
21439
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2570 |
21533
aecac8059c00
run-tests: make testdir an argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21532
diff
changeset
|
2571 testdir specifies the directory where tests are executed from. This |
aecac8059c00
run-tests: make testdir an argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21532
diff
changeset
|
2572 is typically the ``tests`` directory from Mercurial's source |
aecac8059c00
run-tests: make testdir an argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21532
diff
changeset
|
2573 repository. |
aecac8059c00
run-tests: make testdir an argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21532
diff
changeset
|
2574 |
21528
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2575 jobs specifies the number of jobs to run concurrently. Each test |
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2576 executes on its own thread. Tests actually spawn new processes, so |
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2577 state mutation should not be an issue. |
21529
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2578 |
27880
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2579 If there is only one job, it will use the main thread. |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2580 |
21529
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2581 whitelist and blacklist denote tests that have been whitelisted and |
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2582 blacklisted, respectively. These arguments don't belong in TestSuite. |
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2583 Instead, whitelist and blacklist should be handled by the thing that |
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2584 populates the TestSuite with tests. They are present to preserve |
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2585 backwards compatible behavior which reports skipped tests as part |
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2586 of the results. |
21530
78289625e986
run-tests: make retest a named argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21529
diff
changeset
|
2587 |
21531
7fcda22acc43
run-tests: make keywords a named argument to TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21530
diff
changeset
|
2588 keywords denotes key words that will be used to filter which tests |
7fcda22acc43
run-tests: make keywords a named argument to TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21530
diff
changeset
|
2589 to execute. This arguably belongs outside of TestSuite. |
21532
9d2ba7e2324d
run-tests: move loop to a named argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21531
diff
changeset
|
2590 |
9d2ba7e2324d
run-tests: move loop to a named argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21531
diff
changeset
|
2591 loop denotes whether to loop over tests forever. |
21528
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2592 """ |
21439
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2593 super(TestSuite, self).__init__(*args, **kwargs) |
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2594 |
21528
32b9bbca2052
run-tests: pass jobs into TestSuite constructor
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21523
diff
changeset
|
2595 self._jobs = jobs |
21529
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2596 self._whitelist = whitelist |
117e027390ab
run-tests: move whitelist and blacklist to named arguments of TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21528
diff
changeset
|
2597 self._blacklist = blacklist |
21531
7fcda22acc43
run-tests: make keywords a named argument to TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21530
diff
changeset
|
2598 self._keywords = keywords |
21532
9d2ba7e2324d
run-tests: move loop to a named argument of TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21531
diff
changeset
|
2599 self._loop = loop |
24329
e7ca4d4b10e1
run-tests: add --runs-per-test flag
Augie Fackler <augie@google.com>
parents:
24306
diff
changeset
|
2600 self._runs_per_test = runs_per_test |
24330
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2601 self._loadtest = loadtest |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2602 self._showchannels = showchannels |
21439
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2603 |
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2604 def run(self, result): |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2605 # We have a number of filters that need to be applied. We do this |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2606 # here instead of inside Test because it makes the running logic for |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2607 # Test simpler. |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2608 tests = [] |
24330
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2609 num_tests = [0] |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2610 for test in self._tests: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2611 |
24330
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2612 def get(): |
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2613 num_tests[0] += 1 |
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2614 if getattr(test, 'should_reload', False): |
32310
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
2615 return self._loadtest(test, num_tests[0]) |
24330
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2616 return test |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2617 |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2618 if not os.path.exists(test.path): |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2619 result.addSkip(test, "Doesn't exist") |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2620 continue |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2621 |
45513
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2622 is_whitelisted = self._whitelist and ( |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2623 test.relpath in self._whitelist or test.bname in self._whitelist |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2624 ) |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2625 if not is_whitelisted: |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2626 is_blacklisted = self._blacklist and ( |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2627 test.relpath in self._blacklist |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2628 or test.bname in self._blacklist |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2629 ) |
22140fd783d2
run-test: allow relative path in `--blacklist` and `--whitelist` (issue6351)
Antoine cezar<acezar@chwitlabs.fr>
parents:
45442
diff
changeset
|
2630 if is_blacklisted: |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2631 result.addSkip(test, 'blacklisted') |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2632 continue |
21531
7fcda22acc43
run-tests: make keywords a named argument to TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21530
diff
changeset
|
2633 if self._keywords: |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
2634 with open(test.path, 'rb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
2635 t = f.read().lower() + test.bname.lower() |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2636 ignored = False |
21531
7fcda22acc43
run-tests: make keywords a named argument to TestSuite.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21530
diff
changeset
|
2637 for k in self._keywords.lower().split(): |
21507
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2638 if k not in t: |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2639 result.addIgnore(test, "doesn't match keyword") |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2640 ignored = True |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2641 break |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2642 |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2643 if ignored: |
d839e4820da7
run-tests: move test filtering into TestSuite.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21506
diff
changeset
|
2644 continue |
49285
56f98406831b
py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents:
49244
diff
changeset
|
2645 for _ in range(self._runs_per_test): |
24330
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
2646 tests.append(get()) |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2647 |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
2648 runtests = list(tests) |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2649 done = queue.Queue() |
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2650 running = 0 |
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2651 |
49215
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2652 channels_lock = threading.Lock() |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2653 channels = [""] * self._jobs |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2654 |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2655 def job(test, result): |
49215
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2656 with channels_lock: |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2657 for n, v in enumerate(channels): |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2658 if not v: |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2659 channel = n |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2660 break |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2661 else: |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2662 raise ValueError('Could not find output channel') |
8d31ef3017c9
run-tests: prevent race-condition when picking a channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49214
diff
changeset
|
2663 channels[channel] = "=" + test.name[5:].split(".")[0] |
49214
eca367970253
run-tests: send the test result after freeing the channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49213
diff
changeset
|
2664 |
eca367970253
run-tests: send the test result after freeing the channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49213
diff
changeset
|
2665 r = None |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2666 try: |
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2667 test(result) |
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2668 except KeyboardInterrupt: |
49214
eca367970253
run-tests: send the test result after freeing the channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49213
diff
changeset
|
2669 pass |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2670 except: # re-raises |
49214
eca367970253
run-tests: send the test result after freeing the channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49213
diff
changeset
|
2671 r = ('!', test, 'run-test raised an error, see traceback') |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2672 raise |
32622
931bb962e0eb
tests: fix run-tests when there's a bad #if in a test
Augie Fackler <augie@google.com>
parents:
32621
diff
changeset
|
2673 finally: |
931bb962e0eb
tests: fix run-tests when there's a bad #if in a test
Augie Fackler <augie@google.com>
parents:
32621
diff
changeset
|
2674 try: |
931bb962e0eb
tests: fix run-tests when there's a bad #if in a test
Augie Fackler <augie@google.com>
parents:
32621
diff
changeset
|
2675 channels[channel] = '' |
931bb962e0eb
tests: fix run-tests when there's a bad #if in a test
Augie Fackler <augie@google.com>
parents:
32621
diff
changeset
|
2676 except IndexError: |
931bb962e0eb
tests: fix run-tests when there's a bad #if in a test
Augie Fackler <augie@google.com>
parents:
32621
diff
changeset
|
2677 pass |
49214
eca367970253
run-tests: send the test result after freeing the channel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49213
diff
changeset
|
2678 done.put(r) |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2679 |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2680 def stat(): |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2681 count = 0 |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2682 while channels: |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2683 d = '\n%03s ' % count |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2684 for n, v in enumerate(channels): |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2685 if v: |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2686 d += v[0] |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2687 channels[n] = v[1:] or '.' |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2688 else: |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2689 d += ' ' |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2690 d += ' ' |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2691 with iolock: |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2692 sys.stdout.write(d + ' ') |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2693 sys.stdout.flush() |
49285
56f98406831b
py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents:
49244
diff
changeset
|
2694 for x in range(10): |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2695 if channels: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2696 time.sleep(0.1) |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2697 count += 1 |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2698 |
24507
a0668a587c04
run-tests: wait for test threads after first error
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24506
diff
changeset
|
2699 stoppedearly = False |
a0668a587c04
run-tests: wait for test threads after first error
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24506
diff
changeset
|
2700 |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2701 if self._showchannels: |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2702 statthread = threading.Thread(target=stat, name="stat") |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2703 statthread.start() |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2704 |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2705 try: |
27880
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2706 while tests or running: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2707 if not done.empty() or running == self._jobs or not tests: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2708 try: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2709 done.get(True, 1) |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2710 running -= 1 |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2711 if result and result.shouldStop: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2712 stoppedearly = True |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2713 break |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2714 except queue.Empty: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2715 continue |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2716 if tests and not running == self._jobs: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2717 test = tests.pop(0) |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2718 if self._loop: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2719 if getattr(test, 'should_reload', False): |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2720 num_tests[0] += 1 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2721 tests.append(self._loadtest(test, num_tests[0])) |
27880
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2722 else: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2723 tests.append(test) |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2724 if self._jobs == 1: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2725 job(test, result) |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2726 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2727 t = threading.Thread( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2728 target=job, name=test.name, args=(test, result) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2729 ) |
27689
50e621fe0362
run-tests: skip threading for a single test
timeless <timeless@mozdev.org>
parents:
27686
diff
changeset
|
2730 t.start() |
27880
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2731 running += 1 |
24507
a0668a587c04
run-tests: wait for test threads after first error
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24506
diff
changeset
|
2732 |
27880
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2733 # If we stop early we still need to wait on started tests to |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2734 # finish. Otherwise, there is a race between the test completing |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2735 # and the test's cleanup code running. This could result in the |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2736 # test reporting incorrect. |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2737 if stoppedearly: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2738 while running: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2739 try: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2740 done.get(True, 1) |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2741 running -= 1 |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2742 except queue.Empty: |
b04df9ce1fb0
run-tests: skip threading for a single test (issue5040)
timeless <timeless@mozdev.org>
parents:
27777
diff
changeset
|
2743 continue |
21496
f145914e698d
run-tests: move _executetests into TestSuite
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21495
diff
changeset
|
2744 except KeyboardInterrupt: |
21520
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
2745 for test in runtests: |
fa6ba4372678
run-tests: remove global abort flag
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21518
diff
changeset
|
2746 test.abort() |
21439
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2747 |
27396
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2748 channels = [] |
64c584070fc7
run-tests: show scheduling with --showchannels
Matt Mackall <mpm@selenic.com>
parents:
27394
diff
changeset
|
2749 |
21439
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2750 return result |
2e22954b97e3
run-tests: define a custom TestSuite that uses _executetests()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21438
diff
changeset
|
2751 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2752 |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2753 # Save the most recent 5 wall-clock runtimes of each test to a |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2754 # human-readable text file named .testtimes. Tests are sorted |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2755 # alphabetically, while times for each test are listed from oldest to |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2756 # newest. |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2757 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2758 |
32717
e5680cb1414f
run-tests: write test times to output dir
Siddharth Agarwal <sid0@fb.com>
parents:
32716
diff
changeset
|
2759 def loadtimes(outputdir): |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2760 times = [] |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2761 try: |
35855
69d7fcd91696
testrunner: fix updating of .testtimes file
Martin von Zweigbergk <martinvonz@google.com>
parents:
35854
diff
changeset
|
2762 with open(os.path.join(outputdir, b'.testtimes')) as fp: |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2763 for line in fp: |
35854
568917059243
testrunner: make reading of test times work with #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
35848
diff
changeset
|
2764 m = re.match('(.*?) ([0-9. ]+)', line) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2765 times.append( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2766 (m.group(1), [float(t) for t in m.group(2).split()]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2767 ) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
2768 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
2769 pass |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2770 return times |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2771 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2772 |
32717
e5680cb1414f
run-tests: write test times to output dir
Siddharth Agarwal <sid0@fb.com>
parents:
32716
diff
changeset
|
2773 def savetimes(outputdir, result): |
e5680cb1414f
run-tests: write test times to output dir
Siddharth Agarwal <sid0@fb.com>
parents:
32716
diff
changeset
|
2774 saved = dict(loadtimes(outputdir)) |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2775 maxruns = 5 |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44449
diff
changeset
|
2776 skipped = {str(t[0]) for t in result.skipped} |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2777 for tdata in result.times: |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2778 test, real = tdata[0], tdata[3] |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2779 if test not in skipped: |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2780 ts = saved.setdefault(test, []) |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2781 ts.append(real) |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2782 ts[:] = ts[-maxruns:] |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2783 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2784 fd, tmpname = tempfile.mkstemp( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2785 prefix=b'.testtimes', dir=outputdir, text=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2786 ) |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2787 with os.fdopen(fd, 'w') as fp: |
28284
0fe00bdb2f4f
run-tests: fix Python 3 incompatibilities
Gregory Szorc <gregory.szorc@gmail.com>
parents:
28180
diff
changeset
|
2788 for name, ts in sorted(saved.items()): |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2789 fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts]))) |
32717
e5680cb1414f
run-tests: write test times to output dir
Siddharth Agarwal <sid0@fb.com>
parents:
32716
diff
changeset
|
2790 timepath = os.path.join(outputdir, b'.testtimes') |
27634
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2791 try: |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2792 os.unlink(timepath) |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2793 except OSError: |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2794 pass |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2795 try: |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2796 os.rename(tmpname, timepath) |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2797 except OSError: |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2798 pass |
a1eff44c432b
tests: write recent run times to a file named tests/.testtimes
Bryan O'Sullivan <bos@serpentine.com>
parents:
27602
diff
changeset
|
2799 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2800 |
21429
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2801 class TextTestRunner(unittest.TextTestRunner): |
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2802 """Custom unittest test runner that uses appropriate settings.""" |
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2803 |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2804 def __init__(self, runner, *args, **kwargs): |
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2805 super(TextTestRunner, self).__init__(*args, **kwargs) |
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2806 |
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2807 self._runner = runner |
38620
875e033fbbdd
run-tests: fix test result verbosity
Boris Feld <boris.feld@octobus.net>
parents:
38617
diff
changeset
|
2808 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2809 self._result = getTestResult()( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2810 self._runner.options, self.stream, self.descriptions, self.verbosity |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2811 ) |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2812 |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2813 def listtests(self, test): |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2814 test = sorted(test, key=lambda t: t.name) |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2815 |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2816 self._result.onStart(test) |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2817 |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2818 for t in test: |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2819 print(t.name) |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2820 self._result.addSuccess(t) |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2821 |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2822 if self._runner.options.xunit: |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2823 with open(self._runner.options.xunit, "wb") as xuf: |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2824 self._writexunit(self._result, xuf) |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2825 |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2826 if self._runner.options.json: |
32718
232875623c27
run-tests: write JSON reports to output dir
Siddharth Agarwal <sid0@fb.com>
parents:
32717
diff
changeset
|
2827 jsonpath = os.path.join(self._runner._outputdir, b'report.json') |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2828 with open(jsonpath, 'w') as fp: |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2829 self._writejson(self._result, fp) |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2830 |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2831 return self._result |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
2832 |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2833 def run(self, test): |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2834 self._result.onStart(test) |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2835 test(self._result) |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2836 |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2837 failed = len(self._result.failures) |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2838 skipped = len(self._result.skipped) |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2839 ignored = len(self._result.ignored) |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2840 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2841 with iolock: |
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2842 self.stream.writeln('') |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2843 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2844 if not self._runner.options.noskips: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2845 for test, msg in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2846 self._result.skipped, key=lambda s: s[0].name |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2847 ): |
33929
5d2ce90c71f1
run-tests: include "\n" in formatted message instead of calling writeln()
Yuya Nishihara <yuya@tcha.org>
parents:
33871
diff
changeset
|
2848 formatted = 'Skipped %s: %s\n' % (test.name, msg) |
38622
fa6edc6a02a9
run-tests: fix a too long line
Boris Feld <boris.feld@octobus.net>
parents:
38620
diff
changeset
|
2849 msg = highlightmsg(formatted, self._result.color) |
fa6edc6a02a9
run-tests: fix a too long line
Boris Feld <boris.feld@octobus.net>
parents:
38620
diff
changeset
|
2850 self.stream.write(msg) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2851 for test, msg in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2852 self._result.failures, key=lambda f: f[0].name |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2853 ): |
33929
5d2ce90c71f1
run-tests: include "\n" in formatted message instead of calling writeln()
Yuya Nishihara <yuya@tcha.org>
parents:
33871
diff
changeset
|
2854 formatted = 'Failed %s: %s\n' % (test.name, msg) |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2855 self.stream.write(highlightmsg(formatted, self._result.color)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2856 for test, msg in sorted( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2857 self._result.errors, key=lambda e: e[0].name |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2858 ): |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2859 self.stream.writeln('Errored %s: %s' % (test.name, msg)) |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2860 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2861 if self._runner.options.xunit: |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2862 with open(self._runner.options.xunit, "wb") as xuf: |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2863 self._writexunit(self._result, xuf) |
22044
a06172e85fd4
run-tests: add support for xunit test reports
Augie Fackler <raf@durin42.com>
parents:
21997
diff
changeset
|
2864 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2865 if self._runner.options.json: |
32718
232875623c27
run-tests: write JSON reports to output dir
Siddharth Agarwal <sid0@fb.com>
parents:
32717
diff
changeset
|
2866 jsonpath = os.path.join(self._runner._outputdir, b'report.json') |
27773
bf45edfa9d90
run-tests: use a context manager for file I/O
Bryan O'Sullivan <bryano@fb.com>
parents:
27689
diff
changeset
|
2867 with open(jsonpath, 'w') as fp: |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2868 self._writejson(self._result, fp) |
22391
c42e69268f5b
run-tests: added '--json' functionality to store test result in json file
anuraggoel <anurag.dsps@gmail.com>
parents:
22361
diff
changeset
|
2869 |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2870 self._runner._checkhglib('Tested') |
21459
d5945324b130
run-tests: print compatible output from TextTestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21458
diff
changeset
|
2871 |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2872 savetimes(self._runner._outputdir, self._result) |
28596
9949950664cd
run-tests: add support for automatically bisecting test failures
Augie Fackler <augie@google.com>
parents:
28582
diff
changeset
|
2873 |
9949950664cd
run-tests: add support for automatically bisecting test failures
Augie Fackler <augie@google.com>
parents:
28582
diff
changeset
|
2874 if failed and self._runner.options.known_good_rev: |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2875 self._bisecttests(t for t, m in self._result.failures) |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2876 self.stream.writeln( |
32942
5af78c524f34
tests: remove support for warned tests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
32934
diff
changeset
|
2877 '# Ran %d tests, %d skipped, %d failed.' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2878 % (self._result.testsRun, skipped + ignored, failed) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2879 ) |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2880 if failed: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2881 self.stream.writeln( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2882 'python hash seed: %s' % os.environ['PYTHONHASHSEED'] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2883 ) |
25046
40b4308d5653
run-tests: switch all uses of iolock.acquire() to a context manager
Augie Fackler <augie@google.com>
parents:
25045
diff
changeset
|
2884 if self._runner.options.time: |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2885 self.printtimes(self._result.times) |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
2886 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
2887 if self._runner.options.exceptions: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
2888 exceptions = aggregateexceptions( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2889 os.path.join(self._runner._outputdir, b'exceptions') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2890 ) |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
2891 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
2892 self.stream.writeln('Exceptions Report:') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2893 self.stream.writeln( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2894 '%d total from %d frames' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2895 % (exceptions['total'], len(exceptions['exceptioncounts'])) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2896 ) |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
2897 combined = exceptions['combined'] |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
2898 for key in sorted(combined, key=combined.get, reverse=True): |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
2899 frame, line, exc = key |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
2900 totalcount, testcount, leastcount, leasttest = combined[key] |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
2901 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2902 self.stream.writeln( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2903 '%d (%d tests)\t%s: %s (%s - %d total)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2904 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2905 totalcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2906 testcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2907 frame, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2908 exc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2909 leasttest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2910 leastcount, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2911 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2912 ) |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
2913 |
32907
bd77ac2bd23a
run-tests: explicitly flush test runner output for Windows stability
Matt Harbison <matt_harbison@yahoo.com>
parents:
32853
diff
changeset
|
2914 self.stream.flush() |
22104
70bdf59d27b6
run-tests: attempt to fix iolock handling
Matt Mackall <mpm@selenic.com>
parents:
22045
diff
changeset
|
2915 |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
2916 return self._result |
21613
b3213b9fafed
run-tests: exit with non-0 exit code when tests fail or warn
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21539
diff
changeset
|
2917 |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2918 def _bisecttests(self, tests): |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2919 bisectcmd = ['hg', 'bisect'] |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2920 bisectrepo = self._runner.options.bisect_repo |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2921 if bisectrepo: |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2922 bisectcmd.extend(['-R', os.path.abspath(bisectrepo)]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2923 |
34803
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2924 def pread(args): |
34804
149109c96904
run-tests: set HGPLAIN=1 when bisecting
Jun Wu <quark@fb.com>
parents:
34803
diff
changeset
|
2925 env = os.environ.copy() |
149109c96904
run-tests: set HGPLAIN=1 when bisecting
Jun Wu <quark@fb.com>
parents:
34803
diff
changeset
|
2926 env['HGPLAIN'] = '1' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2927 p = subprocess.Popen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2928 args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, env=env |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2929 ) |
34803
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2930 data = p.stdout.read() |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2931 p.wait() |
34803
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2932 return data |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2933 |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2934 for test in tests: |
34803
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2935 pread(bisectcmd + ['--reset']), |
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2936 pread(bisectcmd + ['--bad', '.']) |
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2937 pread(bisectcmd + ['--good', self._runner.options.known_good_rev]) |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2938 # TODO: we probably need to forward more options |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2939 # that alter hg's behavior inside the tests. |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2940 opts = '' |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2941 withhg = self._runner.options.with_hg |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2942 if withhg: |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
2943 opts += ' --with-hg=%s ' % shellquote(_bytes2sys(withhg)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2944 rtc = '%s %s %s %s' % (sysexecutable, sys.argv[0], opts, test) |
34803
d817bf1fc675
run-tests: extract Popen logic to a single method
Jun Wu <quark@fb.com>
parents:
34802
diff
changeset
|
2945 data = pread(bisectcmd + ['--command', rtc]) |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2946 m = re.search( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2947 ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2948 br'\nThe first (?P<goodbad>bad|good) revision ' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2949 br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2950 br'summary: +(?P<summary>[^\n]+)\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2951 ), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2952 data, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2953 (re.MULTILINE | re.DOTALL), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2954 ) |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2955 if m is None: |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2956 self.stream.writeln( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2957 'Failed to identify failure point for %s' % test |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2958 ) |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2959 continue |
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2960 dat = m.groupdict() |
37741
700aaa19de63
tests: fix up a couple of minor bytes inconsistencies in run-tests.py
Augie Fackler <augie@google.com>
parents:
37342
diff
changeset
|
2961 verb = 'broken' if dat['goodbad'] == b'bad' else 'fixed' |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2962 self.stream.writeln( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2963 '%s %s by %s (%s)' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2964 % ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2965 test, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2966 verb, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2967 dat['node'].decode('ascii'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2968 dat['summary'].decode('utf8', 'ignore'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2969 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2970 ) |
34802
9c7548eb7d1c
run-tests: move bisect logic to a separate method
Jun Wu <quark@fb.com>
parents:
34444
diff
changeset
|
2971 |
21495
b162bdc78bef
run-tests: capture execution times in TestResult
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21494
diff
changeset
|
2972 def printtimes(self, times): |
22104
70bdf59d27b6
run-tests: attempt to fix iolock handling
Matt Mackall <mpm@selenic.com>
parents:
22045
diff
changeset
|
2973 # iolock held by run |
21494
dcefc4091c86
run-tests: move outputtimes() into unittest runner class
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21493
diff
changeset
|
2974 self.stream.writeln('# Producing time report') |
21977
4ca4e1572022
run-tests: '--time' option provide more details to Linux users
anuraggoel <anurag.dsps@gmail.com>
parents:
21919
diff
changeset
|
2975 times.sort(key=lambda t: (t[3])) |
25098
bf84ab53c2fd
run-tests: include 'start' and 'end' in --time output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25097
diff
changeset
|
2976 cols = '%7.3f %7.3f %7.3f %7.3f %7.3f %s' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2977 self.stream.writeln( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2978 '%-7s %-7s %-7s %-7s %-7s %s' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2979 % ('start', 'end', 'cuser', 'csys', 'real', 'Test') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2980 ) |
24982
5c15f7e0f52b
run-tests: stop explicit expansion of time data
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24981
diff
changeset
|
2981 for tdata in times: |
5c15f7e0f52b
run-tests: stop explicit expansion of time data
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24981
diff
changeset
|
2982 test = tdata[0] |
25098
bf84ab53c2fd
run-tests: include 'start' and 'end' in --time output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25097
diff
changeset
|
2983 cuser, csys, real, start, end = tdata[1:6] |
bf84ab53c2fd
run-tests: include 'start' and 'end' in --time output
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
25097
diff
changeset
|
2984 self.stream.writeln(cols % (start, end, cuser, csys, real, test)) |
21429
203ed3cf6c81
run-tests: define custom result and runner classes for unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21428
diff
changeset
|
2985 |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2986 @staticmethod |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2987 def _writexunit(result, outf): |
32714
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
2988 # See http://llg.cubic.org/docs/junit/ for a reference. |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44449
diff
changeset
|
2989 timesd = {t[0]: t[3] for t in result.times} |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2990 doc = minidom.Document() |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2991 s = doc.createElement('testsuite') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2992 s.setAttribute('errors', "0") # TODO |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2993 s.setAttribute('failures', str(len(result.failures))) |
41546
20e62312e016
run-tests: set attributes in sorted order
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41540
diff
changeset
|
2994 s.setAttribute('name', 'run-tests') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2995 s.setAttribute( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2996 'skipped', str(len(result.skipped) + len(result.ignored)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
2997 ) |
41546
20e62312e016
run-tests: set attributes in sorted order
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41540
diff
changeset
|
2998 s.setAttribute('tests', str(result.testsRun)) |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
2999 doc.appendChild(s) |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3000 for tc in result.successes: |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3001 t = doc.createElement('testcase') |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3002 t.setAttribute('name', tc.name) |
32702
d0b9c36851f5
run-tests: make time field optional for xunit report
Siddharth Agarwal <sid0@fb.com>
parents:
32701
diff
changeset
|
3003 tctime = timesd.get(tc.name) |
d0b9c36851f5
run-tests: make time field optional for xunit report
Siddharth Agarwal <sid0@fb.com>
parents:
32701
diff
changeset
|
3004 if tctime is not None: |
d0b9c36851f5
run-tests: make time field optional for xunit report
Siddharth Agarwal <sid0@fb.com>
parents:
32701
diff
changeset
|
3005 t.setAttribute('time', '%.3f' % tctime) |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3006 s.appendChild(t) |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3007 for tc, err in sorted(result.faildata.items()): |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3008 t = doc.createElement('testcase') |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3009 t.setAttribute('name', tc) |
32702
d0b9c36851f5
run-tests: make time field optional for xunit report
Siddharth Agarwal <sid0@fb.com>
parents:
32701
diff
changeset
|
3010 tctime = timesd.get(tc) |
d0b9c36851f5
run-tests: make time field optional for xunit report
Siddharth Agarwal <sid0@fb.com>
parents:
32701
diff
changeset
|
3011 if tctime is not None: |
d0b9c36851f5
run-tests: make time field optional for xunit report
Siddharth Agarwal <sid0@fb.com>
parents:
32701
diff
changeset
|
3012 t.setAttribute('time', '%.3f' % tctime) |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3013 # createCDATASection expects a unicode or it will |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3014 # convert using default conversion rules, which will |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3015 # fail if string isn't ASCII. |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3016 err = cdatasafe(err).decode('utf-8', 'replace') |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3017 cd = doc.createCDATASection(err) |
32714
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3018 # Use 'failure' here instead of 'error' to match errors = 0, |
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3019 # failures = len(result.failures) in the testsuite element. |
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3020 failelem = doc.createElement('failure') |
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3021 failelem.setAttribute('message', 'output changed') |
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3022 failelem.setAttribute('type', 'output-mismatch') |
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3023 failelem.appendChild(cd) |
ef8d24539612
run-tests: wrap failures in an XUnit 'failure' element
Siddharth Agarwal <sid0@fb.com>
parents:
32711
diff
changeset
|
3024 t.appendChild(failelem) |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3025 s.appendChild(t) |
32715
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3026 for tc, message in result.skipped: |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3027 # According to the schema, 'skipped' has no attributes. So store |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3028 # the skip message as a text node instead. |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3029 t = doc.createElement('testcase') |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3030 t.setAttribute('name', tc.name) |
34269
20f547806a4d
tests: fix run-tests XML reporting on Python 3
Augie Fackler <augie@google.com>
parents:
34268
diff
changeset
|
3031 binmessage = message.encode('utf-8') |
20f547806a4d
tests: fix run-tests XML reporting on Python 3
Augie Fackler <augie@google.com>
parents:
34268
diff
changeset
|
3032 message = cdatasafe(binmessage).decode('utf-8', 'replace') |
32715
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3033 cd = doc.createCDATASection(message) |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3034 skipelem = doc.createElement('skipped') |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3035 skipelem.appendChild(cd) |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3036 t.appendChild(skipelem) |
a4d0e816a672
run-tests: add information about skipped tests to XUnit output
Siddharth Agarwal <sid0@fb.com>
parents:
32714
diff
changeset
|
3037 s.appendChild(t) |
32700
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3038 outf.write(doc.toprettyxml(indent=' ', encoding='utf-8')) |
3afe258fb0fe
run-tests: factor out xunit write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32622
diff
changeset
|
3039 |
32701
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3040 @staticmethod |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3041 def _writejson(result, outf): |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3042 timesd = {} |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3043 for tdata in result.times: |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3044 test = tdata[0] |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3045 timesd[test] = tdata[1:] |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3046 |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3047 outcome = {} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3048 groups = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3049 ('success', ((tc, None) for tc in result.successes)), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3050 ('failure', result.failures), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3051 ('skip', result.skipped), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3052 ] |
32701
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3053 for res, testcases in groups: |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3054 for tc, __ in testcases: |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3055 if tc.name in timesd: |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3056 diff = result.faildata.get(tc.name, b'') |
32853
3139a7a1e7d4
tests: try and fail more gracefully with broken unicode escapes
Augie Fackler <augie@google.com>
parents:
32720
diff
changeset
|
3057 try: |
3139a7a1e7d4
tests: try and fail more gracefully with broken unicode escapes
Augie Fackler <augie@google.com>
parents:
32720
diff
changeset
|
3058 diff = diff.decode('unicode_escape') |
3139a7a1e7d4
tests: try and fail more gracefully with broken unicode escapes
Augie Fackler <augie@google.com>
parents:
32720
diff
changeset
|
3059 except UnicodeDecodeError as e: |
3139a7a1e7d4
tests: try and fail more gracefully with broken unicode escapes
Augie Fackler <augie@google.com>
parents:
32720
diff
changeset
|
3060 diff = '%r decoding diff, sorry' % e |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3061 tres = { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3062 'result': res, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3063 'time': ('%0.3f' % timesd[tc.name][2]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3064 'cuser': ('%0.3f' % timesd[tc.name][0]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3065 'csys': ('%0.3f' % timesd[tc.name][1]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3066 'start': ('%0.3f' % timesd[tc.name][3]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3067 'end': ('%0.3f' % timesd[tc.name][4]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3068 'diff': diff, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3069 } |
32701
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3070 else: |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3071 # blacklisted test |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3072 tres = {'result': res} |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3073 |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3074 outcome[tc.name] = tres |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3075 jsonout = json.dumps( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3076 outcome, sort_keys=True, indent=4, separators=(',', ': ') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3077 ) |
32701
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3078 outf.writelines(("testreport =", jsonout)) |
60c921ff4104
run-tests: factor out json write code into another method
Siddharth Agarwal <sid0@fb.com>
parents:
32700
diff
changeset
|
3079 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3080 |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3081 def sorttests(testdescs, previoustimes, shuffle=False): |
35489
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3082 """Do an in-place sort of tests.""" |
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3083 if shuffle: |
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3084 random.shuffle(testdescs) |
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3085 return |
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3086 |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3087 if previoustimes: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3088 |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3089 def sortkey(f): |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3090 f = f['path'] |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3091 if f in previoustimes: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3092 # Use most recent time as estimate |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3093 return -(previoustimes[f][-1]) |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3094 else: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3095 # Default to a rather arbitrary value of 1 second for new tests |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3096 return -1.0 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3097 |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3098 else: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3099 # keywords for slow tests |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3100 slow = { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3101 b'svn': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3102 b'cvs': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3103 b'hghave': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3104 b'largefiles-update': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3105 b'run-tests': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3106 b'corruption': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3107 b'race': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3108 b'i18n': 10, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3109 b'check': 100, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3110 b'gendoc': 100, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3111 b'contrib-perf': 200, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3112 b'merge-combination': 100, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3113 } |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3114 perf = {} |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3115 |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3116 def sortkey(f): |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3117 # run largest tests first, as they tend to take the longest |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3118 f = f['path'] |
35489
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3119 try: |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3120 return perf[f] |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3121 except KeyError: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3122 try: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3123 val = -os.stat(f).st_size |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
3124 except FileNotFoundError: |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3125 perf[f] = -1e9 # file does not exist, tell early |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3126 return -1e9 |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3127 for kw, mul in slow.items(): |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3128 if kw in f: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3129 val *= mul |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3130 if f.endswith(b'.py'): |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3131 val /= 10.0 |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3132 perf[f] = val / 1000.0 |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3133 return perf[f] |
35489
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3134 |
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3135 testdescs.sort(key=sortkey) |
212a6e9aecb0
run-tests: extract sorting of tests to own function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35488
diff
changeset
|
3136 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3137 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48880
diff
changeset
|
3138 class TestRunner: |
21340
fda36de1cb0e
run-tests: establish a class to hold testing state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21339
diff
changeset
|
3139 """Holds context for executing tests. |
fda36de1cb0e
run-tests: establish a class to hold testing state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21339
diff
changeset
|
3140 |
fda36de1cb0e
run-tests: establish a class to hold testing state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21339
diff
changeset
|
3141 Tests rely on a lot of state. This object holds it for them. |
fda36de1cb0e
run-tests: establish a class to hold testing state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21339
diff
changeset
|
3142 """ |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3143 |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
3144 # Programs required to run tests. |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
3145 REQUIREDTOOLS = [ |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3146 b'diff', |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3147 b'grep', |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3148 b'unzip', |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3149 b'gunzip', |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3150 b'bunzip2', |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3151 b'sed', |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
3152 ] |
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
3153 |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
3154 # Maps file extensions to test class. |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3155 TESTTYPES = [ |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3156 (b'.py', PythonTest), |
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3157 (b'.t', TTest), |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3158 ] |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3159 |
21341
cb88d4a04f58
run-tests: move TESTDIR out of a global
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21340
diff
changeset
|
3160 def __init__(self): |
21348
b3399154505f
run-tests: add options to runner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21347
diff
changeset
|
3161 self.options = None |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
3162 self._hgroot = None |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3163 self._testdir = None |
32716
2146f01a2577
run-tests: allow specifying an output dir to write .errs to
Siddharth Agarwal <sid0@fb.com>
parents:
32715
diff
changeset
|
3164 self._outputdir = None |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3165 self._hgtmp = None |
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3166 self._installdir = None |
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3167 self._bindir = None |
47575
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3168 # a place for run-tests.py to generate executable it needs |
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3169 self._custom_bin_dir = None |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3170 self._pythondir = None |
47574
2b2f5cf979c3
run-tests: explicitly track that `pythondir` was inferred
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47573
diff
changeset
|
3171 # True if we had to infer the pythondir from --with-hg |
2b2f5cf979c3
run-tests: explicitly track that `pythondir` was inferred
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47573
diff
changeset
|
3172 self._pythondir_inferred = False |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3173 self._coveragefile = None |
21352
39fd89fbbc3c
run-tests: move createdfiles out of a global and into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21351
diff
changeset
|
3174 self._createdfiles = [] |
28099
a5f0c0aab2bb
run-tests: allow to specify executable of any name by --with-hg
Yuya Nishihara <yuya@tcha.org>
parents:
28098
diff
changeset
|
3175 self._hgcommand = None |
21385
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
3176 self._hgpath = None |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3177 self._portoffset = 0 |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3178 self._ports = {} |
21340
fda36de1cb0e
run-tests: establish a class to hold testing state
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21339
diff
changeset
|
3179 |
21376
e4366bc08879
run-tests: move option parser logic to TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21375
diff
changeset
|
3180 def run(self, args, parser=None): |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3181 """Run the test suite.""" |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
3182 oldmask = os.umask(0o22) |
21375
bd70dcb91af6
run-tests: move umask into TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21374
diff
changeset
|
3183 try: |
21376
e4366bc08879
run-tests: move option parser logic to TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21375
diff
changeset
|
3184 parser = parser or getparser() |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
3185 options = parseargs(args, parser) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3186 tests = [_sys2bytes(a) for a in options.tests] |
34263
1533371769b5
tests: add support for listing tests to run in a file
Augie Fackler <augie@google.com>
parents:
34041
diff
changeset
|
3187 if options.test_list is not None: |
1533371769b5
tests: add support for listing tests to run in a file
Augie Fackler <augie@google.com>
parents:
34041
diff
changeset
|
3188 for listfile in options.test_list: |
1533371769b5
tests: add support for listing tests to run in a file
Augie Fackler <augie@google.com>
parents:
34041
diff
changeset
|
3189 with open(listfile, 'rb') as f: |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
3190 tests.extend(t for t in f.read().splitlines() if t) |
21376
e4366bc08879
run-tests: move option parser logic to TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21375
diff
changeset
|
3191 self.options = options |
e4366bc08879
run-tests: move option parser logic to TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21375
diff
changeset
|
3192 |
21375
bd70dcb91af6
run-tests: move umask into TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21374
diff
changeset
|
3193 self._checktools() |
35187
b4b0aed7bfaf
run-tests: convert to argparse
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35155
diff
changeset
|
3194 testdescs = self.findtests(tests) |
25107
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3195 if options.profile_runner: |
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3196 import statprof |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3197 |
25107
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3198 statprof.start() |
52215
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3199 result = self._run( |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3200 testdescs, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3201 shard_index=options.shard_index, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3202 shard_total=options.shard_total, |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3203 ) |
25107
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3204 if options.profile_runner: |
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3205 statprof.stop() |
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3206 statprof.display() |
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3207 return result |
149cc7663ac8
run-tests: add a --profile-runner option
Augie Fackler <augie@google.com>
parents:
25098
diff
changeset
|
3208 |
21375
bd70dcb91af6
run-tests: move umask into TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21374
diff
changeset
|
3209 finally: |
bd70dcb91af6
run-tests: move umask into TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21374
diff
changeset
|
3210 os.umask(oldmask) |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3211 |
52215
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3212 def _run(self, testdescs, shard_index=None, shard_total=None): |
40487
78e5b9d815fa
test: fix self._testdir to use the right mercurial library during testing
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents:
40479
diff
changeset
|
3213 testdir = getcwdb() |
34962
a18eef03d879
run-tests: $TESTDIR can be something else than $PWD
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34842
diff
changeset
|
3214 # assume all tests in same folder for now |
a18eef03d879
run-tests: $TESTDIR can be something else than $PWD
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34842
diff
changeset
|
3215 if testdescs: |
a18eef03d879
run-tests: $TESTDIR can be something else than $PWD
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34842
diff
changeset
|
3216 pathname = os.path.dirname(testdescs[0]['path']) |
35066
57d56f603f70
run-tests: fix TESTDIR if testdescs are absolute paths
Kyle Lippincott <spectral@google.com>
parents:
34969
diff
changeset
|
3217 if pathname: |
40487
78e5b9d815fa
test: fix self._testdir to use the right mercurial library during testing
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents:
40479
diff
changeset
|
3218 testdir = os.path.join(testdir, pathname) |
78e5b9d815fa
test: fix self._testdir to use the right mercurial library during testing
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents:
40479
diff
changeset
|
3219 self._testdir = osenvironb[b'TESTDIR'] = testdir |
49047
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3220 osenvironb[b'TESTDIR_FORWARD_SLASH'] = osenvironb[b'TESTDIR'].replace( |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3221 os.sep.encode('ascii'), b'/' |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3222 ) |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3223 |
32716
2146f01a2577
run-tests: allow specifying an output dir to write .errs to
Siddharth Agarwal <sid0@fb.com>
parents:
32715
diff
changeset
|
3224 if self.options.outputdir: |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3225 self._outputdir = canonpath(_sys2bytes(self.options.outputdir)) |
32716
2146f01a2577
run-tests: allow specifying an output dir to write .errs to
Siddharth Agarwal <sid0@fb.com>
parents:
32715
diff
changeset
|
3226 else: |
40487
78e5b9d815fa
test: fix self._testdir to use the right mercurial library during testing
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents:
40479
diff
changeset
|
3227 self._outputdir = getcwdb() |
35097
fc0f3ed071fc
run-tests: outputdir also has to be changed if $TESTDIR is not $PWD
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
35092
diff
changeset
|
3228 if testdescs and pathname: |
fc0f3ed071fc
run-tests: outputdir also has to be changed if $TESTDIR is not $PWD
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
35092
diff
changeset
|
3229 self._outputdir = os.path.join(self._outputdir, pathname) |
36665
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3230 previoustimes = {} |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3231 if self.options.order_by_runtime: |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3232 previoustimes = dict(loadtimes(self._outputdir)) |
6276cbc704a6
testrunner: add option to sort tests by previous run time
Martin von Zweigbergk <martinvonz@google.com>
parents:
36522
diff
changeset
|
3233 sorttests(testdescs, previoustimes, shuffle=self.options.random) |
21371
a10ba7870c2d
run-tests: assign testdir in TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21370
diff
changeset
|
3234 |
21370
97475f27bebe
run-tests: move hash seed logic to TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21369
diff
changeset
|
3235 if 'PYTHONHASHSEED' not in os.environ: |
97475f27bebe
run-tests: move hash seed logic to TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21369
diff
changeset
|
3236 # use a random python hash seed all the time |
97475f27bebe
run-tests: move hash seed logic to TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21369
diff
changeset
|
3237 # we do the randomness ourself to know what seed is used |
97475f27bebe
run-tests: move hash seed logic to TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21369
diff
changeset
|
3238 os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32)) |
97475f27bebe
run-tests: move hash seed logic to TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21369
diff
changeset
|
3239 |
44518
b2e41723f886
run-tests: restrict Rust thread pool to 3 threads during tests
Raphaël Gomès <rgomes@octobus.net>
parents:
44489
diff
changeset
|
3240 # Rayon (Rust crate for multi-threading) will use all logical CPU cores |
b2e41723f886
run-tests: restrict Rust thread pool to 3 threads during tests
Raphaël Gomès <rgomes@octobus.net>
parents:
44489
diff
changeset
|
3241 # by default, causing thrashing on high-cpu-count systems. |
b2e41723f886
run-tests: restrict Rust thread pool to 3 threads during tests
Raphaël Gomès <rgomes@octobus.net>
parents:
44489
diff
changeset
|
3242 # Setting its limit to 3 during tests should still let us uncover |
b2e41723f886
run-tests: restrict Rust thread pool to 3 threads during tests
Raphaël Gomès <rgomes@octobus.net>
parents:
44489
diff
changeset
|
3243 # multi-threading bugs while keeping the thrashing reasonable. |
b2e41723f886
run-tests: restrict Rust thread pool to 3 threads during tests
Raphaël Gomès <rgomes@octobus.net>
parents:
44489
diff
changeset
|
3244 os.environ.setdefault("RAYON_NUM_THREADS", "3") |
b2e41723f886
run-tests: restrict Rust thread pool to 3 threads during tests
Raphaël Gomès <rgomes@octobus.net>
parents:
44489
diff
changeset
|
3245 |
21369
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3246 if self.options.tmpdir: |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3247 self.options.keep_tmpdir = True |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3248 tmpdir = _sys2bytes(self.options.tmpdir) |
21369
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3249 if os.path.exists(tmpdir): |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3250 # Meaning of tmpdir has changed since 1.3: we used to create |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3251 # HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3252 # tmpdir already exists. |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
3253 print("error: temp dir %r already exists" % tmpdir) |
21369
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3254 return 1 |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3255 |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3256 os.makedirs(tmpdir) |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3257 else: |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3258 d = None |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
3259 if WINDOWS: |
21369
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3260 # without this, we get the default temp dir location, but |
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3261 # in all lowercase, which causes troubles with paths (issue3490) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3262 d = osenvironb.get(b'TMP', None) |
25262
5a809deb88e6
run-tests: python3.5 now supports mkdtemp using bytes for paths
Augie Fackler <raf@durin42.com>
parents:
25261
diff
changeset
|
3263 tmpdir = tempfile.mkdtemp(b'', b'hgtests.', d) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3264 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3265 self._hgtmp = osenvironb[b'HGTMP'] = os.path.realpath(tmpdir) |
21369
1d0aa8bccc87
run-tests: move tmpdir calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21368
diff
changeset
|
3266 |
47575
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3267 self._custom_bin_dir = os.path.join(self._hgtmp, b'custom-bin') |
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3268 os.makedirs(self._custom_bin_dir) |
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3269 |
50932
afb3cccc90f7
run-tests: detect HGWITHRUSTEXT value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
3270 # detect and enforce an alternative way to specify rust extension usage |
afb3cccc90f7
run-tests: detect HGWITHRUSTEXT value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
3271 if ( |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3272 not ( |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3273 self.options.wheel |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3274 or self.options.pure |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3275 or self.options.rust |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3276 or self.options.no_rust |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3277 ) |
50932
afb3cccc90f7
run-tests: detect HGWITHRUSTEXT value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
3278 and os.environ.get("HGWITHRUSTEXT") == "cpython" |
afb3cccc90f7
run-tests: detect HGWITHRUSTEXT value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
3279 ): |
afb3cccc90f7
run-tests: detect HGWITHRUSTEXT value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
3280 self.options.rust = True |
afb3cccc90f7
run-tests: detect HGWITHRUSTEXT value
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
50931
diff
changeset
|
3281 |
21368
a884548f5421
run-tests: move more path calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21367
diff
changeset
|
3282 if self.options.with_hg: |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3283 self._installdir = None |
25042
201823c50610
run-tests: work around with_hg being bytes or string depending on provenance
Augie Fackler <augie@google.com>
parents:
25041
diff
changeset
|
3284 whg = self.options.with_hg |
201823c50610
run-tests: work around with_hg being bytes or string depending on provenance
Augie Fackler <augie@google.com>
parents:
25041
diff
changeset
|
3285 self._bindir = os.path.dirname(os.path.realpath(whg)) |
201823c50610
run-tests: work around with_hg being bytes or string depending on provenance
Augie Fackler <augie@google.com>
parents:
25041
diff
changeset
|
3286 assert isinstance(self._bindir, bytes) |
28099
a5f0c0aab2bb
run-tests: allow to specify executable of any name by --with-hg
Yuya Nishihara <yuya@tcha.org>
parents:
28098
diff
changeset
|
3287 self._hgcommand = os.path.basename(whg) |
21368
a884548f5421
run-tests: move more path calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21367
diff
changeset
|
3288 |
35569
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3289 normbin = os.path.normpath(os.path.abspath(whg)) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3290 normbin = normbin.replace(_sys2bytes(os.sep), b'/') |
35569
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3291 |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3292 # Other Python scripts in the test harness need to |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3293 # `import mercurial`. If `hg` is a Python script, we assume |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3294 # the Mercurial modules are relative to its path and tell the tests |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3295 # to load Python modules from its directory. |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3296 with open(whg, 'rb') as fh: |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3297 initial = fh.read(1024) |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3298 |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3299 if re.match(b'#!.*python', initial): |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3300 self._pythondir = self._bindir |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3301 # If it looks like our in-repo Rust binary, use the source root. |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3302 # This is a bit hacky. But rhg is still not supported outside the |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3303 # source directory. So until it is, do the simple thing. |
35600
31acf6619f08
run-tests: fix regular expression for path test
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35569
diff
changeset
|
3304 elif re.search(b'/rust/target/[^/]+/hg', normbin): |
35569
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3305 self._pythondir = os.path.dirname(self._testdir) |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3306 # Fall back to the legacy behavior. |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3307 else: |
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3308 self._pythondir = self._bindir |
47574
2b2f5cf979c3
run-tests: explicitly track that `pythondir` was inferred
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47573
diff
changeset
|
3309 self._pythondir_inferred = True |
35569
964212780daf
rust: implementation of `hg`
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35536
diff
changeset
|
3310 |
21368
a884548f5421
run-tests: move more path calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21367
diff
changeset
|
3311 else: |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3312 self._installdir = os.path.join(self._hgtmp, b"install") |
52232
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3313 if WINDOWS: |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3314 # The wheel variant will install things in "Scripts". |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3315 # So we can as well always install things here. |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3316 self._bindir = os.path.join(self._installdir, b"Scripts") |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3317 else: |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3318 self._bindir = os.path.join(self._installdir, b"bin") |
28099
a5f0c0aab2bb
run-tests: allow to specify executable of any name by --with-hg
Yuya Nishihara <yuya@tcha.org>
parents:
28098
diff
changeset
|
3319 self._hgcommand = b'hg' |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3320 |
52232
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3321 if self.options.wheel and not WINDOWS: |
52204
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3322 # pip installing a wheel does not have an --install-lib flag |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3323 # so we have to guess where the file will be installed. |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3324 # |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3325 # In addition, that location is not really stable, so we are |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3326 # using awful symlink trrick later in `_installhg` |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3327 v_info = sys.version_info |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3328 suffix = os.path.join( |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3329 b"lib", |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3330 b"python%d.%d" % (v_info.major, v_info.minor), |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3331 b"site-packages", |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3332 ) |
52232
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3333 elif self.options.wheel and WINDOWS: |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3334 # for some reason, Windows use an even different scheme: |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3335 # |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3336 # <prefix>/lib/site-packages/ |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3337 suffix = os.path.join( |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3338 b"lib", |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3339 b"site-packages", |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3340 ) |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3341 else: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3342 suffix = os.path.join(b"lib", b"python") |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3343 self._pythondir = os.path.join(self._installdir, suffix) |
21368
a884548f5421
run-tests: move more path calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21367
diff
changeset
|
3344 |
40976
ef7119cd4965
py3: enable legacy stdio mode in exewrapper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40975
diff
changeset
|
3345 # Force the use of hg.exe instead of relying on MSYS to recognize hg is |
ef7119cd4965
py3: enable legacy stdio mode in exewrapper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40975
diff
changeset
|
3346 # a python script and feed it to python.exe. Legacy stdio is force |
ef7119cd4965
py3: enable legacy stdio mode in exewrapper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40975
diff
changeset
|
3347 # enabled by hg.exe, and this is a more realistic way to launch hg |
ef7119cd4965
py3: enable legacy stdio mode in exewrapper
Matt Harbison <matt_harbison@yahoo.com>
parents:
40975
diff
changeset
|
3348 # anyway. |
52232
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3349 # |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3350 # We do not do it when using wheels and they do not install a .exe. |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3351 if ( |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3352 WINDOWS |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3353 and not self.options.wheel |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3354 and not self._hgcommand.endswith(b'.exe') |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3355 ): |
40975
2465e0b27a0d
run-tests: alias hg to hg.exe on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40930
diff
changeset
|
3356 self._hgcommand += b'.exe' |
2465e0b27a0d
run-tests: alias hg to hg.exe on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
40930
diff
changeset
|
3357 |
47584
ee1fc8f970e6
run-tests: introduce a `HGTEST_REAL_HG` variable for test
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47583
diff
changeset
|
3358 real_hg = os.path.join(self._bindir, self._hgcommand) |
ee1fc8f970e6
run-tests: introduce a `HGTEST_REAL_HG` variable for test
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47583
diff
changeset
|
3359 osenvironb[b'HGTEST_REAL_HG'] = real_hg |
28620
759d167f75cf
run-tests: use different chg socket directories for different tests
Jun Wu <quark@fb.com>
parents:
28596
diff
changeset
|
3360 # set CHGHG, then replace "hg" command by "chg" |
28142
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
3361 chgbindir = self._bindir |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
3362 if self.options.chg or self.options.with_chg: |
47586
a8e33ab50c4f
run-tests: use more explicit signaling for `chg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47585
diff
changeset
|
3363 osenvironb[b'CHG_INSTALLED_AS_HG'] = b'1' |
47584
ee1fc8f970e6
run-tests: introduce a `HGTEST_REAL_HG` variable for test
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47583
diff
changeset
|
3364 osenvironb[b'CHGHG'] = real_hg |
28880
f74eed3115fd
hghave: add "chg" flag to skip tests that can't be compatible with chg
Yuya Nishihara <yuya@tcha.org>
parents:
28829
diff
changeset
|
3365 else: |
47586
a8e33ab50c4f
run-tests: use more explicit signaling for `chg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47585
diff
changeset
|
3366 # drop flag for hghave |
a8e33ab50c4f
run-tests: use more explicit signaling for `chg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47585
diff
changeset
|
3367 osenvironb.pop(b'CHG_INSTALLED_AS_HG', None) |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
3368 if self.options.chg: |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
3369 self._hgcommand = b'chg' |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
3370 elif self.options.with_chg: |
28142
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
3371 chgbindir = os.path.dirname(os.path.realpath(self.options.with_chg)) |
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
3372 self._hgcommand = os.path.basename(self.options.with_chg) |
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
3373 |
46723
a6553ba1c598
tests: Enable rhg fallback to Python by default in tests
Simon Sapin <simon.sapin@octobus.net>
parents:
46668
diff
changeset
|
3374 # configure fallback and replace "hg" command by "rhg" |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3375 rhgbindir = self._bindir |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3376 if self.options.rhg or self.options.with_rhg: |
46724
78e6700ab009
tests: Add `rhg` and `no-rhg` for #require and #if in .t files
Simon Sapin <simon.sapin@octobus.net>
parents:
46723
diff
changeset
|
3377 # Affects hghave.py |
78e6700ab009
tests: Add `rhg` and `no-rhg` for #require and #if in .t files
Simon Sapin <simon.sapin@octobus.net>
parents:
46723
diff
changeset
|
3378 osenvironb[b'RHG_INSTALLED_AS_HG'] = b'1' |
46723
a6553ba1c598
tests: Enable rhg fallback to Python by default in tests
Simon Sapin <simon.sapin@octobus.net>
parents:
46668
diff
changeset
|
3379 # Affects configuration. Alternatives would be setting configuration through |
a6553ba1c598
tests: Enable rhg fallback to Python by default in tests
Simon Sapin <simon.sapin@octobus.net>
parents:
46668
diff
changeset
|
3380 # `$HGRCPATH` but some tests override that, or changing `_hgcommand` to include |
a6553ba1c598
tests: Enable rhg fallback to Python by default in tests
Simon Sapin <simon.sapin@octobus.net>
parents:
46668
diff
changeset
|
3381 # `--config` but that disrupts tests that print command lines and check expected |
a6553ba1c598
tests: Enable rhg fallback to Python by default in tests
Simon Sapin <simon.sapin@octobus.net>
parents:
46668
diff
changeset
|
3382 # output. |
a6553ba1c598
tests: Enable rhg fallback to Python by default in tests
Simon Sapin <simon.sapin@octobus.net>
parents:
46668
diff
changeset
|
3383 osenvironb[b'RHG_ON_UNSUPPORTED'] = b'fallback' |
47584
ee1fc8f970e6
run-tests: introduce a `HGTEST_REAL_HG` variable for test
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47583
diff
changeset
|
3384 osenvironb[b'RHG_FALLBACK_EXECUTABLE'] = real_hg |
47585
5654323832f0
run-tests: drop the `rhg` flag for `hghave.py` if unset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47584
diff
changeset
|
3385 else: |
5654323832f0
run-tests: drop the `rhg` flag for `hghave.py` if unset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47584
diff
changeset
|
3386 # drop flag for hghave |
5654323832f0
run-tests: drop the `rhg` flag for `hghave.py` if unset
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47584
diff
changeset
|
3387 osenvironb.pop(b'RHG_INSTALLED_AS_HG', None) |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3388 if self.options.rhg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3389 self._hgcommand = b'rhg' |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3390 elif self.options.with_rhg: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3391 rhgbindir = os.path.dirname(os.path.realpath(self.options.with_rhg)) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3392 self._hgcommand = os.path.basename(self.options.with_rhg) |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3393 |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3394 if self.options.pyoxidized: |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3395 testdir = os.path.dirname(_sys2bytes(canonpath(sys.argv[0]))) |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3396 reporootdir = os.path.dirname(testdir) |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3397 # XXX we should ideally install stuff instead of using the local build |
49832
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3398 |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3399 exe = b'hg' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3400 triple = b'' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3401 |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3402 if WINDOWS: |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3403 triple = b'x86_64-pc-windows-msvc' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3404 exe = b'hg.exe' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3405 elif MACOS: |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3406 # TODO: support Apple silicon too |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3407 triple = b'x86_64-apple-darwin' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3408 |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
3409 bin_path = b'build/pyoxidizer/%s/release/app/%s' % (triple, exe) |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3410 full_path = os.path.join(reporootdir, bin_path) |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3411 self._hgcommand = full_path |
47831
94158c541c74
pyoxidized: add a `pyoxidizer` hghave keyword for line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47826
diff
changeset
|
3412 # Affects hghave.py |
94158c541c74
pyoxidized: add a `pyoxidizer` hghave keyword for line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47826
diff
changeset
|
3413 osenvironb[b'PYOXIDIZED_INSTALLED_AS_HG'] = b'1' |
94158c541c74
pyoxidized: add a `pyoxidizer` hghave keyword for line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47826
diff
changeset
|
3414 else: |
94158c541c74
pyoxidized: add a `pyoxidizer` hghave keyword for line matching
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47826
diff
changeset
|
3415 osenvironb.pop(b'PYOXIDIZED_INSTALLED_AS_HG', None) |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3416 |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3417 osenvironb[b"BINDIR"] = self._bindir |
25058
caa2043cc322
run-tests: unblock running python tests in python 3
Augie Fackler <augie@google.com>
parents:
25057
diff
changeset
|
3418 osenvironb[b"PYTHON"] = PYTHON |
21368
a884548f5421
run-tests: move more path calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21367
diff
changeset
|
3419 |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3420 fileb = _sys2bytes(__file__) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3421 runtestdir = os.path.abspath(os.path.dirname(fileb)) |
25729
57dfadc4f46c
run-tests.py: add RUNTESTDIR to refer `tests` of Mercurial
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25728
diff
changeset
|
3422 osenvironb[b'RUNTESTDIR'] = runtestdir |
49047
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3423 osenvironb[b'RUNTESTDIR_FORWARD_SLASH'] = runtestdir.replace( |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3424 os.sep.encode('ascii'), b'/' |
c827bb7b5806
run-tests: introduce "forward-slash" version of everything on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48735
diff
changeset
|
3425 ) |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
3426 sepb = _sys2bytes(os.pathsep) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3427 path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb) |
24742
39ee0444e27c
run-tests: also follow symlink when update PATH with 'run-tests.py' dir
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24516
diff
changeset
|
3428 if os.path.islink(__file__): |
39ee0444e27c
run-tests: also follow symlink when update PATH with 'run-tests.py' dir
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24516
diff
changeset
|
3429 # test helper will likely be at the end of the symlink |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3430 realfile = os.path.realpath(fileb) |
24742
39ee0444e27c
run-tests: also follow symlink when update PATH with 'run-tests.py' dir
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24516
diff
changeset
|
3431 realdir = os.path.abspath(os.path.dirname(realfile)) |
39ee0444e27c
run-tests: also follow symlink when update PATH with 'run-tests.py' dir
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24516
diff
changeset
|
3432 path.insert(2, realdir) |
28142
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
3433 if chgbindir != self._bindir: |
85e28a46c7f1
run-tests: add --with-chg option to run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28127
diff
changeset
|
3434 path.insert(1, chgbindir) |
46668
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3435 if rhgbindir != self._bindir: |
fb2368598281
tests: Add `--rhg` and `--with-rhg=<path>` options for `run-tests.py`
Simon Sapin <simon.sapin@octobus.net>
parents:
46384
diff
changeset
|
3436 path.insert(1, rhgbindir) |
25730
c380d5273e91
run-tests.py: add TESTDIR to PATH if it differs from RUNTESTDIR
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25729
diff
changeset
|
3437 if self._testdir != runtestdir: |
c380d5273e91
run-tests.py: add TESTDIR to PATH if it differs from RUNTESTDIR
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25729
diff
changeset
|
3438 path = [self._testdir] + path |
47575
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3439 path = [self._custom_bin_dir] + path |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3440 osenvironb[b"PATH"] = sepb.join(path) |
21368
a884548f5421
run-tests: move more path calculations into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21367
diff
changeset
|
3441 |
21367
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3442 # Include TESTDIR in PYTHONPATH so that out-of-tree extensions |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3443 # can run .../tests/run-tests.py test-foo where test-foo |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3444 # adds an extension to HGRC. Also include run-test.py directory to |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3445 # import modules like heredoctest. |
23859
661b246bf1c4
run-tests: include testdir in $PATH so tests easily can use helper tools
Mads Kiilerich <madski@unity3d.com>
parents:
23728
diff
changeset
|
3446 pypath = [self._pythondir, self._testdir, runtestdir] |
49976
afa9d73780e1
run-tests: stop ignoring venv-installed packages
Matt Harbison <matt_harbison@yahoo.com>
parents:
49875
diff
changeset
|
3447 |
afa9d73780e1
run-tests: stop ignoring venv-installed packages
Matt Harbison <matt_harbison@yahoo.com>
parents:
49875
diff
changeset
|
3448 # Setting PYTHONPATH with an activated venv causes the modules installed |
afa9d73780e1
run-tests: stop ignoring venv-installed packages
Matt Harbison <matt_harbison@yahoo.com>
parents:
49875
diff
changeset
|
3449 # in it to be ignored. Therefore, include the related paths in sys.path |
52008
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3450 # in PYTHONPATH. If the executable is run directly without activation, |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3451 # any modules installed in it would also be ignored, so include them for |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3452 # the same reason. |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3453 |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3454 for p in sys.path: |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3455 if p.startswith(sys.exec_prefix): |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3456 path = _sys2bytes(p) |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3457 if path not in pypath: |
d7e9503c07d2
run-tests: include non-activated venv packages in `PYTHONPATH`
Matt Harbison <matt_harbison@yahoo.com>
parents:
51993
diff
changeset
|
3458 pypath.append(path) |
49976
afa9d73780e1
run-tests: stop ignoring venv-installed packages
Matt Harbison <matt_harbison@yahoo.com>
parents:
49875
diff
changeset
|
3459 |
21367
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3460 # We have to augment PYTHONPATH, rather than simply replacing |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3461 # it, in case external libraries are only available via current |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3462 # PYTHONPATH. (In particular, the Subversion bindings on OS X |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3463 # are in /opt/subversion.) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3464 oldpypath = osenvironb.get(IMPL_PATH) |
21367
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3465 if oldpypath: |
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3466 pypath.append(oldpypath) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3467 osenvironb[IMPL_PATH] = sepb.join(pypath) |
21367
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3468 |
51958
16574ca8b155
test: preserve the existing module policy config for testrepohg resuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51916
diff
changeset
|
3469 os.environ["HGTEST_BASE_HGMODULEPOLICY"] = os.environ.get( |
16574ca8b155
test: preserve the existing module policy config for testrepohg resuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51916
diff
changeset
|
3470 "HGMODULEPOLICY", "" |
16574ca8b155
test: preserve the existing module policy config for testrepohg resuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51916
diff
changeset
|
3471 ) |
16574ca8b155
test: preserve the existing module policy config for testrepohg resuse
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51916
diff
changeset
|
3472 |
23935
d64dd1252386
run-tests.py: inherit --pure option from outer run-tests.py execution
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23933
diff
changeset
|
3473 if self.options.pure: |
d64dd1252386
run-tests.py: inherit --pure option from outer run-tests.py execution
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23933
diff
changeset
|
3474 os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure" |
28905
c969c72d6cbc
run-tests: set HGMODULEPOLICY for --pure
timeless <timeless@mozdev.org>
parents:
28880
diff
changeset
|
3475 os.environ["HGMODULEPOLICY"] = "py" |
44489
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3476 if self.options.rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3477 os.environ["HGMODULEPOLICY"] = "rust+c" |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3478 if self.options.no_rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3479 current_policy = os.environ.get("HGMODULEPOLICY", "") |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3480 if current_policy.startswith("rust+"): |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3481 os.environ["HGMODULEPOLICY"] = current_policy[len("rust+") :] |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3482 os.environ.pop("HGWITHRUSTEXT", None) |
23935
d64dd1252386
run-tests.py: inherit --pure option from outer run-tests.py execution
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
23933
diff
changeset
|
3483 |
26109
bad09bd22b6a
run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents:
26087
diff
changeset
|
3484 if self.options.allow_slow_tests: |
bad09bd22b6a
run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents:
26087
diff
changeset
|
3485 os.environ["HGTEST_SLOW"] = "slow" |
bad09bd22b6a
run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents:
26087
diff
changeset
|
3486 elif 'HGTEST_SLOW' in os.environ: |
bad09bd22b6a
run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents:
26087
diff
changeset
|
3487 del os.environ['HGTEST_SLOW'] |
bad09bd22b6a
run-tests: add support for marking tests as very slow
Augie Fackler <augie@google.com>
parents:
26087
diff
changeset
|
3488 |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3489 self._coveragefile = os.path.join(self._testdir, b'.coverage') |
21367
522e3d24a461
run-tests: move pypath manipulation into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21366
diff
changeset
|
3490 |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3491 if self.options.exceptions: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3492 exceptionsdir = os.path.join(self._outputdir, b'exceptions') |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3493 try: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3494 os.makedirs(exceptionsdir) |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
3495 except FileExistsError: |
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
3496 pass |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3497 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3498 # Remove all existing exception reports. |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3499 for f in os.listdir(exceptionsdir): |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3500 os.unlink(os.path.join(exceptionsdir, f)) |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3501 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3502 osenvironb[b'HGEXCEPTIONSDIR'] = exceptionsdir |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3503 logexceptions = os.path.join(self._testdir, b'logexceptions.py') |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3504 self.options.extra_config_opt.append( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3505 'extensions.logexceptions=%s' % logexceptions.decode('utf-8') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3506 ) |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
3507 |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3508 vlog("# Using TESTDIR", _bytes2sys(self._testdir)) |
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3509 vlog("# Using RUNTESTDIR", _bytes2sys(osenvironb[b'RUNTESTDIR'])) |
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3510 vlog("# Using HGTMP", _bytes2sys(self._hgtmp)) |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3511 vlog("# Using PATH", os.environ["PATH"]) |
43309
b4b1131187c4
py3: decode bytes before logging in run-tests.py
Denis Laxalde <denis@laxalde.org>
parents:
43283
diff
changeset
|
3512 vlog( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
3513 "# Using", |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
3514 _bytes2sys(IMPL_PATH), |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45830
diff
changeset
|
3515 _bytes2sys(osenvironb[IMPL_PATH]), |
43309
b4b1131187c4
py3: decode bytes before logging in run-tests.py
Denis Laxalde <denis@laxalde.org>
parents:
43283
diff
changeset
|
3516 ) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3517 vlog("# Writing to directory", _bytes2sys(self._outputdir)) |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3518 |
52215
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3519 if shard_total is not None: |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3520 slot = shard_index - 1 |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3521 testdescs = [ |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3522 t |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3523 for (idx, t) in enumerate(testdescs) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3524 if (idx % shard_total == slot) |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3525 ] |
36e4d1457c6b
run-tests: implement crude sharding support
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52205
diff
changeset
|
3526 |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3527 try: |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3528 return self._runtests(testdescs) or 0 |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3529 finally: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3530 time.sleep(0.1) |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3531 self._cleanup() |
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3532 |
21363
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3533 def findtests(self, args): |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3534 """Finds possible test files from arguments. |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3535 |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3536 If you wish to inject custom tests into the test harness, this would |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3537 be a good function to monkeypatch or override in a derived class. |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3538 """ |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3539 if not args: |
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3540 if self.options.changed: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3541 proc = Popen4( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3542 b'hg st --rev "%s" -man0 .' |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3543 % _sys2bytes(self.options.changed), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3544 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3545 0, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3546 ) |
21363
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3547 stdout, stderr = proc.communicate() |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3548 args = stdout.strip(b'\0').split(b'\0') |
21363
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3549 else: |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3550 args = os.listdir(b'.') |
21363
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3551 |
34969
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3552 expanded_args = [] |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3553 for arg in args: |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3554 if os.path.isdir(arg): |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3555 if not arg.endswith(b'/'): |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3556 arg += b'/' |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3557 expanded_args.extend([arg + a for a in os.listdir(arg)]) |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3558 else: |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3559 expanded_args.append(arg) |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3560 args = expanded_args |
d600bda4a3e1
run-tests: allow automatic test discovery when providing folder as argument
Matthieu Laneuville <matthieu.laneuville@octobus.net>
parents:
34966
diff
changeset
|
3561 |
44021
6d3b67a837a6
cleanup: drop redundant character escapes from `[]` character sets
Matt Harbison <matt_harbison@yahoo.com>
parents:
43982
diff
changeset
|
3562 testcasepattern = re.compile(br'([\w-]+\.t|py)(?:#([a-zA-Z0-9_\-.#]+))') |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3563 tests = [] |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3564 for t in args: |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3565 case = [] |
38222
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3566 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3567 if not ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3568 os.path.basename(t).startswith(b'test-') |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3569 and (t.endswith(b'.py') or t.endswith(b'.t')) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3570 ): |
41138
8ddc5d8bea25
tests: support passing testcase after .t paths that have path separators
Kyle Lippincott <spectral@google.com>
parents:
40989
diff
changeset
|
3571 m = testcasepattern.match(os.path.basename(t)) |
38222
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3572 if m is not None: |
41141
89d103fc9c19
testrunner: avoid capturing a regex group we don't care about
Martin von Zweigbergk <martinvonz@google.com>
parents:
41138
diff
changeset
|
3573 t_basename, casestr = m.groups() |
41138
8ddc5d8bea25
tests: support passing testcase after .t paths that have path separators
Kyle Lippincott <spectral@google.com>
parents:
40989
diff
changeset
|
3574 t = os.path.join(os.path.dirname(t), t_basename) |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3575 if casestr: |
38934
35180ade80c1
tests: fix bytes/str issues in run-tests.py caught by python3
Augie Fackler <augie@google.com>
parents:
38824
diff
changeset
|
3576 case = casestr.split(b'#') |
38222
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3577 else: |
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3578 continue |
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3579 |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3580 if t.endswith(b'.t'): |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3581 # .t file may contain multiple test cases |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3582 casedimensions = parsettestcases(t) |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3583 if casedimensions: |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3584 cases = [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3585 |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3586 def addcases(case, casedimensions): |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3587 if not casedimensions: |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3588 cases.append(case) |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3589 else: |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3590 for c in casedimensions[0]: |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3591 addcases(case + [c], casedimensions[1:]) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3592 |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3593 addcases([], casedimensions) |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3594 if case and case in cases: |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3595 cases = [case] |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3596 elif case: |
38222
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3597 # Ignore invalid cases |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3598 cases = [] |
38222
507bdc40bb17
run-tests: add support for running specific test cases
Boris Feld <boris.feld@octobus.net>
parents:
37741
diff
changeset
|
3599 else: |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3600 pass |
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3601 tests += [{'path': t, 'case': c} for c in sorted(cases)] |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3602 else: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3603 tests.append({'path': t}) |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3604 else: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3605 tests.append({'path': t}) |
45407
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3606 |
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3607 if self.options.retest: |
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3608 retest_args = [] |
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3609 for test in tests: |
45408
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3610 errpath = self._geterrpath(test) |
45407
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3611 if os.path.exists(errpath): |
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3612 retest_args.append(test) |
de9ec12ee53c
run-tests: refactor filtering logic for --retest flag
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45108
diff
changeset
|
3613 tests = retest_args |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3614 return tests |
21363
00e5f5b9fc90
run-tests: move test discovery logic into a function
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21362
diff
changeset
|
3615 |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3616 def _runtests(self, testdescs): |
32310
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
3617 def _reloadtest(test, i): |
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
3618 # convert a test back to its description dict |
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
3619 desc = {'path': test.path} |
38824
3086a8627b29
testrunner: allow multiple #testcases
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
3620 case = getattr(test, '_case', []) |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3621 if case: |
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3622 desc['case'] = case |
32310
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
3623 return self._gettest(desc, i) |
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
3624 |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3625 try: |
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3626 if self.options.restart: |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3627 orig = list(testdescs) |
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3628 while testdescs: |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3629 desc = testdescs[0] |
45408
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3630 errpath = self._geterrpath(desc) |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3631 if os.path.exists(errpath): |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3632 break |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3633 testdescs.pop(0) |
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3634 if not testdescs: |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
3635 print("running all tests") |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3636 testdescs = orig |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3637 |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3638 tests = [self._gettest(d, i) for i, d in enumerate(testdescs)] |
41178
53327bfbf35d
testrunner: make `-j100 --runs-per-test=100 test-foo.t` use 100 jobs
Martin von Zweigbergk <martinvonz@google.com>
parents:
41141
diff
changeset
|
3639 num_tests = len(tests) * self.options.runs_per_test |
53327bfbf35d
testrunner: make `-j100 --runs-per-test=100 test-foo.t` use 100 jobs
Martin von Zweigbergk <martinvonz@google.com>
parents:
41141
diff
changeset
|
3640 |
53327bfbf35d
testrunner: make `-j100 --runs-per-test=100 test-foo.t` use 100 jobs
Martin von Zweigbergk <martinvonz@google.com>
parents:
41141
diff
changeset
|
3641 jobs = min(num_tests, self.options.jobs) |
40244
1039404c5e1d
run-tests: print number of tests and parallel process count
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39909
diff
changeset
|
3642 |
21458
c42219733f30
run-tests: don't print results in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21457
diff
changeset
|
3643 failed = False |
25050
28526bb5b3b5
run-tests: make sure keyword(s) are in bytes and not str
Augie Fackler <augie@google.com>
parents:
25049
diff
changeset
|
3644 kws = self.options.keywords |
48866
2ccd5e71bcd3
tests: remove last references to PYTHON3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48865
diff
changeset
|
3645 if kws is not None: |
25050
28526bb5b3b5
run-tests: make sure keyword(s) are in bytes and not str
Augie Fackler <augie@google.com>
parents:
25049
diff
changeset
|
3646 kws = kws.encode('utf-8') |
21458
c42219733f30
run-tests: don't print results in unittest mode
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21457
diff
changeset
|
3647 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3648 suite = TestSuite( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3649 self._testdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3650 jobs=jobs, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3651 whitelist=self.options.whitelisted, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3652 blacklist=self.options.blacklist, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3653 keywords=kws, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3654 loop=self.options.loop, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3655 runs_per_test=self.options.runs_per_test, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3656 showchannels=self.options.showchannels, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3657 tests=tests, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3658 loadtest=_reloadtest, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3659 ) |
21464
d19164a018a1
run-tests: execute tests via unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21463
diff
changeset
|
3660 verbosity = 1 |
38620
875e033fbbdd
run-tests: fix test result verbosity
Boris Feld <boris.feld@octobus.net>
parents:
38617
diff
changeset
|
3661 if self.options.list_tests: |
875e033fbbdd
run-tests: fix test result verbosity
Boris Feld <boris.feld@octobus.net>
parents:
38617
diff
changeset
|
3662 verbosity = 0 |
875e033fbbdd
run-tests: fix test result verbosity
Boris Feld <boris.feld@octobus.net>
parents:
38617
diff
changeset
|
3663 elif self.options.verbose: |
21464
d19164a018a1
run-tests: execute tests via unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21463
diff
changeset
|
3664 verbosity = 2 |
d19164a018a1
run-tests: execute tests via unittest
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21463
diff
changeset
|
3665 runner = TextTestRunner(self, verbosity=verbosity) |
32703
9d1d3199382e
run-tests: install hg after computing tests to run
Siddharth Agarwal <sid0@fb.com>
parents:
32702
diff
changeset
|
3666 |
49833
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
3667 osenvironb.pop(b'PYOXIDIZED_IN_MEMORY_RSRC', None) |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
3668 osenvironb.pop(b'PYOXIDIZED_FILESYSTEM_RSRC', None) |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
3669 |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3670 if self.options.list_tests: |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3671 result = runner.listtests(suite) |
32703
9d1d3199382e
run-tests: install hg after computing tests to run
Siddharth Agarwal <sid0@fb.com>
parents:
32702
diff
changeset
|
3672 else: |
49497
1baf0fffd82f
run-tests: display the time it took to install Mercurial
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49496
diff
changeset
|
3673 install_start_time = time.monotonic() |
47577
2ee81806831f
run-tests: setup "correct" python earlier
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47576
diff
changeset
|
3674 self._usecorrectpython() |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3675 if self._installdir: |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3676 self._installhg() |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3677 self._checkhglib("Testing") |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3678 if self.options.chg: |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3679 assert self._installdir |
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3680 self._installchg() |
46754
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
3681 if self.options.rhg: |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
3682 assert self._installdir |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
3683 self._installrhg() |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3684 elif self.options.pyoxidized: |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
3685 self._build_pyoxidized() |
47588
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3686 self._use_correct_mercurial() |
49497
1baf0fffd82f
run-tests: display the time it took to install Mercurial
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49496
diff
changeset
|
3687 install_end_time = time.monotonic() |
1baf0fffd82f
run-tests: display the time it took to install Mercurial
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49496
diff
changeset
|
3688 if self._installdir: |
1baf0fffd82f
run-tests: display the time it took to install Mercurial
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49496
diff
changeset
|
3689 msg = 'installed Mercurial in %.2f seconds' |
1baf0fffd82f
run-tests: display the time it took to install Mercurial
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49496
diff
changeset
|
3690 msg %= install_end_time - install_start_time |
1baf0fffd82f
run-tests: display the time it took to install Mercurial
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
49496
diff
changeset
|
3691 log(msg) |
32703
9d1d3199382e
run-tests: install hg after computing tests to run
Siddharth Agarwal <sid0@fb.com>
parents:
32702
diff
changeset
|
3692 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3693 log( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3694 'running %d tests using %d parallel processes' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3695 % (num_tests, jobs) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3696 ) |
40244
1039404c5e1d
run-tests: print number of tests and parallel process count
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39909
diff
changeset
|
3697 |
32704
1270b00a385d
run-tests: add a way to list tests, with JSON and XUnit support
Siddharth Agarwal <sid0@fb.com>
parents:
32703
diff
changeset
|
3698 result = runner.run(suite) |
21613
b3213b9fafed
run-tests: exit with non-0 exit code when tests fail or warn
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21539
diff
changeset
|
3699 |
42386
15d5a2de44aa
tests: make run-tests exit non-zero if there are "errors"
Kyle Lippincott <spectral@google.com>
parents:
41804
diff
changeset
|
3700 if result.failures or result.errors: |
21613
b3213b9fafed
run-tests: exit with non-0 exit code when tests fail or warn
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21539
diff
changeset
|
3701 failed = True |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3702 |
38617
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
3703 result.onEnd() |
948691ea92a9
run-tests: extract onStart and onEnd into the test result
Boris Feld <boris.feld@octobus.net>
parents:
38616
diff
changeset
|
3704 |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3705 if self.options.anycoverage: |
21378
f7ac3c63d844
run-tests: make some methods of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21377
diff
changeset
|
3706 self._outputcoverage() |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3707 except KeyboardInterrupt: |
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3708 failed = True |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
3709 print("\ninterrupted!") |
21360
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3710 |
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3711 if failed: |
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3712 return 1 |
becce297ae0c
run-tests: move runtests() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21359
diff
changeset
|
3713 |
45408
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3714 def _geterrpath(self, test): |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3715 # test['path'] is a relative path |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3716 if 'case' in test: |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3717 # for multiple dimensions test cases |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3718 casestr = b'#'.join(test['case']) |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3719 errpath = b'%s#%s.err' % (test['path'], casestr) |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3720 else: |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3721 errpath = b'%s.err' % test['path'] |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3722 if self.options.outputdir: |
45442
c6e332a451d0
py3: fix bytes and str mixup in run-tests
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45408
diff
changeset
|
3723 self._outputdir = canonpath(_sys2bytes(self.options.outputdir)) |
c6e332a451d0
py3: fix bytes and str mixup in run-tests
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45408
diff
changeset
|
3724 errpath = os.path.join(self._outputdir, errpath) |
45408
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3725 return errpath |
543e446204c6
run-tests: extract logic to get errpath in a utility func
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
45407
diff
changeset
|
3726 |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3727 def _getport(self, count): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3728 port = self._ports.get(count) # do we have a cached entry? |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3729 if port is None: |
52288
7f8d0c2c3692
run-tests: add a 4th `HGPORT` value
Matt Harbison <matt_harbison@yahoo.com>
parents:
52232
diff
changeset
|
3730 portneeded = 4 |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3731 # above 100 tries we just give up and let test reports failure |
49285
56f98406831b
py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents:
49244
diff
changeset
|
3732 for tries in range(100): |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3733 allfree = True |
27602
67aa88e00fc7
run-tests: fix get port to try differing ports
timeless <timeless@mozdev.org>
parents:
27567
diff
changeset
|
3734 port = self.options.port + self._portoffset |
49285
56f98406831b
py3: remove xrange() compatibility code
Manuel Jacob <me@manueljacob.de>
parents:
49244
diff
changeset
|
3735 for idx in range(portneeded): |
24967
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3736 if not checkportisavailable(port + idx): |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3737 allfree = False |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3738 break |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3739 self._portoffset += portneeded |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3740 if allfree: |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3741 break |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3742 self._ports[count] = port |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3743 return port |
00790cc2b753
run-test: ensure the test ports are available before launching test
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24965
diff
changeset
|
3744 |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3745 def _gettest(self, testdesc, count): |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3746 """Obtain a Test by looking at its filename. |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3747 |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3748 Returns a Test instance. The Test may not be runnable if it doesn't |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3749 map to a known type. |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3750 """ |
32311
a77a75a428f7
run-tests: rename test description dict to testdesc
Jun Wu <quark@fb.com>
parents:
32310
diff
changeset
|
3751 path = testdesc['path'] |
32310
b96be0098624
run-tests: change test identity from a path to a dict
Jun Wu <quark@fb.com>
parents:
32303
diff
changeset
|
3752 lctest = path.lower() |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3753 testcls = Test |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3754 |
21501
98a0c58ee200
run-tests: factor refpath into Test classes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21500
diff
changeset
|
3755 for ext, cls in self.TESTTYPES: |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3756 if lctest.endswith(ext): |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3757 testcls = cls |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3758 break |
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3759 |
40487
78e5b9d815fa
test: fix self._testdir to use the right mercurial library during testing
Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
parents:
40479
diff
changeset
|
3760 refpath = os.path.join(getcwdb(), path) |
25041
09c71e3da704
run-tests: even more bytestring annotations for Python 3
Augie Fackler <augie@google.com>
parents:
25040
diff
changeset
|
3761 tmpdir = os.path.join(self._hgtmp, b'child%d' % count) |
21504
888a5dfe1569
run-tests: pass temp dir into Test.__init__
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21502
diff
changeset
|
3762 |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3763 # extra keyword parameters. 'case' is used by .t tests |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44449
diff
changeset
|
3764 kwds = {k: testdesc[k] for k in ['case'] if k in testdesc} |
32316
7340465bd788
run-tests: support multiple cases in .t test
Jun Wu <quark@fb.com>
parents:
32311
diff
changeset
|
3765 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3766 t = testcls( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3767 refpath, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3768 self._outputdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3769 tmpdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3770 keeptmpdir=self.options.keep_tmpdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3771 debug=self.options.debug, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3772 first=self.options.first, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3773 timeout=self.options.timeout, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3774 startport=self._getport(count), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3775 extraconfigopts=self.options.extra_config_opt, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3776 shell=self.options.shell, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3777 hgcommand=self._hgcommand, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3778 usechg=bool(self.options.with_chg or self.options.chg), |
44615
78a8f65eacc8
run-tests: add --chg-debug flag to show chg debug output
Pulkit Goyal <7895pulkit@gmail.com>
parents:
44577
diff
changeset
|
3779 chgdebug=self.options.chg_debug, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3780 useipv6=useipv6, |
51993
daeb85ebee48
run-test: add regular line break and test count in the dot output
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
51963
diff
changeset
|
3781 **kwds, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
3782 ) |
24330
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
3783 t.should_reload = True |
799bc18e14d1
run-tests: avoid running the same test instance concurrently
Augie Fackler <augie@google.com>
parents:
24329
diff
changeset
|
3784 return t |
21357
4c4f64b8df3c
run-tests: move gettest() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21356
diff
changeset
|
3785 |
21366
5047248536c5
run-tests: establish TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21365
diff
changeset
|
3786 def _cleanup(self): |
21350
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3787 """Clean up state from this test invocation.""" |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3788 if self.options.keep_tmpdir: |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3789 return |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3790 |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
3791 vlog("# Cleaning up HGTMP", _bytes2sys(self._hgtmp)) |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
3792 shutil.rmtree(self._hgtmp, True) |
21352
39fd89fbbc3c
run-tests: move createdfiles out of a global and into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21351
diff
changeset
|
3793 for f in self._createdfiles: |
21350
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3794 try: |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3795 os.remove(f) |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3796 except OSError: |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3797 pass |
dfcef61f5bd4
run-tests: move cleanup() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21349
diff
changeset
|
3798 |
21378
f7ac3c63d844
run-tests: make some methods of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21377
diff
changeset
|
3799 def _usecorrectpython(self): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
3800 """Configure the environment to use the appropriate Python in tests.""" |
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
3801 # Tests must use the same interpreter as us or bad things will happen. |
52230
7a568296296e
windows: simply rely on the PATH adjustment to find python.exe in tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52215
diff
changeset
|
3802 pyexe_names = [b'python', b'python3'] |
39647
543a788eea2d
py3: allow run-tests.py to run on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
39646
diff
changeset
|
3803 |
543a788eea2d
py3: allow run-tests.py to run on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
39646
diff
changeset
|
3804 # os.symlink() is a thing with py3 on Windows, but it requires |
543a788eea2d
py3: allow run-tests.py to run on Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
39646
diff
changeset
|
3805 # Administrator rights. |
47639
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3806 if not WINDOWS and getattr(os, 'symlink', None): |
47494
81d70de39c7e
run-tests: unroll a non-so-one-liner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
3807 msg = "# Making python executable in test path a symlink to '%s'" |
81d70de39c7e
run-tests: unroll a non-so-one-liner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
3808 msg %= sysexecutable |
81d70de39c7e
run-tests: unroll a non-so-one-liner
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47312
diff
changeset
|
3809 vlog(msg) |
47500
23f5ed6dbcb1
run-tests: stop writing a `python3` symlink pointing to python2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47498
diff
changeset
|
3810 for pyexename in pyexe_names: |
47575
27fb9f32e1a3
run-tests: always define a custom-bin directory
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47574
diff
changeset
|
3811 mypython = os.path.join(self._custom_bin_dir, pyexename) |
21351
fe5647506565
run-tests: move usecorrectpython() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21350
diff
changeset
|
3812 try: |
47498
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3813 if os.readlink(mypython) == sysexecutable: |
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3814 continue |
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3815 os.unlink(mypython) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
3816 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
3817 pass |
47498
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3818 if self._findprogram(pyexename) != sysexecutable: |
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3819 try: |
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3820 os.symlink(sysexecutable, mypython) |
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3821 self._createdfiles.append(mypython) |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
3822 except FileExistsError: |
47498
9d929f9cb9b4
run-tests: avoid an early return
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47497
diff
changeset
|
3823 # child processes may race, which is harmless |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
3824 pass |
47639
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3825 elif WINDOWS and not os.getenv('MSYSTEM'): |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3826 raise AssertionError('cannot run test on Windows without MSYSTEM') |
21351
fe5647506565
run-tests: move usecorrectpython() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21350
diff
changeset
|
3827 else: |
47639
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3828 # Generate explicit file instead of symlink |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3829 # |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3830 # This is especially important as Windows doesn't have |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3831 # `python3.exe`, and MSYS cannot understand the reparse point with |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3832 # that name provided by Microsoft. Create a simple script on PATH |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3833 # with that name that delegates to the py3 launcher so the shebang |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3834 # lines work. |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3835 esc_executable = _sys2bytes(shellquote(sysexecutable)) |
47500
23f5ed6dbcb1
run-tests: stop writing a `python3` symlink pointing to python2
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47498
diff
changeset
|
3836 for pyexename in pyexe_names: |
47639
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3837 stub_exec_path = os.path.join(self._custom_bin_dir, pyexename) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3838 with open(stub_exec_path, 'wb') as f: |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3839 f.write(b'#!/bin/sh\n') |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3840 f.write(b'%s "$@"\n' % esc_executable) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3841 |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3842 if WINDOWS: |
52230
7a568296296e
windows: simply rely on the PATH adjustment to find python.exe in tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52215
diff
changeset
|
3843 # adjust the path to make sur the main python finds itself and |
7a568296296e
windows: simply rely on the PATH adjustment to find python.exe in tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52215
diff
changeset
|
3844 # its own dll |
47639
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3845 path = os.environ['PATH'].split(os.pathsep) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3846 main_exec_dir = os.path.dirname(sysexecutable) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3847 extra_paths = [_bytes2sys(self._custom_bin_dir), main_exec_dir] |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3848 |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3849 # Binaries installed by pip into the user area like pylint.exe may |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3850 # not be in PATH by default. |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3851 appdata = os.environ.get('APPDATA') |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3852 vi = sys.version_info |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3853 if appdata is not None: |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3854 python_dir = 'Python%d%d' % (vi[0], vi[1]) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3855 scripts_path = [appdata, 'Python', python_dir, 'Scripts'] |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3856 scripts_dir = os.path.join(*scripts_path) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3857 extra_paths.append(scripts_dir) |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3858 |
e1130abae834
run-test: rework the redirection script for python on windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47638
diff
changeset
|
3859 os.environ['PATH'] = os.pathsep.join(extra_paths + path) |
21351
fe5647506565
run-tests: move usecorrectpython() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21350
diff
changeset
|
3860 |
47588
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3861 def _use_correct_mercurial(self): |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3862 target_exec = os.path.join(self._custom_bin_dir, b'hg') |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3863 if self._hgcommand != b'hg': |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3864 # shutil.which only accept bytes from 3.8 |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3865 real_exec = which(self._hgcommand) |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3866 if real_exec is None: |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3867 raise ValueError('could not find exec path for "%s"', real_exec) |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3868 if real_exec == target_exec: |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3869 # do not overwrite something with itself |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3870 return |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3871 if WINDOWS: |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3872 with open(target_exec, 'wb') as f: |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3873 f.write(b'#!/bin/sh\n') |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3874 escaped_exec = shellquote(_bytes2sys(real_exec)) |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3875 f.write(b'%s "$@"\n' % _sys2bytes(escaped_exec)) |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3876 else: |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3877 os.symlink(real_exec, target_exec) |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3878 self._createdfiles.append(target_exec) |
eb611ecb435c
run-tests: rely on an actual executable in PATH instead of alias for `hg`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47586
diff
changeset
|
3879 |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3880 def _install_hg_cmd_wheel(self): |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3881 wheel_path = self.options.wheel |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3882 assert wheel_path |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3883 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3884 # TODO: actually use these flag later, to double check the wheel we |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3885 # installed match our intend (in `_checkhglib`) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3886 if self.options.pure: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3887 assert False, b"--pure" |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3888 elif self.options.rust: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3889 assert False, b"--rust" |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3890 elif self.options.no_rust: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3891 assert False, b"--no-rust" |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3892 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3893 script = _sys2bytes(os.path.realpath(sys.argv[0])) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3894 exe = _sys2bytes(sysexecutable) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3895 hgroot = os.path.dirname(os.path.dirname(script)) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3896 self._hgroot = hgroot |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3897 os.chdir(hgroot) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3898 cmd = [ |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3899 exe, |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3900 b"-m", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3901 b"pip", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3902 b"install", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3903 wheel_path, |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3904 b"--force", |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3905 b"--ignore-installed", |
52204
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3906 b"--prefix", |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3907 self._installdir, |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3908 ] |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3909 if not WINDOWS: |
52232
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3910 # windows does not have this flag apparently. |
763817eca85e
wheel: make --hg-wheel works on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52230
diff
changeset
|
3911 cmd.append(b"--break-system-packages") |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3912 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3913 return cmd |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3914 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3915 def _install_hg_cmd_setup(self): |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3916 # Run installer in hg root |
44488
0d9ad84a28d9
run-tests: rename "pure" variable to setup_opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44470
diff
changeset
|
3917 setup_opts = b"" |
24306
6ddc86eedc3b
style: kill ersatz if-else ternary operators
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
24075
diff
changeset
|
3918 if self.options.pure: |
44488
0d9ad84a28d9
run-tests: rename "pure" variable to setup_opts
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
44470
diff
changeset
|
3919 setup_opts = b"--pure" |
44489
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3920 elif self.options.rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3921 setup_opts = b"--rust" |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3922 elif self.options.no_rust: |
9183b7dcfa8d
run-tests: add option for running with and without Rust extensions
Raphaël Gomès <rgomes@octobus.net>
parents:
44488
diff
changeset
|
3923 setup_opts = b"--no-rust" |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3924 |
48862
2336e79a119c
tests: remove Python 3 conditionalizing from variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48861
diff
changeset
|
3925 script = _sys2bytes(os.path.realpath(sys.argv[0])) |
2336e79a119c
tests: remove Python 3 conditionalizing from variables
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48861
diff
changeset
|
3926 exe = _sys2bytes(sysexecutable) |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
3927 hgroot = os.path.dirname(os.path.dirname(script)) |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
3928 self._hgroot = hgroot |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
3929 os.chdir(hgroot) |
52147
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3930 cmd = [ |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3931 exe, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3932 b"setup.py", |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3933 ] |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3934 if setup_opts: |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3935 cmd.append(setup_opts) |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3936 cmd.extend( |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3937 [ |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3938 b"clean", |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3939 b"--all", |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3940 b"build", |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3941 ] |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3942 ) |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3943 if self.options.compiler: |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3944 cmd.append("--compiler") |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3945 cmd.append(_sys2bytes(self.options.compiler)) |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3946 cmd.extend( |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3947 [ |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3948 b"--build-base=%s" % os.path.join(self._hgtmp, b"build"), |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3949 b"install", |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3950 b"--force", |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3951 b"--prefix=%s" % self._installdir, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3952 b"--install-lib=%s" % self._pythondir, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3953 b"--install-scripts=%s" % self._bindir, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3954 ] |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3955 ) |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3956 if not WINDOWS: |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
3957 # The --home="" trick works only on OS where os.sep == '/' |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
3958 # because of a distutils convert_path() fast-path. Avoid it at |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
3959 # least on Windows for now, deal with .pydistutils.cfg bugs |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
3960 # when they happen. |
52147
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3961 cmd.append(b"--home=") |
24075
4bf484276787
run-tests: ensure install directories exist
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24074
diff
changeset
|
3962 |
52148
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3963 return cmd |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3964 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3965 def _installhg(self): |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3966 """Install hg into the test environment. |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3967 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3968 This will also configure hg with the appropriate testing settings. |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3969 """ |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3970 vlog("# Performing temporary installation of HG") |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3971 install_env = original_env.copy() |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3972 if self.options.wheel is None: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3973 cmd = self._install_hg_cmd_setup() |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3974 else: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3975 cmd = self._install_hg_cmd_wheel() |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3976 install_env["PYTHONUSERBASE"] = _bytes2sys(self._installdir) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3977 |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3978 installerrs = os.path.join(self._hgtmp, b"install.err") |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3979 if self.options.pure: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3980 install_env.pop('HGWITHRUSTEXT', None) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3981 elif self.options.no_rust: |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3982 install_env.pop('HGWITHRUSTEXT', None) |
1dbbb957bbe6
run-tests: add a --hg-wheel options to test a pre-built wheel
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52147
diff
changeset
|
3983 |
24075
4bf484276787
run-tests: ensure install directories exist
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24074
diff
changeset
|
3984 # setuptools requires install directories to exist. |
52205
ba0a842e0907
pycompat: drop some now useless workaround for makedirs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52204
diff
changeset
|
3985 os.makedirs(self._pythondir, exist_ok=True) |
ba0a842e0907
pycompat: drop some now useless workaround for makedirs
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52204
diff
changeset
|
3986 os.makedirs(self._bindir, exist_ok=True) |
52204
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3987 if self.options.wheel is not None and not WINDOWS: |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3988 # the wheel instalation location is not stable, so try to deal with |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3989 # that to funnel it back where we need its. |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3990 # |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3991 # (mostly deals with Debian shenanigans) |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3992 assert self._pythondir.endswith(b'site-packages') |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3993 lib_dir = os.path.dirname(self._pythondir) |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3994 dist_dir = os.path.join(lib_dir, b'dist-packages') |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3995 os.symlink(b'./site-packages', dist_dir) |
f8d5001dd03e
run-tests: install wheel using --prefix instead of --user
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52148
diff
changeset
|
3996 os.symlink(b'.', os.path.join(self._installdir, b'local')) |
24075
4bf484276787
run-tests: ensure install directories exist
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24074
diff
changeset
|
3997 |
52147
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3998 vlog("# Running", cmd) |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
3999 with open(installerrs, "wb") as logfile: |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4000 r = subprocess.call( |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4001 cmd, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4002 env=install_env, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4003 stdout=logfile, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4004 stderr=subprocess.STDOUT, |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4005 ) |
6f7cc970bfda
run-tests: don't use shell call for subprocess
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
52008
diff
changeset
|
4006 if r == 0: |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4007 if not self.options.verbose: |
26087
06cd67a5044f
run-tests: ignore failed removal of nonexistent installerrs
Augie Fackler <augie@google.com>
parents:
25730
diff
changeset
|
4008 try: |
06cd67a5044f
run-tests: ignore failed removal of nonexistent installerrs
Augie Fackler <augie@google.com>
parents:
25730
diff
changeset
|
4009 os.remove(installerrs) |
49306
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
4010 except FileNotFoundError: |
2e726c934fcd
py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents:
49305
diff
changeset
|
4011 pass |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4012 else: |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
4013 with open(installerrs, 'rb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
4014 for line in f: |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
4015 sys.stdout.buffer.write(line) |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4016 sys.exit(1) |
21534
3ece55d16044
run-tests: make attributes of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21533
diff
changeset
|
4017 os.chdir(self._testdir) |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4018 |
25044
9de94acfde8a
run-tests: fix installation of hg by bytesifying more constants
Augie Fackler <augie@google.com>
parents:
25042
diff
changeset
|
4019 hgbat = os.path.join(self._bindir, b'hg.bat') |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4020 if os.path.isfile(hgbat): |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4021 # hg.bat expects to be put in bin/scripts while run-tests.py |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4022 # installation layout put it in bin/ directly. Fix it |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
4023 with open(hgbat, 'rb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
4024 data = f.read() |
41540
17a6e063c886
run-tests: use raw strings for regular expressions
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41495
diff
changeset
|
4025 if br'"%~dp0..\python" "%~dp0hg" %*' in data: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4026 data = data.replace( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4027 br'"%~dp0..\python" "%~dp0hg" %*', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4028 b'"%~dp0python" "%~dp0hg" %*', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4029 ) |
35450
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
4030 with open(hgbat, 'wb') as f: |
e31773898197
run-tests: use context managers for file descriptors
Matt Harbison <matt_harbison@yahoo.com>
parents:
35449
diff
changeset
|
4031 f.write(data) |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4032 else: |
25031
0adc22a0b6b3
python3: update killdaemons and run-tests print and exception syntax
Augie Fackler <augie@google.com>
parents:
24984
diff
changeset
|
4033 print('WARNING: cannot fix hg.bat reference to python.exe') |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4034 |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4035 if self.options.anycoverage: |
43283
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4036 custom = os.path.join( |
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4037 osenvironb[b'RUNTESTDIR'], b'sitecustomize.py' |
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4038 ) |
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4039 target = os.path.join(self._pythondir, b'sitecustomize.py') |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4040 vlog('# Installing coverage trigger to %s' % target) |
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4041 shutil.copyfile(custom, target) |
43283
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4042 rc = os.path.join(self._testdir, b'.coveragerc') |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4043 vlog('# Installing coverage rc to %s' % rc) |
43283
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4044 osenvironb[b'COVERAGE_PROCESS_START'] = rc |
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4045 covdir = os.path.join(self._installdir, b'..', b'coverage') |
24505
031947baf4d0
run-tests: collect aggregate code coverage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24504
diff
changeset
|
4046 try: |
031947baf4d0
run-tests: collect aggregate code coverage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24504
diff
changeset
|
4047 os.mkdir(covdir) |
49305
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
4048 except FileExistsError: |
53e9422a9b45
py3: catch FileExistsError instead of checking errno == EEXIST
Manuel Jacob <me@manueljacob.de>
parents:
49285
diff
changeset
|
4049 pass |
24505
031947baf4d0
run-tests: collect aggregate code coverage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24504
diff
changeset
|
4050 |
43283
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4051 osenvironb[b'COVERAGE_DIR'] = covdir |
21353
a42a5195a182
run-tests: move installhg() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21352
diff
changeset
|
4052 |
21378
f7ac3c63d844
run-tests: make some methods of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21377
diff
changeset
|
4053 def _checkhglib(self, verb): |
21354
29629ef43d39
run-tests: move checkhglib into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21353
diff
changeset
|
4054 """Ensure that the 'mercurial' package imported by python is |
29629ef43d39
run-tests: move checkhglib into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21353
diff
changeset
|
4055 the one we expect it to be. If not, print a warning to stderr.""" |
47574
2b2f5cf979c3
run-tests: explicitly track that `pythondir` was inferred
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47573
diff
changeset
|
4056 if self._pythondir_inferred: |
23139
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23077
diff
changeset
|
4057 # The pythondir has been inferred from --with-hg flag. |
e53f6b72a0e4
spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents:
23077
diff
changeset
|
4058 # We cannot expect anything sensible here. |
21733
9ad11d5bcc2f
run-tests: don't check for the mercurial library used when using --with-hg
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21614
diff
changeset
|
4059 return |
25044
9de94acfde8a
run-tests: fix installation of hg by bytesifying more constants
Augie Fackler <augie@google.com>
parents:
25042
diff
changeset
|
4060 expecthg = os.path.join(self._pythondir, b'mercurial') |
21385
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4061 actualhg = self._gethgpath() |
21354
29629ef43d39
run-tests: move checkhglib into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21353
diff
changeset
|
4062 if os.path.abspath(actualhg) != os.path.abspath(expecthg): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4063 sys.stderr.write( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4064 'warning: %s with unexpected mercurial lib: %s\n' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4065 ' (expected %s)\n' % (verb, actualhg, expecthg) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4066 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4067 |
21385
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4068 def _gethgpath(self): |
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4069 """Return the path to the mercurial package that is actually found by |
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4070 the current Python interpreter.""" |
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4071 if self._hgpath is not None: |
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4072 return self._hgpath |
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4073 |
40930
fcdff048a8e5
py3: teach run-tests.py to handle exe with spaces when --local isn't specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
40491
diff
changeset
|
4074 cmd = b'"%s" -c "import mercurial; print (mercurial.__path__[0])"' |
48863
c76255cde807
tests: unconditionalize _bytes2sys()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48862
diff
changeset
|
4075 cmd = _bytes2sys(cmd % PYTHON) |
40930
fcdff048a8e5
py3: teach run-tests.py to handle exe with spaces when --local isn't specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
40491
diff
changeset
|
4076 |
fcdff048a8e5
py3: teach run-tests.py to handle exe with spaces when --local isn't specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
40491
diff
changeset
|
4077 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) |
fcdff048a8e5
py3: teach run-tests.py to handle exe with spaces when --local isn't specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
40491
diff
changeset
|
4078 out, err = p.communicate() |
fcdff048a8e5
py3: teach run-tests.py to handle exe with spaces when --local isn't specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
40491
diff
changeset
|
4079 |
fcdff048a8e5
py3: teach run-tests.py to handle exe with spaces when --local isn't specified
Matt Harbison <matt_harbison@yahoo.com>
parents:
40491
diff
changeset
|
4080 self._hgpath = out.strip() |
21385
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4081 |
28414e5ac9ec
run-tests: move _gethgpath() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21384
diff
changeset
|
4082 return self._hgpath |
21354
29629ef43d39
run-tests: move checkhglib into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21353
diff
changeset
|
4083 |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4084 def _installchg(self): |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4085 """Install chg into the test environment""" |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4086 vlog('# Performing temporary installation of CHG') |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4087 assert os.path.dirname(self._bindir) == self._installdir |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4088 assert self._hgroot, 'must be called after _installhg()' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4089 cmd = b'"%(make)s" clean install PREFIX="%(prefix)s"' % { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4090 b'make': b'make', # TODO: switch by option or environment? |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4091 b'prefix': self._installdir, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4092 } |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4093 cwd = os.path.join(self._hgroot, b'contrib', b'chg') |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4094 vlog("# Running", cmd) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4095 proc = subprocess.Popen( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4096 cmd, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4097 shell=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4098 cwd=cwd, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4099 stdin=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4100 stdout=subprocess.PIPE, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4101 stderr=subprocess.STDOUT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4102 ) |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4103 out, _err = proc.communicate() |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4104 if proc.returncode != 0: |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
4105 sys.stdout.buffer.write(out) |
28143
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4106 sys.exit(1) |
c754996fd41f
run-tests: add --chg option to install and run tests using chg
Yuya Nishihara <yuya@tcha.org>
parents:
28142
diff
changeset
|
4107 |
46754
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4108 def _installrhg(self): |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4109 """Install rhg into the test environment""" |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4110 vlog('# Performing temporary installation of rhg') |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4111 assert os.path.dirname(self._bindir) == self._installdir |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4112 assert self._hgroot, 'must be called after _installhg()' |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4113 cmd = b'"%(make)s" install-rhg PREFIX="%(prefix)s"' % { |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4114 b'make': b'make', # TODO: switch by option or environment? |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4115 b'prefix': self._installdir, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4116 } |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4117 cwd = self._hgroot |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4118 vlog("# Running", cmd) |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4119 proc = subprocess.Popen( |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4120 cmd, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4121 shell=True, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4122 cwd=cwd, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4123 stdin=subprocess.PIPE, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4124 stdout=subprocess.PIPE, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4125 stderr=subprocess.STDOUT, |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4126 ) |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4127 out, _err = proc.communicate() |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4128 if proc.returncode != 0: |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
4129 sys.stdout.buffer.write(out) |
46754
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4130 sys.exit(1) |
9ba00a9dc6ea
run-test: install rhg if --rhg is passed
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
46724
diff
changeset
|
4131 |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4132 def _build_pyoxidized(self): |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4133 """build a pyoxidized version of mercurial into the test environment |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4134 |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4135 Ideally this function would be `install_pyoxidier` and would both build |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4136 and install pyoxidier. However we are starting small to get pyoxidizer |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4137 build binary to testing quickly. |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4138 """ |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4139 vlog('# build a pyoxidized version of Mercurial') |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4140 assert os.path.dirname(self._bindir) == self._installdir |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4141 assert self._hgroot, 'must be called after _installhg()' |
49832
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4142 target = b'' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4143 if WINDOWS: |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4144 target = b'windows' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4145 elif MACOS: |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4146 target = b'macos' |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4147 |
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4148 cmd = b'"%(make)s" pyoxidizer-%(platform)s-tests' % { |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4149 b'make': b'make', |
49832
9a4c76cc8fe6
run-tests: support --pyoxidized on macOS
Matt Harbison <matt_harbison@yahoo.com>
parents:
49497
diff
changeset
|
4150 b'platform': target, |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4151 } |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4152 cwd = self._hgroot |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4153 vlog("# Running", cmd) |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4154 proc = subprocess.Popen( |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4155 _bytes2sys(cmd), |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4156 shell=True, |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4157 cwd=_bytes2sys(cwd), |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4158 stdin=subprocess.PIPE, |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4159 stdout=subprocess.PIPE, |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4160 stderr=subprocess.STDOUT, |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4161 ) |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4162 out, _err = proc.communicate() |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4163 if proc.returncode != 0: |
48857
41c552a20716
tests: collapse some more trivial if PYTHON3 blocks
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48856
diff
changeset
|
4164 sys.stdout.buffer.write(out) |
47826
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4165 sys.exit(1) |
83235fb50e1c
run-tests: introduce a --pyoxidized option
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47776
diff
changeset
|
4166 |
49833
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4167 cmd = _bytes2sys(b"%s debuginstall -Tjson" % self._hgcommand) |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4168 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4169 out, err = p.communicate() |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4170 |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4171 props = json.loads(out)[0] |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4172 |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4173 # Affects hghave.py |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4174 osenvironb.pop(b'PYOXIDIZED_IN_MEMORY_RSRC', None) |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4175 osenvironb.pop(b'PYOXIDIZED_FILESYSTEM_RSRC', None) |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4176 if props["hgmodules"] == props["pythonexe"]: |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4177 osenvironb[b'PYOXIDIZED_IN_MEMORY_RSRC'] = b'1' |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4178 else: |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4179 osenvironb[b'PYOXIDIZED_FILESYSTEM_RSRC'] = b'1' |
a2356e15200a
hghave: add predicates for embedded and filesystem pyoxidizer resources
Matt Harbison <matt_harbison@yahoo.com>
parents:
49832
diff
changeset
|
4180 |
21378
f7ac3c63d844
run-tests: make some methods of TestRunner internal
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21377
diff
changeset
|
4181 def _outputcoverage(self): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
4182 """Produce code coverage output.""" |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
4183 import coverage |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4184 |
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
29282
diff
changeset
|
4185 coverage = coverage.coverage |
21356
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4186 |
24504
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4187 vlog('# Producing coverage report') |
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4188 # chdir is the easiest way to get short, relative paths in the |
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4189 # output. |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
4190 os.chdir(self._hgroot) |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4191 covdir = os.path.join(_bytes2sys(self._installdir), '..', 'coverage') |
24505
031947baf4d0
run-tests: collect aggregate code coverage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24504
diff
changeset
|
4192 cov = coverage(data_file=os.path.join(covdir, 'cov')) |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
4193 |
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
4194 # Map install directory paths back to source directory. |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4195 cov.config.paths['srcdir'] = ['.', _bytes2sys(self._pythondir)] |
24506
60bbb4079c28
run-tests: report code coverage from source directory
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24505
diff
changeset
|
4196 |
24505
031947baf4d0
run-tests: collect aggregate code coverage
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24504
diff
changeset
|
4197 cov.combine() |
21356
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4198 |
43283
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4199 omit = [ |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4200 _bytes2sys(os.path.join(x, b'*')) |
43283
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4201 for x in [self._bindir, self._testdir] |
96eb9ef777a8
run-tests: make code coverage work on Python 3
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43076
diff
changeset
|
4202 ] |
24504
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4203 cov.report(ignore_errors=True, omit=omit) |
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4204 |
21356
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4205 if self.options.htmlcov: |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4206 htmldir = os.path.join(_bytes2sys(self._outputdir), 'htmlcov') |
24504
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4207 cov.html_report(directory=htmldir, omit=omit) |
21356
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4208 if self.options.annotate: |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4209 adir = os.path.join(_bytes2sys(self._outputdir), 'annotated') |
21356
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4210 if not os.path.isdir(adir): |
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4211 os.mkdir(adir) |
24504
7046ecabd9a8
run-tests: obtain code coverage via Python API
Gregory Szorc <gregory.szorc@gmail.com>
parents:
24500
diff
changeset
|
4212 cov.annotate(directory=adir, omit=omit) |
21356
f96d7dfd8cb5
run-tests: move outputcoverage() into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21355
diff
changeset
|
4213 |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4214 def _findprogram(self, program): |
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4215 """Search PATH for a executable program""" |
44448
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4216 dpb = _sys2bytes(os.defpath) |
55c443fcb4fc
tests: rename _bytespath() to _sys2bytes() and _strpath() to _sys2str()
Manuel Jacob <me@manueljacob.de>
parents:
44447
diff
changeset
|
4217 sepb = _sys2bytes(os.pathsep) |
25038
66da89457c47
run-tests: fix _findprogram to reliably return bytes
Augie Fackler <augie@google.com>
parents:
25037
diff
changeset
|
4218 for p in osenvironb.get(b'PATH', dpb).split(sepb): |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4219 name = os.path.join(p, program) |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
4220 if WINDOWS or os.access(name, os.X_OK): |
45031
383005aa9cdc
run-tests: find python binary on Python 3 (issue6361)
Axel Hecht <axel@pike.org>
parents:
45013
diff
changeset
|
4221 return _bytes2sys(name) |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4222 return None |
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4223 |
21374
592b3d2616d7
run-tests: move checktools into TestRunner.run()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21373
diff
changeset
|
4224 def _checktools(self): |
21536
92a6b16c9186
run-tests: add docstrings
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21535
diff
changeset
|
4225 """Ensure tools required to run tests are present.""" |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4226 for p in self.REQUIREDTOOLS: |
47573
75b623801f6a
run-tests: use a global WINDOWS constant instead of multiple tests
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47571
diff
changeset
|
4227 if WINDOWS and not p.endswith(b'.exe'): |
39589
4eb0f2452ad7
py3: add b'' to some run-tests.py strings for Windows
Matt Harbison <matt_harbison@yahoo.com>
parents:
39403
diff
changeset
|
4228 p += b'.exe' |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4229 found = self._findprogram(p) |
43309
b4b1131187c4
py3: decode bytes before logging in run-tests.py
Denis Laxalde <denis@laxalde.org>
parents:
43283
diff
changeset
|
4230 p = p.decode("utf-8") |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4231 if found: |
45031
383005aa9cdc
run-tests: find python binary on Python 3 (issue6361)
Axel Hecht <axel@pike.org>
parents:
45013
diff
changeset
|
4232 vlog("# Found prerequisite", p, "at", found) |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4233 else: |
43309
b4b1131187c4
py3: decode bytes before logging in run-tests.py
Denis Laxalde <denis@laxalde.org>
parents:
43283
diff
changeset
|
4234 print("WARNING: Did not find prerequisite tool: %s " % p) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4235 |
21365
10cf9054d941
run-tests: move program searching into TestRunner
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21364
diff
changeset
|
4236 |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4237 def aggregateexceptions(path): |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4238 exceptioncounts = collections.Counter() |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4239 testsbyfailure = collections.defaultdict(set) |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4240 failuresbytest = collections.defaultdict(set) |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4241 |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4242 for f in os.listdir(path): |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4243 with open(os.path.join(path, f), 'rb') as fh: |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4244 data = fh.read().split(b'\0') |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4245 if len(data) != 5: |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4246 continue |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4247 |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4248 exc, mainframe, hgframe, hgline, testname = data |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4249 exc = exc.decode('utf-8') |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4250 mainframe = mainframe.decode('utf-8') |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4251 hgframe = hgframe.decode('utf-8') |
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4252 hgline = hgline.decode('utf-8') |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4253 testname = testname.decode('utf-8') |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4254 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4255 key = (hgframe, hgline, exc) |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4256 exceptioncounts[key] += 1 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4257 testsbyfailure[key].add(testname) |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4258 failuresbytest[testname].add(key) |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4259 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4260 # Find test having fewest failures for each failure. |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4261 leastfailing = {} |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4262 for key, tests in testsbyfailure.items(): |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4263 fewesttest = None |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4264 fewestcount = 99999999 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4265 for test in sorted(tests): |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4266 if len(failuresbytest[test]) < fewestcount: |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4267 fewesttest = test |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4268 fewestcount = len(failuresbytest[test]) |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4269 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4270 leastfailing[key] = (fewestcount, fewesttest) |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4271 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4272 # Create a combined counter so we can sort by total occurrences and |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4273 # impacted tests. |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4274 combined = {} |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4275 for key in exceptioncounts: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4276 combined[key] = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4277 exceptioncounts[key], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4278 len(testsbyfailure[key]), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4279 leastfailing[key][0], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4280 leastfailing[key][1], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4281 ) |
36037
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4282 |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4283 return { |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4284 'exceptioncounts': exceptioncounts, |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4285 'total': sum(exceptioncounts.values()), |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4286 'combined': combined, |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4287 'leastfailing': leastfailing, |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4288 'byfailure': testsbyfailure, |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4289 'bytest': failuresbytest, |
8de90e006c78
run-tests: report tests that exception occurred in
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35991
diff
changeset
|
4290 } |
35190
bd8875b6473c
run-tests: mechanism to report exceptions during test execution
Gregory Szorc <gregory.szorc@gmail.com>
parents:
35189
diff
changeset
|
4291 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4292 |
13347
ce07defe7d9f
run-tests: loadable as module
Simon Heimberg <simohe@besonet.ch>
parents:
13031
diff
changeset
|
4293 if __name__ == '__main__': |
47638
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4294 if WINDOWS and not os.getenv('MSYSTEM'): |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4295 print('cannot run test on Windows without MSYSTEM', file=sys.stderr) |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4296 print( |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4297 '(if you need to do so contact the mercurial devs: ' |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4298 'mercurial@mercurial-scm.org)', |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4299 file=sys.stderr, |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4300 ) |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4301 sys.exit(255) |
55a715c36e3b
run-test: act that we requires MSYS to run the test on Windows
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
47619
diff
changeset
|
4302 |
21377
71081f7f9e52
run-tests: eliminate main()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21376
diff
changeset
|
4303 runner = TestRunner() |
22120
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4304 |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4305 try: |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4306 import msvcrt |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43073
diff
changeset
|
4307 |
22120
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4308 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4309 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4310 msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4311 except ImportError: |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4312 pass |
68a7ef4311ce
run-tests: self-test on Windows needs binary streams
Matt Mackall <mpm@selenic.com>
parents:
21919
diff
changeset
|
4313 |
21377
71081f7f9e52
run-tests: eliminate main()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
21376
diff
changeset
|
4314 sys.exit(runner.run(sys.argv[1:])) |