Show More
@@ -1,3955 +1,3955 | |||
|
1 | 1 | #!/usr/bin/env python3 |
|
2 | 2 | # |
|
3 | 3 | # run-tests.py - Run a set of tests on Mercurial |
|
4 | 4 | # |
|
5 | 5 | # Copyright 2006 Olivia Mackall <olivia@selenic.com> |
|
6 | 6 | # |
|
7 | 7 | # This software may be used and distributed according to the terms of the |
|
8 | 8 | # GNU General Public License version 2 or any later version. |
|
9 | 9 | |
|
10 | 10 | # Modifying this script is tricky because it has many modes: |
|
11 | 11 | # - serial (default) vs parallel (-jN, N > 1) |
|
12 | 12 | # - no coverage (default) vs coverage (-c, -C, -s) |
|
13 | 13 | # - temp install (default) vs specific hg script (--with-hg, --local) |
|
14 | 14 | # - tests are a mix of shell scripts and Python scripts |
|
15 | 15 | # |
|
16 | 16 | # If you change this script, it is recommended that you ensure you |
|
17 | 17 | # haven't broken it by running it in various modes with a representative |
|
18 | 18 | # sample of test scripts. For example: |
|
19 | 19 | # |
|
20 | 20 | # 1) serial, no coverage, temp install: |
|
21 | 21 | # ./run-tests.py test-s* |
|
22 | 22 | # 2) serial, no coverage, local hg: |
|
23 | 23 | # ./run-tests.py --local test-s* |
|
24 | 24 | # 3) serial, coverage, temp install: |
|
25 | 25 | # ./run-tests.py -c test-s* |
|
26 | 26 | # 4) serial, coverage, local hg: |
|
27 | 27 | # ./run-tests.py -c --local test-s* # unsupported |
|
28 | 28 | # 5) parallel, no coverage, temp install: |
|
29 | 29 | # ./run-tests.py -j2 test-s* |
|
30 | 30 | # 6) parallel, no coverage, local hg: |
|
31 | 31 | # ./run-tests.py -j2 --local test-s* |
|
32 | 32 | # 7) parallel, coverage, temp install: |
|
33 | 33 | # ./run-tests.py -j2 -c test-s* # currently broken |
|
34 | 34 | # 8) parallel, coverage, local install: |
|
35 | 35 | # ./run-tests.py -j2 -c --local test-s* # unsupported (and broken) |
|
36 | 36 | # 9) parallel, custom tmp dir: |
|
37 | 37 | # ./run-tests.py -j2 --tmpdir /tmp/myhgtests |
|
38 | 38 | # 10) parallel, pure, tests that call run-tests: |
|
39 | 39 | # ./run-tests.py --pure `grep -l run-tests.py *.t` |
|
40 | 40 | # |
|
41 | 41 | # (You could use any subset of the tests: test-s* happens to match |
|
42 | 42 | # enough that it's worth doing parallel runs, few enough that it |
|
43 | 43 | # completes fairly quickly, includes both shell and Python scripts, and |
|
44 | 44 | # includes some scripts that run daemon processes.) |
|
45 | 45 | |
|
46 | 46 | from __future__ import absolute_import, print_function |
|
47 | 47 | |
|
48 | 48 | import argparse |
|
49 | 49 | import collections |
|
50 | 50 | import contextlib |
|
51 | 51 | import difflib |
|
52 | 52 | import distutils.version as version |
|
53 | 53 | import errno |
|
54 | 54 | import json |
|
55 | 55 | import multiprocessing |
|
56 | 56 | import os |
|
57 | 57 | import platform |
|
58 | 58 | import random |
|
59 | 59 | import re |
|
60 | 60 | import shutil |
|
61 | 61 | import signal |
|
62 | 62 | import socket |
|
63 | 63 | import subprocess |
|
64 | 64 | import sys |
|
65 | 65 | import sysconfig |
|
66 | 66 | import tempfile |
|
67 | 67 | import threading |
|
68 | 68 | import time |
|
69 | 69 | import unittest |
|
70 | 70 | import uuid |
|
71 | 71 | import xml.dom.minidom as minidom |
|
72 | 72 | |
|
73 | 73 | WINDOWS = os.name == r'nt' |
|
74 | 74 | |
|
75 | 75 | try: |
|
76 | 76 | import Queue as queue |
|
77 | 77 | except ImportError: |
|
78 | 78 | import queue |
|
79 | 79 | |
|
80 | 80 | try: |
|
81 | 81 | import shlex |
|
82 | 82 | |
|
83 | 83 | shellquote = shlex.quote |
|
84 | 84 | except (ImportError, AttributeError): |
|
85 | 85 | import pipes |
|
86 | 86 | |
|
87 | 87 | shellquote = pipes.quote |
|
88 | 88 | |
|
89 | 89 | |
|
90 | 90 | processlock = threading.Lock() |
|
91 | 91 | |
|
92 | 92 | pygmentspresent = False |
|
93 | 93 | try: # is pygments installed |
|
94 | 94 | import pygments |
|
95 | 95 | import pygments.lexers as lexers |
|
96 | 96 | import pygments.lexer as lexer |
|
97 | 97 | import pygments.formatters as formatters |
|
98 | 98 | import pygments.token as token |
|
99 | 99 | import pygments.style as style |
|
100 | 100 | |
|
101 | 101 | if WINDOWS: |
|
102 | 102 | hgpath = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
|
103 | 103 | sys.path.append(hgpath) |
|
104 | 104 | try: |
|
105 | 105 | from mercurial import win32 # pytype: disable=import-error |
|
106 | 106 | |
|
107 | 107 | # Don't check the result code because it fails on heptapod, but |
|
108 | 108 | # something is able to convert to color anyway. |
|
109 | 109 | win32.enablevtmode() |
|
110 | 110 | finally: |
|
111 | 111 | sys.path = sys.path[:-1] |
|
112 | 112 | |
|
113 | 113 | pygmentspresent = True |
|
114 | 114 | difflexer = lexers.DiffLexer() |
|
115 | 115 | terminal256formatter = formatters.Terminal256Formatter() |
|
116 | 116 | except ImportError: |
|
117 | 117 | pass |
|
118 | 118 | |
|
119 | 119 | if pygmentspresent: |
|
120 | 120 | |
|
121 | 121 | class TestRunnerStyle(style.Style): |
|
122 | 122 | default_style = "" |
|
123 | 123 | skipped = token.string_to_tokentype("Token.Generic.Skipped") |
|
124 | 124 | failed = token.string_to_tokentype("Token.Generic.Failed") |
|
125 | 125 | skippedname = token.string_to_tokentype("Token.Generic.SName") |
|
126 | 126 | failedname = token.string_to_tokentype("Token.Generic.FName") |
|
127 | 127 | styles = { |
|
128 | 128 | skipped: '#e5e5e5', |
|
129 | 129 | skippedname: '#00ffff', |
|
130 | 130 | failed: '#7f0000', |
|
131 | 131 | failedname: '#ff0000', |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | class TestRunnerLexer(lexer.RegexLexer): |
|
135 | 135 | testpattern = r'[\w-]+\.(t|py)(#[a-zA-Z0-9_\-\.]+)?' |
|
136 | 136 | tokens = { |
|
137 | 137 | 'root': [ |
|
138 | 138 | (r'^Skipped', token.Generic.Skipped, 'skipped'), |
|
139 | 139 | (r'^Failed ', token.Generic.Failed, 'failed'), |
|
140 | 140 | (r'^ERROR: ', token.Generic.Failed, 'failed'), |
|
141 | 141 | ], |
|
142 | 142 | 'skipped': [ |
|
143 | 143 | (testpattern, token.Generic.SName), |
|
144 | 144 | (r':.*', token.Generic.Skipped), |
|
145 | 145 | ], |
|
146 | 146 | 'failed': [ |
|
147 | 147 | (testpattern, token.Generic.FName), |
|
148 | 148 | (r'(:| ).*', token.Generic.Failed), |
|
149 | 149 | ], |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | runnerformatter = formatters.Terminal256Formatter(style=TestRunnerStyle) |
|
153 | 153 | runnerlexer = TestRunnerLexer() |
|
154 | 154 | |
|
155 | 155 | origenviron = os.environ.copy() |
|
156 | 156 | |
|
157 | 157 | |
|
158 | 158 | if sys.version_info > (3, 5, 0): |
|
159 | 159 | PYTHON3 = True |
|
160 | 160 | xrange = range # we use xrange in one place, and we'd rather not use range |
|
161 | 161 | |
|
162 | 162 | def _sys2bytes(p): |
|
163 | 163 | if p is None: |
|
164 | 164 | return p |
|
165 | 165 | return p.encode('utf-8') |
|
166 | 166 | |
|
167 | 167 | def _bytes2sys(p): |
|
168 | 168 | if p is None: |
|
169 | 169 | return p |
|
170 | 170 | return p.decode('utf-8') |
|
171 | 171 | |
|
172 | 172 | osenvironb = getattr(os, 'environb', None) |
|
173 | 173 | if osenvironb is None: |
|
174 | 174 | # Windows lacks os.environb, for instance. A proxy over the real thing |
|
175 | 175 | # instead of a copy allows the environment to be updated via bytes on |
|
176 | 176 | # all platforms. |
|
177 | 177 | class environbytes(object): |
|
178 | 178 | def __init__(self, strenv): |
|
179 | 179 | self.__len__ = strenv.__len__ |
|
180 | 180 | self.clear = strenv.clear |
|
181 | 181 | self._strenv = strenv |
|
182 | 182 | |
|
183 | 183 | def __getitem__(self, k): |
|
184 | 184 | v = self._strenv.__getitem__(_bytes2sys(k)) |
|
185 | 185 | return _sys2bytes(v) |
|
186 | 186 | |
|
187 | 187 | def __setitem__(self, k, v): |
|
188 | 188 | self._strenv.__setitem__(_bytes2sys(k), _bytes2sys(v)) |
|
189 | 189 | |
|
190 | 190 | def __delitem__(self, k): |
|
191 | 191 | self._strenv.__delitem__(_bytes2sys(k)) |
|
192 | 192 | |
|
193 | 193 | def __contains__(self, k): |
|
194 | 194 | return self._strenv.__contains__(_bytes2sys(k)) |
|
195 | 195 | |
|
196 | 196 | def __iter__(self): |
|
197 | 197 | return iter([_sys2bytes(k) for k in iter(self._strenv)]) |
|
198 | 198 | |
|
199 | 199 | def get(self, k, default=None): |
|
200 | 200 | v = self._strenv.get(_bytes2sys(k), _bytes2sys(default)) |
|
201 | 201 | return _sys2bytes(v) |
|
202 | 202 | |
|
203 | 203 | def pop(self, k, default=None): |
|
204 | 204 | v = self._strenv.pop(_bytes2sys(k), _bytes2sys(default)) |
|
205 | 205 | return _sys2bytes(v) |
|
206 | 206 | |
|
207 | 207 | osenvironb = environbytes(os.environ) |
|
208 | 208 | |
|
209 | 209 | getcwdb = getattr(os, 'getcwdb') |
|
210 | 210 | if not getcwdb or WINDOWS: |
|
211 | 211 | getcwdb = lambda: _sys2bytes(os.getcwd()) |
|
212 | 212 | |
|
213 | 213 | elif sys.version_info >= (3, 0, 0): |
|
214 | 214 | print( |
|
215 | 215 | '%s is only supported on Python 3.5+ and 2.7, not %s' |
|
216 | 216 | % (sys.argv[0], '.'.join(str(v) for v in sys.version_info[:3])) |
|
217 | 217 | ) |
|
218 | 218 | sys.exit(70) # EX_SOFTWARE from `man 3 sysexit` |
|
219 | 219 | else: |
|
220 | 220 | PYTHON3 = False |
|
221 | 221 | |
|
222 | 222 | # In python 2.x, path operations are generally done using |
|
223 | 223 | # bytestrings by default, so we don't have to do any extra |
|
224 | 224 | # fiddling there. We define the wrapper functions anyway just to |
|
225 | 225 | # help keep code consistent between platforms. |
|
226 | 226 | def _sys2bytes(p): |
|
227 | 227 | return p |
|
228 | 228 | |
|
229 | 229 | _bytes2sys = _sys2bytes |
|
230 | 230 | osenvironb = os.environ |
|
231 | 231 | getcwdb = os.getcwd |
|
232 | 232 | |
|
233 | 233 | # For Windows support |
|
234 | 234 | wifexited = getattr(os, "WIFEXITED", lambda x: False) |
|
235 | 235 | |
|
236 | 236 | # Whether to use IPv6 |
|
237 | 237 | def checksocketfamily(name, port=20058): |
|
238 | 238 | """return true if we can listen on localhost using family=name |
|
239 | 239 | |
|
240 | 240 | name should be either 'AF_INET', or 'AF_INET6'. |
|
241 | 241 | port being used is okay - EADDRINUSE is considered as successful. |
|
242 | 242 | """ |
|
243 | 243 | family = getattr(socket, name, None) |
|
244 | 244 | if family is None: |
|
245 | 245 | return False |
|
246 | 246 | try: |
|
247 | 247 | s = socket.socket(family, socket.SOCK_STREAM) |
|
248 | 248 | s.bind(('localhost', port)) |
|
249 | 249 | s.close() |
|
250 | 250 | return True |
|
251 | 251 | except socket.error as exc: |
|
252 | 252 | if exc.errno == errno.EADDRINUSE: |
|
253 | 253 | return True |
|
254 | 254 | elif exc.errno in (errno.EADDRNOTAVAIL, errno.EPROTONOSUPPORT): |
|
255 | 255 | return False |
|
256 | 256 | else: |
|
257 | 257 | raise |
|
258 | 258 | else: |
|
259 | 259 | return False |
|
260 | 260 | |
|
261 | 261 | |
|
262 | 262 | # useipv6 will be set by parseargs |
|
263 | 263 | useipv6 = None |
|
264 | 264 | |
|
265 | 265 | |
|
266 | 266 | def checkportisavailable(port): |
|
267 | 267 | """return true if a port seems free to bind on localhost""" |
|
268 | 268 | if useipv6: |
|
269 | 269 | family = socket.AF_INET6 |
|
270 | 270 | else: |
|
271 | 271 | family = socket.AF_INET |
|
272 | 272 | try: |
|
273 | 273 | with contextlib.closing(socket.socket(family, socket.SOCK_STREAM)) as s: |
|
274 | 274 | s.bind(('localhost', port)) |
|
275 | 275 | return True |
|
276 | 276 | except socket.error as exc: |
|
277 | 277 | if WINDOWS and exc.errno == errno.WSAEACCES: |
|
278 | 278 | return False |
|
279 | 279 | elif PYTHON3: |
|
280 | 280 | # TODO: make a proper exception handler after dropping py2. This |
|
281 | 281 | # works because socket.error is an alias for OSError on py3, |
|
282 | 282 | # which is also the baseclass of PermissionError. |
|
283 | 283 | if isinstance(exc, PermissionError): |
|
284 | 284 | return False |
|
285 | 285 | if exc.errno not in ( |
|
286 | 286 | errno.EADDRINUSE, |
|
287 | 287 | errno.EADDRNOTAVAIL, |
|
288 | 288 | errno.EPROTONOSUPPORT, |
|
289 | 289 | ): |
|
290 | 290 | raise |
|
291 | 291 | return False |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | closefds = os.name == 'posix' |
|
295 | 295 | |
|
296 | 296 | |
|
297 | 297 | def Popen4(cmd, wd, timeout, env=None): |
|
298 | 298 | processlock.acquire() |
|
299 | 299 | p = subprocess.Popen( |
|
300 | 300 | _bytes2sys(cmd), |
|
301 | 301 | shell=True, |
|
302 | 302 | bufsize=-1, |
|
303 | 303 | cwd=_bytes2sys(wd), |
|
304 | 304 | env=env, |
|
305 | 305 | close_fds=closefds, |
|
306 | 306 | stdin=subprocess.PIPE, |
|
307 | 307 | stdout=subprocess.PIPE, |
|
308 | 308 | stderr=subprocess.STDOUT, |
|
309 | 309 | ) |
|
310 | 310 | processlock.release() |
|
311 | 311 | |
|
312 | 312 | p.fromchild = p.stdout |
|
313 | 313 | p.tochild = p.stdin |
|
314 | 314 | p.childerr = p.stderr |
|
315 | 315 | |
|
316 | 316 | p.timeout = False |
|
317 | 317 | if timeout: |
|
318 | 318 | |
|
319 | 319 | def t(): |
|
320 | 320 | start = time.time() |
|
321 | 321 | while time.time() - start < timeout and p.returncode is None: |
|
322 | 322 | time.sleep(0.1) |
|
323 | 323 | p.timeout = True |
|
324 | 324 | vlog('# Timout reached for process %d' % p.pid) |
|
325 | 325 | if p.returncode is None: |
|
326 | 326 | terminate(p) |
|
327 | 327 | |
|
328 | 328 | threading.Thread(target=t).start() |
|
329 | 329 | |
|
330 | 330 | return p |
|
331 | 331 | |
|
332 | 332 | |
|
333 | 333 | if sys.executable: |
|
334 | 334 | sysexecutable = sys.executable |
|
335 | 335 | elif os.environ.get('PYTHONEXECUTABLE'): |
|
336 | 336 | sysexecutable = os.environ['PYTHONEXECUTABLE'] |
|
337 | 337 | elif os.environ.get('PYTHON'): |
|
338 | 338 | sysexecutable = os.environ['PYTHON'] |
|
339 | 339 | else: |
|
340 | 340 | raise AssertionError('Could not find Python interpreter') |
|
341 | 341 | |
|
342 | 342 | PYTHON = _sys2bytes(sysexecutable.replace('\\', '/')) |
|
343 | 343 | IMPL_PATH = b'PYTHONPATH' |
|
344 | 344 | if 'java' in sys.platform: |
|
345 | 345 | IMPL_PATH = b'JYTHONPATH' |
|
346 | 346 | |
|
347 | 347 | default_defaults = { |
|
348 | 348 | 'jobs': ('HGTEST_JOBS', multiprocessing.cpu_count()), |
|
349 | 349 | 'timeout': ('HGTEST_TIMEOUT', 360), |
|
350 | 350 | 'slowtimeout': ('HGTEST_SLOWTIMEOUT', 1500), |
|
351 | 351 | 'port': ('HGTEST_PORT', 20059), |
|
352 | 352 | 'shell': ('HGTEST_SHELL', 'sh'), |
|
353 | 353 | } |
|
354 | 354 | |
|
355 | 355 | defaults = default_defaults.copy() |
|
356 | 356 | |
|
357 | 357 | |
|
358 | 358 | def canonpath(path): |
|
359 | 359 | return os.path.realpath(os.path.expanduser(path)) |
|
360 | 360 | |
|
361 | 361 | |
|
362 | 362 | def parselistfiles(files, listtype, warn=True): |
|
363 | 363 | entries = dict() |
|
364 | 364 | for filename in files: |
|
365 | 365 | try: |
|
366 | 366 | path = os.path.expanduser(os.path.expandvars(filename)) |
|
367 | 367 | f = open(path, "rb") |
|
368 | 368 | except IOError as err: |
|
369 | 369 | if err.errno != errno.ENOENT: |
|
370 | 370 | raise |
|
371 | 371 | if warn: |
|
372 | 372 | print("warning: no such %s file: %s" % (listtype, filename)) |
|
373 | 373 | continue |
|
374 | 374 | |
|
375 | 375 | for line in f.readlines(): |
|
376 | 376 | line = line.split(b'#', 1)[0].strip() |
|
377 | 377 | if line: |
|
378 | 378 | # Ensure path entries are compatible with os.path.relpath() |
|
379 | 379 | entries[os.path.normpath(line)] = filename |
|
380 | 380 | |
|
381 | 381 | f.close() |
|
382 | 382 | return entries |
|
383 | 383 | |
|
384 | 384 | |
|
385 | 385 | def parsettestcases(path): |
|
386 | 386 | """read a .t test file, return a set of test case names |
|
387 | 387 | |
|
388 | 388 | If path does not exist, return an empty set. |
|
389 | 389 | """ |
|
390 | 390 | cases = [] |
|
391 | 391 | try: |
|
392 | 392 | with open(path, 'rb') as f: |
|
393 | 393 | for l in f: |
|
394 | 394 | if l.startswith(b'#testcases '): |
|
395 | 395 | cases.append(sorted(l[11:].split())) |
|
396 | 396 | except IOError as ex: |
|
397 | 397 | if ex.errno != errno.ENOENT: |
|
398 | 398 | raise |
|
399 | 399 | return cases |
|
400 | 400 | |
|
401 | 401 | |
|
402 | 402 | def getparser(): |
|
403 | 403 | """Obtain the OptionParser used by the CLI.""" |
|
404 | 404 | parser = argparse.ArgumentParser(usage='%(prog)s [options] [tests]') |
|
405 | 405 | |
|
406 | 406 | selection = parser.add_argument_group('Test Selection') |
|
407 | 407 | selection.add_argument( |
|
408 | 408 | '--allow-slow-tests', |
|
409 | 409 | action='store_true', |
|
410 | 410 | help='allow extremely slow tests', |
|
411 | 411 | ) |
|
412 | 412 | selection.add_argument( |
|
413 | 413 | "--blacklist", |
|
414 | 414 | action="append", |
|
415 | 415 | help="skip tests listed in the specified blacklist file", |
|
416 | 416 | ) |
|
417 | 417 | selection.add_argument( |
|
418 | 418 | "--changed", |
|
419 | 419 | help="run tests that are changed in parent rev or working directory", |
|
420 | 420 | ) |
|
421 | 421 | selection.add_argument( |
|
422 | 422 | "-k", "--keywords", help="run tests matching keywords" |
|
423 | 423 | ) |
|
424 | 424 | selection.add_argument( |
|
425 | 425 | "-r", "--retest", action="store_true", help="retest failed tests" |
|
426 | 426 | ) |
|
427 | 427 | selection.add_argument( |
|
428 | 428 | "--test-list", |
|
429 | 429 | action="append", |
|
430 | 430 | help="read tests to run from the specified file", |
|
431 | 431 | ) |
|
432 | 432 | selection.add_argument( |
|
433 | 433 | "--whitelist", |
|
434 | 434 | action="append", |
|
435 | 435 | help="always run tests listed in the specified whitelist file", |
|
436 | 436 | ) |
|
437 | 437 | selection.add_argument( |
|
438 | 438 | 'tests', metavar='TESTS', nargs='*', help='Tests to run' |
|
439 | 439 | ) |
|
440 | 440 | |
|
441 | 441 | harness = parser.add_argument_group('Test Harness Behavior') |
|
442 | 442 | harness.add_argument( |
|
443 | 443 | '--bisect-repo', |
|
444 | 444 | metavar='bisect_repo', |
|
445 | 445 | help=( |
|
446 | 446 | "Path of a repo to bisect. Use together with " "--known-good-rev" |
|
447 | 447 | ), |
|
448 | 448 | ) |
|
449 | 449 | harness.add_argument( |
|
450 | 450 | "-d", |
|
451 | 451 | "--debug", |
|
452 | 452 | action="store_true", |
|
453 | 453 | help="debug mode: write output of test scripts to console" |
|
454 | 454 | " rather than capturing and diffing it (disables timeout)", |
|
455 | 455 | ) |
|
456 | 456 | harness.add_argument( |
|
457 | 457 | "-f", |
|
458 | 458 | "--first", |
|
459 | 459 | action="store_true", |
|
460 | 460 | help="exit on the first test failure", |
|
461 | 461 | ) |
|
462 | 462 | harness.add_argument( |
|
463 | 463 | "-i", |
|
464 | 464 | "--interactive", |
|
465 | 465 | action="store_true", |
|
466 | 466 | help="prompt to accept changed output", |
|
467 | 467 | ) |
|
468 | 468 | harness.add_argument( |
|
469 | 469 | "-j", |
|
470 | 470 | "--jobs", |
|
471 | 471 | type=int, |
|
472 | 472 | help="number of jobs to run in parallel" |
|
473 | 473 | " (default: $%s or %d)" % defaults['jobs'], |
|
474 | 474 | ) |
|
475 | 475 | harness.add_argument( |
|
476 | 476 | "--keep-tmpdir", |
|
477 | 477 | action="store_true", |
|
478 | 478 | help="keep temporary directory after running tests", |
|
479 | 479 | ) |
|
480 | 480 | harness.add_argument( |
|
481 | 481 | '--known-good-rev', |
|
482 | 482 | metavar="known_good_rev", |
|
483 | 483 | help=( |
|
484 | 484 | "Automatically bisect any failures using this " |
|
485 | 485 | "revision as a known-good revision." |
|
486 | 486 | ), |
|
487 | 487 | ) |
|
488 | 488 | harness.add_argument( |
|
489 | 489 | "--list-tests", |
|
490 | 490 | action="store_true", |
|
491 | 491 | help="list tests instead of running them", |
|
492 | 492 | ) |
|
493 | 493 | harness.add_argument( |
|
494 | 494 | "--loop", action="store_true", help="loop tests repeatedly" |
|
495 | 495 | ) |
|
496 | 496 | harness.add_argument( |
|
497 | 497 | '--random', action="store_true", help='run tests in random order' |
|
498 | 498 | ) |
|
499 | 499 | harness.add_argument( |
|
500 | 500 | '--order-by-runtime', |
|
501 | 501 | action="store_true", |
|
502 | 502 | help='run slowest tests first, according to .testtimes', |
|
503 | 503 | ) |
|
504 | 504 | harness.add_argument( |
|
505 | 505 | "-p", |
|
506 | 506 | "--port", |
|
507 | 507 | type=int, |
|
508 | 508 | help="port on which servers should listen" |
|
509 | 509 | " (default: $%s or %d)" % defaults['port'], |
|
510 | 510 | ) |
|
511 | 511 | harness.add_argument( |
|
512 | 512 | '--profile-runner', |
|
513 | 513 | action='store_true', |
|
514 | 514 | help='run statprof on run-tests', |
|
515 | 515 | ) |
|
516 | 516 | harness.add_argument( |
|
517 | 517 | "-R", "--restart", action="store_true", help="restart at last error" |
|
518 | 518 | ) |
|
519 | 519 | harness.add_argument( |
|
520 | 520 | "--runs-per-test", |
|
521 | 521 | type=int, |
|
522 | 522 | dest="runs_per_test", |
|
523 | 523 | help="run each test N times (default=1)", |
|
524 | 524 | default=1, |
|
525 | 525 | ) |
|
526 | 526 | harness.add_argument( |
|
527 | 527 | "--shell", help="shell to use (default: $%s or %s)" % defaults['shell'] |
|
528 | 528 | ) |
|
529 | 529 | harness.add_argument( |
|
530 | 530 | '--showchannels', action='store_true', help='show scheduling channels' |
|
531 | 531 | ) |
|
532 | 532 | harness.add_argument( |
|
533 | 533 | "--slowtimeout", |
|
534 | 534 | type=int, |
|
535 | 535 | help="kill errant slow tests after SLOWTIMEOUT seconds" |
|
536 | 536 | " (default: $%s or %d)" % defaults['slowtimeout'], |
|
537 | 537 | ) |
|
538 | 538 | harness.add_argument( |
|
539 | 539 | "-t", |
|
540 | 540 | "--timeout", |
|
541 | 541 | type=int, |
|
542 | 542 | help="kill errant tests after TIMEOUT seconds" |
|
543 | 543 | " (default: $%s or %d)" % defaults['timeout'], |
|
544 | 544 | ) |
|
545 | 545 | harness.add_argument( |
|
546 | 546 | "--tmpdir", |
|
547 | 547 | help="run tests in the given temporary directory" |
|
548 | 548 | " (implies --keep-tmpdir)", |
|
549 | 549 | ) |
|
550 | 550 | harness.add_argument( |
|
551 | 551 | "-v", "--verbose", action="store_true", help="output verbose messages" |
|
552 | 552 | ) |
|
553 | 553 | |
|
554 | 554 | hgconf = parser.add_argument_group('Mercurial Configuration') |
|
555 | 555 | hgconf.add_argument( |
|
556 | 556 | "--chg", |
|
557 | 557 | action="store_true", |
|
558 | 558 | help="install and use chg wrapper in place of hg", |
|
559 | 559 | ) |
|
560 | 560 | hgconf.add_argument( |
|
561 | 561 | "--chg-debug", |
|
562 | 562 | action="store_true", |
|
563 | 563 | help="show chg debug logs", |
|
564 | 564 | ) |
|
565 | 565 | hgconf.add_argument( |
|
566 | 566 | "--rhg", |
|
567 | 567 | action="store_true", |
|
568 | 568 | help="install and use rhg Rust implementation in place of hg", |
|
569 | 569 | ) |
|
570 | 570 | hgconf.add_argument("--compiler", help="compiler to build with") |
|
571 | 571 | hgconf.add_argument( |
|
572 | 572 | '--extra-config-opt', |
|
573 | 573 | action="append", |
|
574 | 574 | default=[], |
|
575 | 575 | help='set the given config opt in the test hgrc', |
|
576 | 576 | ) |
|
577 | 577 | hgconf.add_argument( |
|
578 | 578 | "-l", |
|
579 | 579 | "--local", |
|
580 | 580 | action="store_true", |
|
581 | 581 | help="shortcut for --with-hg=<testdir>/../hg, " |
|
582 | 582 | "--with-rhg=<testdir>/../rust/target/release/rhg if --rhg is set, " |
|
583 | 583 | "and --with-chg=<testdir>/../contrib/chg/chg if --chg is set", |
|
584 | 584 | ) |
|
585 | 585 | hgconf.add_argument( |
|
586 | 586 | "--ipv6", |
|
587 | 587 | action="store_true", |
|
588 | 588 | help="prefer IPv6 to IPv4 for network related tests", |
|
589 | 589 | ) |
|
590 | 590 | hgconf.add_argument( |
|
591 | 591 | "--pure", |
|
592 | 592 | action="store_true", |
|
593 | 593 | help="use pure Python code instead of C extensions", |
|
594 | 594 | ) |
|
595 | 595 | hgconf.add_argument( |
|
596 | 596 | "--rust", |
|
597 | 597 | action="store_true", |
|
598 | 598 | help="use Rust code alongside C extensions", |
|
599 | 599 | ) |
|
600 | 600 | hgconf.add_argument( |
|
601 | 601 | "--no-rust", |
|
602 | 602 | action="store_true", |
|
603 | 603 | help="do not use Rust code even if compiled", |
|
604 | 604 | ) |
|
605 | 605 | hgconf.add_argument( |
|
606 | 606 | "--with-chg", |
|
607 | 607 | metavar="CHG", |
|
608 | 608 | help="use specified chg wrapper in place of hg", |
|
609 | 609 | ) |
|
610 | 610 | hgconf.add_argument( |
|
611 | 611 | "--with-rhg", |
|
612 | 612 | metavar="RHG", |
|
613 | 613 | help="use specified rhg Rust implementation in place of hg", |
|
614 | 614 | ) |
|
615 | 615 | hgconf.add_argument( |
|
616 | 616 | "--with-hg", |
|
617 | 617 | metavar="HG", |
|
618 | 618 | help="test using specified hg script rather than a " |
|
619 | 619 | "temporary installation", |
|
620 | 620 | ) |
|
621 | 621 | |
|
622 | 622 | reporting = parser.add_argument_group('Results Reporting') |
|
623 | 623 | reporting.add_argument( |
|
624 | 624 | "-C", |
|
625 | 625 | "--annotate", |
|
626 | 626 | action="store_true", |
|
627 | 627 | help="output files annotated with coverage", |
|
628 | 628 | ) |
|
629 | 629 | reporting.add_argument( |
|
630 | 630 | "--color", |
|
631 | 631 | choices=["always", "auto", "never"], |
|
632 | 632 | default=os.environ.get('HGRUNTESTSCOLOR', 'auto'), |
|
633 | 633 | help="colorisation: always|auto|never (default: auto)", |
|
634 | 634 | ) |
|
635 | 635 | reporting.add_argument( |
|
636 | 636 | "-c", |
|
637 | 637 | "--cover", |
|
638 | 638 | action="store_true", |
|
639 | 639 | help="print a test coverage report", |
|
640 | 640 | ) |
|
641 | 641 | reporting.add_argument( |
|
642 | 642 | '--exceptions', |
|
643 | 643 | action='store_true', |
|
644 | 644 | help='log all exceptions and generate an exception report', |
|
645 | 645 | ) |
|
646 | 646 | reporting.add_argument( |
|
647 | 647 | "-H", |
|
648 | 648 | "--htmlcov", |
|
649 | 649 | action="store_true", |
|
650 | 650 | help="create an HTML report of the coverage of the files", |
|
651 | 651 | ) |
|
652 | 652 | reporting.add_argument( |
|
653 | 653 | "--json", |
|
654 | 654 | action="store_true", |
|
655 | 655 | help="store test result data in 'report.json' file", |
|
656 | 656 | ) |
|
657 | 657 | reporting.add_argument( |
|
658 | 658 | "--outputdir", |
|
659 | 659 | help="directory to write error logs to (default=test directory)", |
|
660 | 660 | ) |
|
661 | 661 | reporting.add_argument( |
|
662 | 662 | "-n", "--nodiff", action="store_true", help="skip showing test changes" |
|
663 | 663 | ) |
|
664 | 664 | reporting.add_argument( |
|
665 | 665 | "-S", |
|
666 | 666 | "--noskips", |
|
667 | 667 | action="store_true", |
|
668 | 668 | help="don't report skip tests verbosely", |
|
669 | 669 | ) |
|
670 | 670 | reporting.add_argument( |
|
671 | 671 | "--time", action="store_true", help="time how long each test takes" |
|
672 | 672 | ) |
|
673 | 673 | reporting.add_argument("--view", help="external diff viewer") |
|
674 | 674 | reporting.add_argument( |
|
675 | 675 | "--xunit", help="record xunit results at specified path" |
|
676 | 676 | ) |
|
677 | 677 | |
|
678 | 678 | for option, (envvar, default) in defaults.items(): |
|
679 | 679 | defaults[option] = type(default)(os.environ.get(envvar, default)) |
|
680 | 680 | parser.set_defaults(**defaults) |
|
681 | 681 | |
|
682 | 682 | return parser |
|
683 | 683 | |
|
684 | 684 | |
|
685 | 685 | def parseargs(args, parser): |
|
686 | 686 | """Parse arguments with our OptionParser and validate results.""" |
|
687 | 687 | options = parser.parse_args(args) |
|
688 | 688 | |
|
689 | 689 | # jython is always pure |
|
690 | 690 | if 'java' in sys.platform or '__pypy__' in sys.modules: |
|
691 | 691 | options.pure = True |
|
692 | 692 | |
|
693 | 693 | if platform.python_implementation() != 'CPython' and options.rust: |
|
694 | 694 | parser.error('Rust extensions are only available with CPython') |
|
695 | 695 | |
|
696 | 696 | if options.pure and options.rust: |
|
697 | 697 | parser.error('--rust cannot be used with --pure') |
|
698 | 698 | |
|
699 | 699 | if options.rust and options.no_rust: |
|
700 | 700 | parser.error('--rust cannot be used with --no-rust') |
|
701 | 701 | |
|
702 | 702 | if options.local: |
|
703 | 703 | if options.with_hg or options.with_rhg or options.with_chg: |
|
704 | 704 | parser.error( |
|
705 | 705 | '--local cannot be used with --with-hg or --with-rhg or --with-chg' |
|
706 | 706 | ) |
|
707 | 707 | testdir = os.path.dirname(_sys2bytes(canonpath(sys.argv[0]))) |
|
708 | 708 | reporootdir = os.path.dirname(testdir) |
|
709 | 709 | pathandattrs = [(b'hg', 'with_hg')] |
|
710 | 710 | if options.chg: |
|
711 | 711 | pathandattrs.append((b'contrib/chg/chg', 'with_chg')) |
|
712 | 712 | if options.rhg: |
|
713 | 713 | pathandattrs.append((b'rust/target/release/rhg', 'with_rhg')) |
|
714 | 714 | for relpath, attr in pathandattrs: |
|
715 | 715 | binpath = os.path.join(reporootdir, relpath) |
|
716 | 716 | if not (WINDOWS or os.access(binpath, os.X_OK)): |
|
717 | 717 | parser.error( |
|
718 | 718 | '--local specified, but %r not found or ' |
|
719 | 719 | 'not executable' % binpath |
|
720 | 720 | ) |
|
721 | 721 | setattr(options, attr, _bytes2sys(binpath)) |
|
722 | 722 | |
|
723 | 723 | if options.with_hg: |
|
724 | 724 | options.with_hg = canonpath(_sys2bytes(options.with_hg)) |
|
725 | 725 | if not ( |
|
726 | 726 | os.path.isfile(options.with_hg) |
|
727 | 727 | and os.access(options.with_hg, os.X_OK) |
|
728 | 728 | ): |
|
729 | 729 | parser.error('--with-hg must specify an executable hg script') |
|
730 | 730 | if os.path.basename(options.with_hg) not in [b'hg', b'hg.exe']: |
|
731 | 731 | msg = 'warning: --with-hg should specify an hg script, not: %s\n' |
|
732 | 732 | msg %= _bytes2sys(os.path.basename(options.with_hg)) |
|
733 | 733 | sys.stderr.write(msg) |
|
734 | 734 | sys.stderr.flush() |
|
735 | 735 | |
|
736 | 736 | if (options.chg or options.with_chg) and WINDOWS: |
|
737 | 737 | parser.error('chg does not work on %s' % os.name) |
|
738 | 738 | if (options.rhg or options.with_rhg) and WINDOWS: |
|
739 | 739 | parser.error('rhg does not work on %s' % os.name) |
|
740 | 740 | if options.with_chg: |
|
741 | 741 | options.chg = False # no installation to temporary location |
|
742 | 742 | options.with_chg = canonpath(_sys2bytes(options.with_chg)) |
|
743 | 743 | if not ( |
|
744 | 744 | os.path.isfile(options.with_chg) |
|
745 | 745 | and os.access(options.with_chg, os.X_OK) |
|
746 | 746 | ): |
|
747 | 747 | parser.error('--with-chg must specify a chg executable') |
|
748 | 748 | if options.with_rhg: |
|
749 | 749 | options.rhg = False # no installation to temporary location |
|
750 | 750 | options.with_rhg = canonpath(_sys2bytes(options.with_rhg)) |
|
751 | 751 | if not ( |
|
752 | 752 | os.path.isfile(options.with_rhg) |
|
753 | 753 | and os.access(options.with_rhg, os.X_OK) |
|
754 | 754 | ): |
|
755 | 755 | parser.error('--with-rhg must specify a rhg executable') |
|
756 | 756 | if options.chg and options.with_hg: |
|
757 | 757 | # chg shares installation location with hg |
|
758 | 758 | parser.error( |
|
759 | 759 | '--chg does not work when --with-hg is specified ' |
|
760 | 760 | '(use --with-chg instead)' |
|
761 | 761 | ) |
|
762 | 762 | if options.rhg and options.with_hg: |
|
763 | 763 | # rhg shares installation location with hg |
|
764 | 764 | parser.error( |
|
765 | 765 | '--rhg does not work when --with-hg is specified ' |
|
766 | 766 | '(use --with-rhg instead)' |
|
767 | 767 | ) |
|
768 | 768 | if options.rhg and options.chg: |
|
769 | 769 | parser.error('--rhg and --chg do not work together') |
|
770 | 770 | |
|
771 | 771 | if options.color == 'always' and not pygmentspresent: |
|
772 | 772 | sys.stderr.write( |
|
773 | 773 | 'warning: --color=always ignored because ' |
|
774 | 774 | 'pygments is not installed\n' |
|
775 | 775 | ) |
|
776 | 776 | |
|
777 | 777 | if options.bisect_repo and not options.known_good_rev: |
|
778 | 778 | parser.error("--bisect-repo cannot be used without --known-good-rev") |
|
779 | 779 | |
|
780 | 780 | global useipv6 |
|
781 | 781 | if options.ipv6: |
|
782 | 782 | useipv6 = checksocketfamily('AF_INET6') |
|
783 | 783 | else: |
|
784 | 784 | # only use IPv6 if IPv4 is unavailable and IPv6 is available |
|
785 | 785 | useipv6 = (not checksocketfamily('AF_INET')) and checksocketfamily( |
|
786 | 786 | 'AF_INET6' |
|
787 | 787 | ) |
|
788 | 788 | |
|
789 | 789 | options.anycoverage = options.cover or options.annotate or options.htmlcov |
|
790 | 790 | if options.anycoverage: |
|
791 | 791 | try: |
|
792 | 792 | import coverage |
|
793 | 793 | |
|
794 | 794 | covver = version.StrictVersion(coverage.__version__).version |
|
795 | 795 | if covver < (3, 3): |
|
796 | 796 | parser.error('coverage options require coverage 3.3 or later') |
|
797 | 797 | except ImportError: |
|
798 | 798 | parser.error('coverage options now require the coverage package') |
|
799 | 799 | |
|
800 | 800 | if options.anycoverage and options.local: |
|
801 | 801 | # this needs some path mangling somewhere, I guess |
|
802 | 802 | parser.error( |
|
803 | 803 | "sorry, coverage options do not work when --local " "is specified" |
|
804 | 804 | ) |
|
805 | 805 | |
|
806 | 806 | if options.anycoverage and options.with_hg: |
|
807 | 807 | parser.error( |
|
808 | 808 | "sorry, coverage options do not work when --with-hg " "is specified" |
|
809 | 809 | ) |
|
810 | 810 | |
|
811 | 811 | global verbose |
|
812 | 812 | if options.verbose: |
|
813 | 813 | verbose = '' |
|
814 | 814 | |
|
815 | 815 | if options.tmpdir: |
|
816 | 816 | options.tmpdir = canonpath(options.tmpdir) |
|
817 | 817 | |
|
818 | 818 | if options.jobs < 1: |
|
819 | 819 | parser.error('--jobs must be positive') |
|
820 | 820 | if options.interactive and options.debug: |
|
821 | 821 | parser.error("-i/--interactive and -d/--debug are incompatible") |
|
822 | 822 | if options.debug: |
|
823 | 823 | if options.timeout != defaults['timeout']: |
|
824 | 824 | sys.stderr.write('warning: --timeout option ignored with --debug\n') |
|
825 | 825 | if options.slowtimeout != defaults['slowtimeout']: |
|
826 | 826 | sys.stderr.write( |
|
827 | 827 | 'warning: --slowtimeout option ignored with --debug\n' |
|
828 | 828 | ) |
|
829 | 829 | options.timeout = 0 |
|
830 | 830 | options.slowtimeout = 0 |
|
831 | 831 | |
|
832 | 832 | if options.blacklist: |
|
833 | 833 | options.blacklist = parselistfiles(options.blacklist, 'blacklist') |
|
834 | 834 | if options.whitelist: |
|
835 | 835 | options.whitelisted = parselistfiles(options.whitelist, 'whitelist') |
|
836 | 836 | else: |
|
837 | 837 | options.whitelisted = {} |
|
838 | 838 | |
|
839 | 839 | if options.showchannels: |
|
840 | 840 | options.nodiff = True |
|
841 | 841 | |
|
842 | 842 | return options |
|
843 | 843 | |
|
844 | 844 | |
|
845 | 845 | def rename(src, dst): |
|
846 | 846 | """Like os.rename(), trade atomicity and opened files friendliness |
|
847 | 847 | for existing destination support. |
|
848 | 848 | """ |
|
849 | 849 | shutil.copy(src, dst) |
|
850 | 850 | os.remove(src) |
|
851 | 851 | |
|
852 | 852 | |
|
853 | 853 | def makecleanable(path): |
|
854 | 854 | """Try to fix directory permission recursively so that the entire tree |
|
855 | 855 | can be deleted""" |
|
856 | 856 | for dirpath, dirnames, _filenames in os.walk(path, topdown=True): |
|
857 | 857 | for d in dirnames: |
|
858 | 858 | p = os.path.join(dirpath, d) |
|
859 | 859 | try: |
|
860 | 860 | os.chmod(p, os.stat(p).st_mode & 0o777 | 0o700) # chmod u+rwx |
|
861 | 861 | except OSError: |
|
862 | 862 | pass |
|
863 | 863 | |
|
864 | 864 | |
|
865 | 865 | _unified_diff = difflib.unified_diff |
|
866 | 866 | if PYTHON3: |
|
867 | 867 | import functools |
|
868 | 868 | |
|
869 | 869 | _unified_diff = functools.partial(difflib.diff_bytes, difflib.unified_diff) |
|
870 | 870 | |
|
871 | 871 | |
|
872 | 872 | def getdiff(expected, output, ref, err): |
|
873 | 873 | servefail = False |
|
874 | 874 | lines = [] |
|
875 | 875 | for line in _unified_diff(expected, output, ref, err): |
|
876 | 876 | if line.startswith(b'+++') or line.startswith(b'---'): |
|
877 | 877 | line = line.replace(b'\\', b'/') |
|
878 | 878 | if line.endswith(b' \n'): |
|
879 | 879 | line = line[:-2] + b'\n' |
|
880 | 880 | lines.append(line) |
|
881 | 881 | if not servefail and line.startswith( |
|
882 | 882 | b'+ abort: child process failed to start' |
|
883 | 883 | ): |
|
884 | 884 | servefail = True |
|
885 | 885 | |
|
886 | 886 | return servefail, lines |
|
887 | 887 | |
|
888 | 888 | |
|
889 | 889 | verbose = False |
|
890 | 890 | |
|
891 | 891 | |
|
892 | 892 | def vlog(*msg): |
|
893 | 893 | """Log only when in verbose mode.""" |
|
894 | 894 | if verbose is False: |
|
895 | 895 | return |
|
896 | 896 | |
|
897 | 897 | return log(*msg) |
|
898 | 898 | |
|
899 | 899 | |
|
900 | 900 | # Bytes that break XML even in a CDATA block: control characters 0-31 |
|
901 | 901 | # sans \t, \n and \r |
|
902 | 902 | CDATA_EVIL = re.compile(br"[\000-\010\013\014\016-\037]") |
|
903 | 903 | |
|
904 | 904 | # Match feature conditionalized output lines in the form, capturing the feature |
|
905 | 905 | # list in group 2, and the preceeding line output in group 1: |
|
906 | 906 | # |
|
907 | 907 | # output..output (feature !)\n |
|
908 | 908 | optline = re.compile(br'(.*) \((.+?) !\)\n$') |
|
909 | 909 | |
|
910 | 910 | |
|
911 | 911 | def cdatasafe(data): |
|
912 | 912 | """Make a string safe to include in a CDATA block. |
|
913 | 913 | |
|
914 | 914 | Certain control characters are illegal in a CDATA block, and |
|
915 | 915 | there's no way to include a ]]> in a CDATA either. This function |
|
916 | 916 | replaces illegal bytes with ? and adds a space between the ]] so |
|
917 | 917 | that it won't break the CDATA block. |
|
918 | 918 | """ |
|
919 | 919 | return CDATA_EVIL.sub(b'?', data).replace(b']]>', b'] ]>') |
|
920 | 920 | |
|
921 | 921 | |
|
922 | 922 | def log(*msg): |
|
923 | 923 | """Log something to stdout. |
|
924 | 924 | |
|
925 | 925 | Arguments are strings to print. |
|
926 | 926 | """ |
|
927 | 927 | with iolock: |
|
928 | 928 | if verbose: |
|
929 | 929 | print(verbose, end=' ') |
|
930 | 930 | for m in msg: |
|
931 | 931 | print(m, end=' ') |
|
932 | 932 | print() |
|
933 | 933 | sys.stdout.flush() |
|
934 | 934 | |
|
935 | 935 | |
|
936 | 936 | def highlightdiff(line, color): |
|
937 | 937 | if not color: |
|
938 | 938 | return line |
|
939 | 939 | assert pygmentspresent |
|
940 | 940 | return pygments.highlight( |
|
941 | 941 | line.decode('latin1'), difflexer, terminal256formatter |
|
942 | 942 | ).encode('latin1') |
|
943 | 943 | |
|
944 | 944 | |
|
945 | 945 | def highlightmsg(msg, color): |
|
946 | 946 | if not color: |
|
947 | 947 | return msg |
|
948 | 948 | assert pygmentspresent |
|
949 | 949 | return pygments.highlight(msg, runnerlexer, runnerformatter) |
|
950 | 950 | |
|
951 | 951 | |
|
952 | 952 | def terminate(proc): |
|
953 | 953 | """Terminate subprocess""" |
|
954 | 954 | vlog('# Terminating process %d' % proc.pid) |
|
955 | 955 | try: |
|
956 | 956 | proc.terminate() |
|
957 | 957 | except OSError: |
|
958 | 958 | pass |
|
959 | 959 | |
|
960 | 960 | |
|
961 | 961 | def killdaemons(pidfile): |
|
962 | 962 | import killdaemons as killmod |
|
963 | 963 | |
|
964 | 964 | return killmod.killdaemons(pidfile, tryhard=False, remove=True, logfn=vlog) |
|
965 | 965 | |
|
966 | 966 | |
|
967 | 967 | class Test(unittest.TestCase): |
|
968 | 968 | """Encapsulates a single, runnable test. |
|
969 | 969 | |
|
970 | 970 | While this class conforms to the unittest.TestCase API, it differs in that |
|
971 | 971 | instances need to be instantiated manually. (Typically, unittest.TestCase |
|
972 | 972 | classes are instantiated automatically by scanning modules.) |
|
973 | 973 | """ |
|
974 | 974 | |
|
975 | 975 | # Status code reserved for skipped tests (used by hghave). |
|
976 | 976 | SKIPPED_STATUS = 80 |
|
977 | 977 | |
|
978 | 978 | def __init__( |
|
979 | 979 | self, |
|
980 | 980 | path, |
|
981 | 981 | outputdir, |
|
982 | 982 | tmpdir, |
|
983 | 983 | keeptmpdir=False, |
|
984 | 984 | debug=False, |
|
985 | 985 | first=False, |
|
986 | 986 | timeout=None, |
|
987 | 987 | startport=None, |
|
988 | 988 | extraconfigopts=None, |
|
989 | 989 | shell=None, |
|
990 | 990 | hgcommand=None, |
|
991 | 991 | slowtimeout=None, |
|
992 | 992 | usechg=False, |
|
993 | 993 | chgdebug=False, |
|
994 | 994 | useipv6=False, |
|
995 | 995 | ): |
|
996 | 996 | """Create a test from parameters. |
|
997 | 997 | |
|
998 | 998 | path is the full path to the file defining the test. |
|
999 | 999 | |
|
1000 | 1000 | tmpdir is the main temporary directory to use for this test. |
|
1001 | 1001 | |
|
1002 | 1002 | keeptmpdir determines whether to keep the test's temporary directory |
|
1003 | 1003 | after execution. It defaults to removal (False). |
|
1004 | 1004 | |
|
1005 | 1005 | debug mode will make the test execute verbosely, with unfiltered |
|
1006 | 1006 | output. |
|
1007 | 1007 | |
|
1008 | 1008 | timeout controls the maximum run time of the test. It is ignored when |
|
1009 | 1009 | debug is True. See slowtimeout for tests with #require slow. |
|
1010 | 1010 | |
|
1011 | 1011 | slowtimeout overrides timeout if the test has #require slow. |
|
1012 | 1012 | |
|
1013 | 1013 | startport controls the starting port number to use for this test. Each |
|
1014 | 1014 | test will reserve 3 port numbers for execution. It is the caller's |
|
1015 | 1015 | responsibility to allocate a non-overlapping port range to Test |
|
1016 | 1016 | instances. |
|
1017 | 1017 | |
|
1018 | 1018 | extraconfigopts is an iterable of extra hgrc config options. Values |
|
1019 | 1019 | must have the form "key=value" (something understood by hgrc). Values |
|
1020 | 1020 | of the form "foo.key=value" will result in "[foo] key=value". |
|
1021 | 1021 | |
|
1022 | 1022 | shell is the shell to execute tests in. |
|
1023 | 1023 | """ |
|
1024 | 1024 | if timeout is None: |
|
1025 | 1025 | timeout = defaults['timeout'] |
|
1026 | 1026 | if startport is None: |
|
1027 | 1027 | startport = defaults['port'] |
|
1028 | 1028 | if slowtimeout is None: |
|
1029 | 1029 | slowtimeout = defaults['slowtimeout'] |
|
1030 | 1030 | self.path = path |
|
1031 | 1031 | self.relpath = os.path.relpath(path) |
|
1032 | 1032 | self.bname = os.path.basename(path) |
|
1033 | 1033 | self.name = _bytes2sys(self.bname) |
|
1034 | 1034 | self._testdir = os.path.dirname(path) |
|
1035 | 1035 | self._outputdir = outputdir |
|
1036 | 1036 | self._tmpname = os.path.basename(path) |
|
1037 | 1037 | self.errpath = os.path.join(self._outputdir, b'%s.err' % self.bname) |
|
1038 | 1038 | |
|
1039 | 1039 | self._threadtmp = tmpdir |
|
1040 | 1040 | self._keeptmpdir = keeptmpdir |
|
1041 | 1041 | self._debug = debug |
|
1042 | 1042 | self._first = first |
|
1043 | 1043 | self._timeout = timeout |
|
1044 | 1044 | self._slowtimeout = slowtimeout |
|
1045 | 1045 | self._startport = startport |
|
1046 | 1046 | self._extraconfigopts = extraconfigopts or [] |
|
1047 | 1047 | self._shell = _sys2bytes(shell) |
|
1048 | 1048 | self._hgcommand = hgcommand or b'hg' |
|
1049 | 1049 | self._usechg = usechg |
|
1050 | 1050 | self._chgdebug = chgdebug |
|
1051 | 1051 | self._useipv6 = useipv6 |
|
1052 | 1052 | |
|
1053 | 1053 | self._aborted = False |
|
1054 | 1054 | self._daemonpids = [] |
|
1055 | 1055 | self._finished = None |
|
1056 | 1056 | self._ret = None |
|
1057 | 1057 | self._out = None |
|
1058 | 1058 | self._skipped = None |
|
1059 | 1059 | self._testtmp = None |
|
1060 | 1060 | self._chgsockdir = None |
|
1061 | 1061 | |
|
1062 | 1062 | self._refout = self.readrefout() |
|
1063 | 1063 | |
|
1064 | 1064 | def readrefout(self): |
|
1065 | 1065 | """read reference output""" |
|
1066 | 1066 | # If we're not in --debug mode and reference output file exists, |
|
1067 | 1067 | # check test output against it. |
|
1068 | 1068 | if self._debug: |
|
1069 | 1069 | return None # to match "out is None" |
|
1070 | 1070 | elif os.path.exists(self.refpath): |
|
1071 | 1071 | with open(self.refpath, 'rb') as f: |
|
1072 | 1072 | return f.read().splitlines(True) |
|
1073 | 1073 | else: |
|
1074 | 1074 | return [] |
|
1075 | 1075 | |
|
1076 | 1076 | # needed to get base class __repr__ running |
|
1077 | 1077 | @property |
|
1078 | 1078 | def _testMethodName(self): |
|
1079 | 1079 | return self.name |
|
1080 | 1080 | |
|
1081 | 1081 | def __str__(self): |
|
1082 | 1082 | return self.name |
|
1083 | 1083 | |
|
1084 | 1084 | def shortDescription(self): |
|
1085 | 1085 | return self.name |
|
1086 | 1086 | |
|
1087 | 1087 | def setUp(self): |
|
1088 | 1088 | """Tasks to perform before run().""" |
|
1089 | 1089 | self._finished = False |
|
1090 | 1090 | self._ret = None |
|
1091 | 1091 | self._out = None |
|
1092 | 1092 | self._skipped = None |
|
1093 | 1093 | |
|
1094 | 1094 | try: |
|
1095 | 1095 | os.mkdir(self._threadtmp) |
|
1096 | 1096 | except OSError as e: |
|
1097 | 1097 | if e.errno != errno.EEXIST: |
|
1098 | 1098 | raise |
|
1099 | 1099 | |
|
1100 | 1100 | name = self._tmpname |
|
1101 | 1101 | self._testtmp = os.path.join(self._threadtmp, name) |
|
1102 | 1102 | os.mkdir(self._testtmp) |
|
1103 | 1103 | |
|
1104 | 1104 | # Remove any previous output files. |
|
1105 | 1105 | if os.path.exists(self.errpath): |
|
1106 | 1106 | try: |
|
1107 | 1107 | os.remove(self.errpath) |
|
1108 | 1108 | except OSError as e: |
|
1109 | 1109 | # We might have raced another test to clean up a .err |
|
1110 | 1110 | # file, so ignore ENOENT when removing a previous .err |
|
1111 | 1111 | # file. |
|
1112 | 1112 | if e.errno != errno.ENOENT: |
|
1113 | 1113 | raise |
|
1114 | 1114 | |
|
1115 | 1115 | if self._usechg: |
|
1116 | 1116 | self._chgsockdir = os.path.join( |
|
1117 | 1117 | self._threadtmp, b'%s.chgsock' % name |
|
1118 | 1118 | ) |
|
1119 | 1119 | os.mkdir(self._chgsockdir) |
|
1120 | 1120 | |
|
1121 | 1121 | def run(self, result): |
|
1122 | 1122 | """Run this test and report results against a TestResult instance.""" |
|
1123 | 1123 | # This function is extremely similar to unittest.TestCase.run(). Once |
|
1124 | 1124 | # we require Python 2.7 (or at least its version of unittest), this |
|
1125 | 1125 | # function can largely go away. |
|
1126 | 1126 | self._result = result |
|
1127 | 1127 | result.startTest(self) |
|
1128 | 1128 | try: |
|
1129 | 1129 | try: |
|
1130 | 1130 | self.setUp() |
|
1131 | 1131 | except (KeyboardInterrupt, SystemExit): |
|
1132 | 1132 | self._aborted = True |
|
1133 | 1133 | raise |
|
1134 | 1134 | except Exception: |
|
1135 | 1135 | result.addError(self, sys.exc_info()) |
|
1136 | 1136 | return |
|
1137 | 1137 | |
|
1138 | 1138 | success = False |
|
1139 | 1139 | try: |
|
1140 | 1140 | self.runTest() |
|
1141 | 1141 | except KeyboardInterrupt: |
|
1142 | 1142 | self._aborted = True |
|
1143 | 1143 | raise |
|
1144 | 1144 | except unittest.SkipTest as e: |
|
1145 | 1145 | result.addSkip(self, str(e)) |
|
1146 | 1146 | # The base class will have already counted this as a |
|
1147 | 1147 | # test we "ran", but we want to exclude skipped tests |
|
1148 | 1148 | # from those we count towards those run. |
|
1149 | 1149 | result.testsRun -= 1 |
|
1150 | 1150 | except self.failureException as e: |
|
1151 | 1151 | # This differs from unittest in that we don't capture |
|
1152 | 1152 | # the stack trace. This is for historical reasons and |
|
1153 | 1153 | # this decision could be revisited in the future, |
|
1154 | 1154 | # especially for PythonTest instances. |
|
1155 | 1155 | if result.addFailure(self, str(e)): |
|
1156 | 1156 | success = True |
|
1157 | 1157 | except Exception: |
|
1158 | 1158 | result.addError(self, sys.exc_info()) |
|
1159 | 1159 | else: |
|
1160 | 1160 | success = True |
|
1161 | 1161 | |
|
1162 | 1162 | try: |
|
1163 | 1163 | self.tearDown() |
|
1164 | 1164 | except (KeyboardInterrupt, SystemExit): |
|
1165 | 1165 | self._aborted = True |
|
1166 | 1166 | raise |
|
1167 | 1167 | except Exception: |
|
1168 | 1168 | result.addError(self, sys.exc_info()) |
|
1169 | 1169 | success = False |
|
1170 | 1170 | |
|
1171 | 1171 | if success: |
|
1172 | 1172 | result.addSuccess(self) |
|
1173 | 1173 | finally: |
|
1174 | 1174 | result.stopTest(self, interrupted=self._aborted) |
|
1175 | 1175 | |
|
1176 | 1176 | def runTest(self): |
|
1177 | 1177 | """Run this test instance. |
|
1178 | 1178 | |
|
1179 | 1179 | This will return a tuple describing the result of the test. |
|
1180 | 1180 | """ |
|
1181 | 1181 | env = self._getenv() |
|
1182 | 1182 | self._genrestoreenv(env) |
|
1183 | 1183 | self._daemonpids.append(env['DAEMON_PIDS']) |
|
1184 | 1184 | self._createhgrc(env['HGRCPATH']) |
|
1185 | 1185 | |
|
1186 | 1186 | vlog('# Test', self.name) |
|
1187 | 1187 | |
|
1188 | 1188 | ret, out = self._run(env) |
|
1189 | 1189 | self._finished = True |
|
1190 | 1190 | self._ret = ret |
|
1191 | 1191 | self._out = out |
|
1192 | 1192 | |
|
1193 | 1193 | def describe(ret): |
|
1194 | 1194 | if ret < 0: |
|
1195 | 1195 | return 'killed by signal: %d' % -ret |
|
1196 | 1196 | return 'returned error code %d' % ret |
|
1197 | 1197 | |
|
1198 | 1198 | self._skipped = False |
|
1199 | 1199 | |
|
1200 | 1200 | if ret == self.SKIPPED_STATUS: |
|
1201 | 1201 | if out is None: # Debug mode, nothing to parse. |
|
1202 | 1202 | missing = ['unknown'] |
|
1203 | 1203 | failed = None |
|
1204 | 1204 | else: |
|
1205 | 1205 | missing, failed = TTest.parsehghaveoutput(out) |
|
1206 | 1206 | |
|
1207 | 1207 | if not missing: |
|
1208 | 1208 | missing = ['skipped'] |
|
1209 | 1209 | |
|
1210 | 1210 | if failed: |
|
1211 | 1211 | self.fail('hg have failed checking for %s' % failed[-1]) |
|
1212 | 1212 | else: |
|
1213 | 1213 | self._skipped = True |
|
1214 | 1214 | raise unittest.SkipTest(missing[-1]) |
|
1215 | 1215 | elif ret == 'timeout': |
|
1216 | 1216 | self.fail('timed out') |
|
1217 | 1217 | elif ret is False: |
|
1218 | 1218 | self.fail('no result code from test') |
|
1219 | 1219 | elif out != self._refout: |
|
1220 | 1220 | # Diff generation may rely on written .err file. |
|
1221 | 1221 | if ( |
|
1222 | 1222 | (ret != 0 or out != self._refout) |
|
1223 | 1223 | and not self._skipped |
|
1224 | 1224 | and not self._debug |
|
1225 | 1225 | ): |
|
1226 | 1226 | with open(self.errpath, 'wb') as f: |
|
1227 | 1227 | for line in out: |
|
1228 | 1228 | f.write(line) |
|
1229 | 1229 | |
|
1230 | 1230 | # The result object handles diff calculation for us. |
|
1231 | 1231 | with firstlock: |
|
1232 | 1232 | if self._result.addOutputMismatch(self, ret, out, self._refout): |
|
1233 | 1233 | # change was accepted, skip failing |
|
1234 | 1234 | return |
|
1235 | 1235 | if self._first: |
|
1236 | 1236 | global firsterror |
|
1237 | 1237 | firsterror = True |
|
1238 | 1238 | |
|
1239 | 1239 | if ret: |
|
1240 | 1240 | msg = 'output changed and ' + describe(ret) |
|
1241 | 1241 | else: |
|
1242 | 1242 | msg = 'output changed' |
|
1243 | 1243 | |
|
1244 | 1244 | self.fail(msg) |
|
1245 | 1245 | elif ret: |
|
1246 | 1246 | self.fail(describe(ret)) |
|
1247 | 1247 | |
|
1248 | 1248 | def tearDown(self): |
|
1249 | 1249 | """Tasks to perform after run().""" |
|
1250 | 1250 | for entry in self._daemonpids: |
|
1251 | 1251 | killdaemons(entry) |
|
1252 | 1252 | self._daemonpids = [] |
|
1253 | 1253 | |
|
1254 | 1254 | if self._keeptmpdir: |
|
1255 | 1255 | log( |
|
1256 | 1256 | '\nKeeping testtmp dir: %s\nKeeping threadtmp dir: %s' |
|
1257 | 1257 | % ( |
|
1258 | 1258 | _bytes2sys(self._testtmp), |
|
1259 | 1259 | _bytes2sys(self._threadtmp), |
|
1260 | 1260 | ) |
|
1261 | 1261 | ) |
|
1262 | 1262 | else: |
|
1263 | 1263 | try: |
|
1264 | 1264 | shutil.rmtree(self._testtmp) |
|
1265 | 1265 | except OSError: |
|
1266 | 1266 | # unreadable directory may be left in $TESTTMP; fix permission |
|
1267 | 1267 | # and try again |
|
1268 | 1268 | makecleanable(self._testtmp) |
|
1269 | 1269 | shutil.rmtree(self._testtmp, True) |
|
1270 | 1270 | shutil.rmtree(self._threadtmp, True) |
|
1271 | 1271 | |
|
1272 | 1272 | if self._usechg: |
|
1273 | 1273 | # chgservers will stop automatically after they find the socket |
|
1274 | 1274 | # files are deleted |
|
1275 | 1275 | shutil.rmtree(self._chgsockdir, True) |
|
1276 | 1276 | |
|
1277 | 1277 | if ( |
|
1278 | 1278 | (self._ret != 0 or self._out != self._refout) |
|
1279 | 1279 | and not self._skipped |
|
1280 | 1280 | and not self._debug |
|
1281 | 1281 | and self._out |
|
1282 | 1282 | ): |
|
1283 | 1283 | with open(self.errpath, 'wb') as f: |
|
1284 | 1284 | for line in self._out: |
|
1285 | 1285 | f.write(line) |
|
1286 | 1286 | |
|
1287 | 1287 | vlog("# Ret was:", self._ret, '(%s)' % self.name) |
|
1288 | 1288 | |
|
1289 | 1289 | def _run(self, env): |
|
1290 | 1290 | # This should be implemented in child classes to run tests. |
|
1291 | 1291 | raise unittest.SkipTest('unknown test type') |
|
1292 | 1292 | |
|
1293 | 1293 | def abort(self): |
|
1294 | 1294 | """Terminate execution of this test.""" |
|
1295 | 1295 | self._aborted = True |
|
1296 | 1296 | |
|
1297 | 1297 | def _portmap(self, i): |
|
1298 | 1298 | offset = b'' if i == 0 else b'%d' % i |
|
1299 | 1299 | return (br':%d\b' % (self._startport + i), b':$HGPORT%s' % offset) |
|
1300 | 1300 | |
|
1301 | 1301 | def _getreplacements(self): |
|
1302 | 1302 | """Obtain a mapping of text replacements to apply to test output. |
|
1303 | 1303 | |
|
1304 | 1304 | Test output needs to be normalized so it can be compared to expected |
|
1305 | 1305 | output. This function defines how some of that normalization will |
|
1306 | 1306 | occur. |
|
1307 | 1307 | """ |
|
1308 | 1308 | r = [ |
|
1309 | 1309 | # This list should be parallel to defineport in _getenv |
|
1310 | 1310 | self._portmap(0), |
|
1311 | 1311 | self._portmap(1), |
|
1312 | 1312 | self._portmap(2), |
|
1313 | 1313 | (br'([^0-9])%s' % re.escape(self._localip()), br'\1$LOCALIP'), |
|
1314 | 1314 | (br'\bHG_TXNID=TXN:[a-f0-9]{40}\b', br'HG_TXNID=TXN:$ID$'), |
|
1315 | 1315 | ] |
|
1316 | 1316 | r.append((self._escapepath(self._testtmp), b'$TESTTMP')) |
|
1317 | 1317 | if WINDOWS: |
|
1318 | 1318 | # JSON output escapes backslashes in Windows paths, so also catch a |
|
1319 | 1319 | # double-escape. |
|
1320 | 1320 | replaced = self._testtmp.replace(b'\\', br'\\') |
|
1321 | 1321 | r.append((self._escapepath(replaced), b'$STR_REPR_TESTTMP')) |
|
1322 | 1322 | |
|
1323 | 1323 | replacementfile = os.path.join(self._testdir, b'common-pattern.py') |
|
1324 | 1324 | |
|
1325 | 1325 | if os.path.exists(replacementfile): |
|
1326 | 1326 | data = {} |
|
1327 | 1327 | with open(replacementfile, mode='rb') as source: |
|
1328 | 1328 | # the intermediate 'compile' step help with debugging |
|
1329 | 1329 | code = compile(source.read(), replacementfile, 'exec') |
|
1330 | 1330 | exec(code, data) |
|
1331 | 1331 | for value in data.get('substitutions', ()): |
|
1332 | 1332 | if len(value) != 2: |
|
1333 | 1333 | msg = 'malformatted substitution in %s: %r' |
|
1334 | 1334 | msg %= (replacementfile, value) |
|
1335 | 1335 | raise ValueError(msg) |
|
1336 | 1336 | r.append(value) |
|
1337 | 1337 | return r |
|
1338 | 1338 | |
|
1339 | 1339 | def _escapepath(self, p): |
|
1340 | 1340 | if WINDOWS: |
|
1341 | 1341 | return b''.join( |
|
1342 | 1342 | c.isalpha() |
|
1343 | 1343 | and b'[%s%s]' % (c.lower(), c.upper()) |
|
1344 | 1344 | or c in b'/\\' |
|
1345 | 1345 | and br'[/\\]' |
|
1346 | 1346 | or c.isdigit() |
|
1347 | 1347 | and c |
|
1348 | 1348 | or b'\\' + c |
|
1349 | 1349 | for c in [p[i : i + 1] for i in range(len(p))] |
|
1350 | 1350 | ) |
|
1351 | 1351 | else: |
|
1352 | 1352 | return re.escape(p) |
|
1353 | 1353 | |
|
1354 | 1354 | def _localip(self): |
|
1355 | 1355 | if self._useipv6: |
|
1356 | 1356 | return b'::1' |
|
1357 | 1357 | else: |
|
1358 | 1358 | return b'127.0.0.1' |
|
1359 | 1359 | |
|
1360 | 1360 | def _genrestoreenv(self, testenv): |
|
1361 | 1361 | """Generate a script that can be used by tests to restore the original |
|
1362 | 1362 | environment.""" |
|
1363 | 1363 | # Put the restoreenv script inside self._threadtmp |
|
1364 | 1364 | scriptpath = os.path.join(self._threadtmp, b'restoreenv.sh') |
|
1365 | 1365 | testenv['HGTEST_RESTOREENV'] = _bytes2sys(scriptpath) |
|
1366 | 1366 | |
|
1367 | 1367 | # Only restore environment variable names that the shell allows |
|
1368 | 1368 | # us to export. |
|
1369 | 1369 | name_regex = re.compile('^[a-zA-Z][a-zA-Z0-9_]*$') |
|
1370 | 1370 | |
|
1371 | 1371 | # Do not restore these variables; otherwise tests would fail. |
|
1372 | 1372 | reqnames = {'PYTHON', 'TESTDIR', 'TESTTMP'} |
|
1373 | 1373 | |
|
1374 | 1374 | with open(scriptpath, 'w') as envf: |
|
1375 | 1375 | for name, value in origenviron.items(): |
|
1376 | 1376 | if not name_regex.match(name): |
|
1377 | 1377 | # Skip environment variables with unusual names not |
|
1378 | 1378 | # allowed by most shells. |
|
1379 | 1379 | continue |
|
1380 | 1380 | if name in reqnames: |
|
1381 | 1381 | continue |
|
1382 | 1382 | envf.write('%s=%s\n' % (name, shellquote(value))) |
|
1383 | 1383 | |
|
1384 | 1384 | for name in testenv: |
|
1385 | 1385 | if name in origenviron or name in reqnames: |
|
1386 | 1386 | continue |
|
1387 | 1387 | envf.write('unset %s\n' % (name,)) |
|
1388 | 1388 | |
|
1389 | 1389 | def _getenv(self): |
|
1390 | 1390 | """Obtain environment variables to use during test execution.""" |
|
1391 | 1391 | |
|
1392 | 1392 | def defineport(i): |
|
1393 | 1393 | offset = '' if i == 0 else '%s' % i |
|
1394 | 1394 | env["HGPORT%s" % offset] = '%s' % (self._startport + i) |
|
1395 | 1395 | |
|
1396 | 1396 | env = os.environ.copy() |
|
1397 | 1397 | env['PYTHONUSERBASE'] = sysconfig.get_config_var('userbase') or '' |
|
1398 | 1398 | env['HGEMITWARNINGS'] = '1' |
|
1399 | 1399 | env['TESTTMP'] = _bytes2sys(self._testtmp) |
|
1400 | 1400 | uid_file = os.path.join(_bytes2sys(self._testtmp), 'UID') |
|
1401 | 1401 | env['HGTEST_UUIDFILE'] = uid_file |
|
1402 | 1402 | env['TESTNAME'] = self.name |
|
1403 | 1403 | env['HOME'] = _bytes2sys(self._testtmp) |
|
1404 | 1404 | if WINDOWS: |
|
1405 | 1405 | env['REALUSERPROFILE'] = env['USERPROFILE'] |
|
1406 | 1406 | # py3.8+ ignores HOME: https://bugs.python.org/issue36264 |
|
1407 | 1407 | env['USERPROFILE'] = env['HOME'] |
|
1408 | 1408 | formated_timeout = _bytes2sys(b"%d" % default_defaults['timeout'][1]) |
|
1409 | 1409 | env['HGTEST_TIMEOUT_DEFAULT'] = formated_timeout |
|
1410 | 1410 | env['HGTEST_TIMEOUT'] = _bytes2sys(b"%d" % self._timeout) |
|
1411 | 1411 | # This number should match portneeded in _getport |
|
1412 | 1412 | for port in xrange(3): |
|
1413 | 1413 | # This list should be parallel to _portmap in _getreplacements |
|
1414 | 1414 | defineport(port) |
|
1415 | 1415 | env["HGRCPATH"] = _bytes2sys(os.path.join(self._threadtmp, b'.hgrc')) |
|
1416 | 1416 | env["DAEMON_PIDS"] = _bytes2sys( |
|
1417 | 1417 | os.path.join(self._threadtmp, b'daemon.pids') |
|
1418 | 1418 | ) |
|
1419 | 1419 | env["HGEDITOR"] = ( |
|
1420 | 1420 | '"' + sysexecutable + '"' + ' -c "import sys; sys.exit(0)"' |
|
1421 | 1421 | ) |
|
1422 | 1422 | env["HGUSER"] = "test" |
|
1423 | 1423 | env["HGENCODING"] = "ascii" |
|
1424 | 1424 | env["HGENCODINGMODE"] = "strict" |
|
1425 | 1425 | env["HGHOSTNAME"] = "test-hostname" |
|
1426 | 1426 | env['HGIPV6'] = str(int(self._useipv6)) |
|
1427 | 1427 | # See contrib/catapipe.py for how to use this functionality. |
|
1428 | 1428 | if 'HGTESTCATAPULTSERVERPIPE' not in env: |
|
1429 | 1429 | # If we don't have HGTESTCATAPULTSERVERPIPE explicitly set, pull the |
|
1430 | 1430 | # non-test one in as a default, otherwise set to devnull |
|
1431 | 1431 | env['HGTESTCATAPULTSERVERPIPE'] = env.get( |
|
1432 | 1432 | 'HGCATAPULTSERVERPIPE', os.devnull |
|
1433 | 1433 | ) |
|
1434 | 1434 | |
|
1435 | 1435 | extraextensions = [] |
|
1436 | 1436 | for opt in self._extraconfigopts: |
|
1437 | 1437 | section, key = opt.split('.', 1) |
|
1438 | 1438 | if section != 'extensions': |
|
1439 | 1439 | continue |
|
1440 | 1440 | name = key.split('=', 1)[0] |
|
1441 | 1441 | extraextensions.append(name) |
|
1442 | 1442 | |
|
1443 | 1443 | if extraextensions: |
|
1444 | 1444 | env['HGTESTEXTRAEXTENSIONS'] = ' '.join(extraextensions) |
|
1445 | 1445 | |
|
1446 | 1446 | # LOCALIP could be ::1 or 127.0.0.1. Useful for tests that require raw |
|
1447 | 1447 | # IP addresses. |
|
1448 | 1448 | env['LOCALIP'] = _bytes2sys(self._localip()) |
|
1449 | 1449 | |
|
1450 | 1450 | # This has the same effect as Py_LegacyWindowsStdioFlag in exewrapper.c, |
|
1451 | 1451 | # but this is needed for testing python instances like dummyssh, |
|
1452 | 1452 | # dummysmtpd.py, and dumbhttp.py. |
|
1453 | 1453 | if PYTHON3 and WINDOWS: |
|
1454 | 1454 | env['PYTHONLEGACYWINDOWSSTDIO'] = '1' |
|
1455 | 1455 | |
|
1456 | 1456 | # Modified HOME in test environment can confuse Rust tools. So set |
|
1457 | 1457 | # CARGO_HOME and RUSTUP_HOME automatically if a Rust toolchain is |
|
1458 | 1458 | # present and these variables aren't already defined. |
|
1459 | 1459 | cargo_home_path = os.path.expanduser('~/.cargo') |
|
1460 | 1460 | rustup_home_path = os.path.expanduser('~/.rustup') |
|
1461 | 1461 | |
|
1462 | 1462 | if os.path.exists(cargo_home_path) and b'CARGO_HOME' not in osenvironb: |
|
1463 | 1463 | env['CARGO_HOME'] = cargo_home_path |
|
1464 | 1464 | if ( |
|
1465 | 1465 | os.path.exists(rustup_home_path) |
|
1466 | 1466 | and b'RUSTUP_HOME' not in osenvironb |
|
1467 | 1467 | ): |
|
1468 | 1468 | env['RUSTUP_HOME'] = rustup_home_path |
|
1469 | 1469 | |
|
1470 | 1470 | # Reset some environment variables to well-known values so that |
|
1471 | 1471 | # the tests produce repeatable output. |
|
1472 | 1472 | env['LANG'] = env['LC_ALL'] = env['LANGUAGE'] = 'C' |
|
1473 | 1473 | env['TZ'] = 'GMT' |
|
1474 | 1474 | env["EMAIL"] = "Foo Bar <foo.bar@example.com>" |
|
1475 | 1475 | env['COLUMNS'] = '80' |
|
1476 | 1476 | env['TERM'] = 'xterm' |
|
1477 | 1477 | |
|
1478 | 1478 | dropped = [ |
|
1479 | 1479 | 'CDPATH', |
|
1480 | 1480 | 'CHGDEBUG', |
|
1481 | 1481 | 'EDITOR', |
|
1482 | 1482 | 'GREP_OPTIONS', |
|
1483 | 1483 | 'HG', |
|
1484 | 1484 | 'HGMERGE', |
|
1485 | 1485 | 'HGPLAIN', |
|
1486 | 1486 | 'HGPLAINEXCEPT', |
|
1487 | 1487 | 'HGPROF', |
|
1488 | 1488 | 'http_proxy', |
|
1489 | 1489 | 'no_proxy', |
|
1490 | 1490 | 'NO_PROXY', |
|
1491 | 1491 | 'PAGER', |
|
1492 | 1492 | 'VISUAL', |
|
1493 | 1493 | ] |
|
1494 | 1494 | |
|
1495 | 1495 | for k in dropped: |
|
1496 | 1496 | if k in env: |
|
1497 | 1497 | del env[k] |
|
1498 | 1498 | |
|
1499 | 1499 | # unset env related to hooks |
|
1500 | 1500 | for k in list(env): |
|
1501 | 1501 | if k.startswith('HG_'): |
|
1502 | 1502 | del env[k] |
|
1503 | 1503 | |
|
1504 | 1504 | if self._usechg: |
|
1505 | 1505 | env['CHGSOCKNAME'] = os.path.join(self._chgsockdir, b'server') |
|
1506 | 1506 | if self._chgdebug: |
|
1507 | 1507 | env['CHGDEBUG'] = 'true' |
|
1508 | 1508 | |
|
1509 | 1509 | return env |
|
1510 | 1510 | |
|
1511 | 1511 | def _createhgrc(self, path): |
|
1512 | 1512 | """Create an hgrc file for this test.""" |
|
1513 | 1513 | with open(path, 'wb') as hgrc: |
|
1514 | 1514 | hgrc.write(b'[ui]\n') |
|
1515 | 1515 | hgrc.write(b'slash = True\n') |
|
1516 | 1516 | hgrc.write(b'interactive = False\n') |
|
1517 | 1517 | hgrc.write(b'detailed-exit-code = True\n') |
|
1518 | 1518 | hgrc.write(b'merge = internal:merge\n') |
|
1519 | 1519 | hgrc.write(b'mergemarkers = detailed\n') |
|
1520 | 1520 | hgrc.write(b'promptecho = True\n') |
|
1521 | 1521 | hgrc.write(b'timeout.warn=15\n') |
|
1522 | 1522 | hgrc.write(b'[defaults]\n') |
|
1523 | 1523 | hgrc.write(b'[devel]\n') |
|
1524 | 1524 | hgrc.write(b'all-warnings = true\n') |
|
1525 | 1525 | hgrc.write(b'default-date = 0 0\n') |
|
1526 | 1526 | hgrc.write(b'[largefiles]\n') |
|
1527 | 1527 | hgrc.write( |
|
1528 | 1528 | b'usercache = %s\n' |
|
1529 | 1529 | % (os.path.join(self._testtmp, b'.cache/largefiles')) |
|
1530 | 1530 | ) |
|
1531 | 1531 | hgrc.write(b'[lfs]\n') |
|
1532 | 1532 | hgrc.write( |
|
1533 | 1533 | b'usercache = %s\n' |
|
1534 | 1534 | % (os.path.join(self._testtmp, b'.cache/lfs')) |
|
1535 | 1535 | ) |
|
1536 | 1536 | hgrc.write(b'[web]\n') |
|
1537 | 1537 | hgrc.write(b'address = localhost\n') |
|
1538 | 1538 | hgrc.write(b'ipv6 = %r\n' % self._useipv6) |
|
1539 | 1539 | hgrc.write(b'server-header = testing stub value\n') |
|
1540 | 1540 | |
|
1541 | 1541 | for opt in self._extraconfigopts: |
|
1542 | 1542 | section, key = _sys2bytes(opt).split(b'.', 1) |
|
1543 | 1543 | assert b'=' in key, ( |
|
1544 | 1544 | 'extra config opt %s must ' 'have an = for assignment' % opt |
|
1545 | 1545 | ) |
|
1546 | 1546 | hgrc.write(b'[%s]\n%s\n' % (section, key)) |
|
1547 | 1547 | |
|
1548 | 1548 | def fail(self, msg): |
|
1549 | 1549 | # unittest differentiates between errored and failed. |
|
1550 | 1550 | # Failed is denoted by AssertionError (by default at least). |
|
1551 | 1551 | raise AssertionError(msg) |
|
1552 | 1552 | |
|
1553 | 1553 | def _runcommand(self, cmd, env, normalizenewlines=False): |
|
1554 | 1554 | """Run command in a sub-process, capturing the output (stdout and |
|
1555 | 1555 | stderr). |
|
1556 | 1556 | |
|
1557 | 1557 | Return a tuple (exitcode, output). output is None in debug mode. |
|
1558 | 1558 | """ |
|
1559 | 1559 | if self._debug: |
|
1560 | 1560 | proc = subprocess.Popen( |
|
1561 | 1561 | _bytes2sys(cmd), |
|
1562 | 1562 | shell=True, |
|
1563 | 1563 | cwd=_bytes2sys(self._testtmp), |
|
1564 | 1564 | env=env, |
|
1565 | 1565 | ) |
|
1566 | 1566 | ret = proc.wait() |
|
1567 | 1567 | return (ret, None) |
|
1568 | 1568 | |
|
1569 | 1569 | proc = Popen4(cmd, self._testtmp, self._timeout, env) |
|
1570 | 1570 | |
|
1571 | 1571 | def cleanup(): |
|
1572 | 1572 | terminate(proc) |
|
1573 | 1573 | ret = proc.wait() |
|
1574 | 1574 | if ret == 0: |
|
1575 | 1575 | ret = signal.SIGTERM << 8 |
|
1576 | 1576 | killdaemons(env['DAEMON_PIDS']) |
|
1577 | 1577 | return ret |
|
1578 | 1578 | |
|
1579 | 1579 | proc.tochild.close() |
|
1580 | 1580 | |
|
1581 | 1581 | try: |
|
1582 | 1582 | output = proc.fromchild.read() |
|
1583 | 1583 | except KeyboardInterrupt: |
|
1584 | 1584 | vlog('# Handling keyboard interrupt') |
|
1585 | 1585 | cleanup() |
|
1586 | 1586 | raise |
|
1587 | 1587 | |
|
1588 | 1588 | ret = proc.wait() |
|
1589 | 1589 | if wifexited(ret): |
|
1590 | 1590 | ret = os.WEXITSTATUS(ret) |
|
1591 | 1591 | |
|
1592 | 1592 | if proc.timeout: |
|
1593 | 1593 | ret = 'timeout' |
|
1594 | 1594 | |
|
1595 | 1595 | if ret: |
|
1596 | 1596 | killdaemons(env['DAEMON_PIDS']) |
|
1597 | 1597 | |
|
1598 | 1598 | for s, r in self._getreplacements(): |
|
1599 | 1599 | output = re.sub(s, r, output) |
|
1600 | 1600 | |
|
1601 | 1601 | if normalizenewlines: |
|
1602 | 1602 | output = output.replace(b'\r\n', b'\n') |
|
1603 | 1603 | |
|
1604 | 1604 | return ret, output.splitlines(True) |
|
1605 | 1605 | |
|
1606 | 1606 | |
|
1607 | 1607 | class PythonTest(Test): |
|
1608 | 1608 | """A Python-based test.""" |
|
1609 | 1609 | |
|
1610 | 1610 | @property |
|
1611 | 1611 | def refpath(self): |
|
1612 | 1612 | return os.path.join(self._testdir, b'%s.out' % self.bname) |
|
1613 | 1613 | |
|
1614 | 1614 | def _run(self, env): |
|
1615 | 1615 | # Quote the python(3) executable for Windows |
|
1616 | 1616 | cmd = b'"%s" "%s"' % (PYTHON, self.path) |
|
1617 | 1617 | vlog("# Running", cmd.decode("utf-8")) |
|
1618 | 1618 | result = self._runcommand(cmd, env, normalizenewlines=WINDOWS) |
|
1619 | 1619 | if self._aborted: |
|
1620 | 1620 | raise KeyboardInterrupt() |
|
1621 | 1621 | |
|
1622 | 1622 | return result |
|
1623 | 1623 | |
|
1624 | 1624 | |
|
1625 | 1625 | # Some glob patterns apply only in some circumstances, so the script |
|
1626 | 1626 | # might want to remove (glob) annotations that otherwise should be |
|
1627 | 1627 | # retained. |
|
1628 | 1628 | checkcodeglobpats = [ |
|
1629 | 1629 | # On Windows it looks like \ doesn't require a (glob), but we know |
|
1630 | 1630 | # better. |
|
1631 | 1631 | re.compile(br'^pushing to \$TESTTMP/.*[^)]$'), |
|
1632 | 1632 | re.compile(br'^moving \S+/.*[^)]$'), |
|
1633 | 1633 | re.compile(br'^pulling from \$TESTTMP/.*[^)]$'), |
|
1634 | 1634 | # Not all platforms have 127.0.0.1 as loopback (though most do), |
|
1635 | 1635 | # so we always glob that too. |
|
1636 | 1636 | re.compile(br'.*\$LOCALIP.*$'), |
|
1637 | 1637 | ] |
|
1638 | 1638 | |
|
1639 | 1639 | bchr = chr |
|
1640 | 1640 | if PYTHON3: |
|
1641 | 1641 | bchr = lambda x: bytes([x]) |
|
1642 | 1642 | |
|
1643 | 1643 | WARN_UNDEFINED = 1 |
|
1644 | 1644 | WARN_YES = 2 |
|
1645 | 1645 | WARN_NO = 3 |
|
1646 | 1646 | |
|
1647 | 1647 | MARK_OPTIONAL = b" (?)\n" |
|
1648 | 1648 | |
|
1649 | 1649 | |
|
1650 | 1650 | def isoptional(line): |
|
1651 | 1651 | return line.endswith(MARK_OPTIONAL) |
|
1652 | 1652 | |
|
1653 | 1653 | |
|
1654 | 1654 | class TTest(Test): |
|
1655 | 1655 | """A "t test" is a test backed by a .t file.""" |
|
1656 | 1656 | |
|
1657 | 1657 | SKIPPED_PREFIX = b'skipped: ' |
|
1658 | 1658 | FAILED_PREFIX = b'hghave check failed: ' |
|
1659 | 1659 | NEEDESCAPE = re.compile(br'[\x00-\x08\x0b-\x1f\x7f-\xff]').search |
|
1660 | 1660 | |
|
1661 | 1661 | ESCAPESUB = re.compile(br'[\x00-\x08\x0b-\x1f\\\x7f-\xff]').sub |
|
1662 | 1662 | ESCAPEMAP = {bchr(i): br'\x%02x' % i for i in range(256)} |
|
1663 | 1663 | ESCAPEMAP.update({b'\\': b'\\\\', b'\r': br'\r'}) |
|
1664 | 1664 | |
|
1665 | 1665 | def __init__(self, path, *args, **kwds): |
|
1666 | 1666 | # accept an extra "case" parameter |
|
1667 | 1667 | case = kwds.pop('case', []) |
|
1668 | 1668 | self._case = case |
|
1669 | 1669 | self._allcases = {x for y in parsettestcases(path) for x in y} |
|
1670 | 1670 | super(TTest, self).__init__(path, *args, **kwds) |
|
1671 | 1671 | if case: |
|
1672 | 1672 | casepath = b'#'.join(case) |
|
1673 | 1673 | self.name = '%s#%s' % (self.name, _bytes2sys(casepath)) |
|
1674 | 1674 | self.errpath = b'%s#%s.err' % (self.errpath[:-4], casepath) |
|
1675 | 1675 | self._tmpname += b'-%s' % casepath.replace(b'#', b'-') |
|
1676 | 1676 | self._have = {} |
|
1677 | 1677 | |
|
1678 | 1678 | @property |
|
1679 | 1679 | def refpath(self): |
|
1680 | 1680 | return os.path.join(self._testdir, self.bname) |
|
1681 | 1681 | |
|
1682 | 1682 | def _run(self, env): |
|
1683 | 1683 | with open(self.path, 'rb') as f: |
|
1684 | 1684 | lines = f.readlines() |
|
1685 | 1685 | |
|
1686 | 1686 | # .t file is both reference output and the test input, keep reference |
|
1687 | 1687 | # output updated with the the test input. This avoids some race |
|
1688 | 1688 | # conditions where the reference output does not match the actual test. |
|
1689 | 1689 | if self._refout is not None: |
|
1690 | 1690 | self._refout = lines |
|
1691 | 1691 | |
|
1692 | 1692 | salt, script, after, expected = self._parsetest(lines) |
|
1693 | 1693 | |
|
1694 | 1694 | # Write out the generated script. |
|
1695 | 1695 | fname = b'%s.sh' % self._testtmp |
|
1696 | 1696 | with open(fname, 'wb') as f: |
|
1697 | 1697 | for l in script: |
|
1698 | 1698 | f.write(l) |
|
1699 | 1699 | |
|
1700 | 1700 | cmd = b'%s "%s"' % (self._shell, fname) |
|
1701 | 1701 | vlog("# Running", cmd.decode("utf-8")) |
|
1702 | 1702 | |
|
1703 | 1703 | exitcode, output = self._runcommand(cmd, env) |
|
1704 | 1704 | |
|
1705 | 1705 | if self._aborted: |
|
1706 | 1706 | raise KeyboardInterrupt() |
|
1707 | 1707 | |
|
1708 | 1708 | # Do not merge output if skipped. Return hghave message instead. |
|
1709 | 1709 | # Similarly, with --debug, output is None. |
|
1710 | 1710 | if exitcode == self.SKIPPED_STATUS or output is None: |
|
1711 | 1711 | return exitcode, output |
|
1712 | 1712 | |
|
1713 | 1713 | return self._processoutput(exitcode, output, salt, after, expected) |
|
1714 | 1714 | |
|
1715 | 1715 | def _hghave(self, reqs): |
|
1716 | 1716 | allreqs = b' '.join(reqs) |
|
1717 | 1717 | |
|
1718 | 1718 | self._detectslow(reqs) |
|
1719 | 1719 | |
|
1720 | 1720 | if allreqs in self._have: |
|
1721 | 1721 | return self._have.get(allreqs) |
|
1722 | 1722 | |
|
1723 | 1723 | # TODO do something smarter when all other uses of hghave are gone. |
|
1724 | 1724 | runtestdir = osenvironb[b'RUNTESTDIR'] |
|
1725 | 1725 | tdir = runtestdir.replace(b'\\', b'/') |
|
1726 | 1726 | proc = Popen4( |
|
1727 | 1727 | b'%s -c "%s/hghave %s"' % (self._shell, tdir, allreqs), |
|
1728 | 1728 | self._testtmp, |
|
1729 | 1729 | 0, |
|
1730 | 1730 | self._getenv(), |
|
1731 | 1731 | ) |
|
1732 | 1732 | stdout, stderr = proc.communicate() |
|
1733 | 1733 | ret = proc.wait() |
|
1734 | 1734 | if wifexited(ret): |
|
1735 | 1735 | ret = os.WEXITSTATUS(ret) |
|
1736 | 1736 | if ret == 2: |
|
1737 | 1737 | print(stdout.decode('utf-8')) |
|
1738 | 1738 | sys.exit(1) |
|
1739 | 1739 | |
|
1740 | 1740 | if ret != 0: |
|
1741 | 1741 | self._have[allreqs] = (False, stdout) |
|
1742 | 1742 | return False, stdout |
|
1743 | 1743 | |
|
1744 | 1744 | self._have[allreqs] = (True, None) |
|
1745 | 1745 | return True, None |
|
1746 | 1746 | |
|
1747 | 1747 | def _detectslow(self, reqs): |
|
1748 | 1748 | """update the timeout of slow test when appropriate""" |
|
1749 | 1749 | if b'slow' in reqs: |
|
1750 | 1750 | self._timeout = self._slowtimeout |
|
1751 | 1751 | |
|
1752 | 1752 | def _iftest(self, args): |
|
1753 | 1753 | # implements "#if" |
|
1754 | 1754 | reqs = [] |
|
1755 | 1755 | for arg in args: |
|
1756 | 1756 | if arg.startswith(b'no-') and arg[3:] in self._allcases: |
|
1757 | 1757 | if arg[3:] in self._case: |
|
1758 | 1758 | return False |
|
1759 | 1759 | elif arg in self._allcases: |
|
1760 | 1760 | if arg not in self._case: |
|
1761 | 1761 | return False |
|
1762 | 1762 | else: |
|
1763 | 1763 | reqs.append(arg) |
|
1764 | 1764 | self._detectslow(reqs) |
|
1765 | 1765 | return self._hghave(reqs)[0] |
|
1766 | 1766 | |
|
1767 | 1767 | def _parsetest(self, lines): |
|
1768 | 1768 | # We generate a shell script which outputs unique markers to line |
|
1769 | 1769 | # up script results with our source. These markers include input |
|
1770 | 1770 | # line number and the last return code. |
|
1771 | 1771 | salt = b"SALT%d" % time.time() |
|
1772 | 1772 | |
|
1773 | 1773 | def addsalt(line, inpython): |
|
1774 | 1774 | if inpython: |
|
1775 | 1775 | script.append(b'%s %d 0\n' % (salt, line)) |
|
1776 | 1776 | else: |
|
1777 | 1777 | script.append(b'echo %s %d $?\n' % (salt, line)) |
|
1778 | 1778 | |
|
1779 | 1779 | activetrace = [] |
|
1780 | 1780 | session = str(uuid.uuid4()) |
|
1781 | 1781 | if PYTHON3: |
|
1782 | 1782 | session = session.encode('ascii') |
|
1783 | 1783 | hgcatapult = os.getenv('HGTESTCATAPULTSERVERPIPE') or os.getenv( |
|
1784 | 1784 | 'HGCATAPULTSERVERPIPE' |
|
1785 | 1785 | ) |
|
1786 | 1786 | |
|
1787 | 1787 | def toggletrace(cmd=None): |
|
1788 | 1788 | if not hgcatapult or hgcatapult == os.devnull: |
|
1789 | 1789 | return |
|
1790 | 1790 | |
|
1791 | 1791 | if activetrace: |
|
1792 | 1792 | script.append( |
|
1793 | 1793 | b'echo END %s %s >> "$HGTESTCATAPULTSERVERPIPE"\n' |
|
1794 | 1794 | % (session, activetrace[0]) |
|
1795 | 1795 | ) |
|
1796 | 1796 | if cmd is None: |
|
1797 | 1797 | return |
|
1798 | 1798 | |
|
1799 | 1799 | if isinstance(cmd, str): |
|
1800 | 1800 | quoted = shellquote(cmd.strip()) |
|
1801 | 1801 | else: |
|
1802 | 1802 | quoted = shellquote(cmd.strip().decode('utf8')).encode('utf8') |
|
1803 | 1803 | quoted = quoted.replace(b'\\', b'\\\\') |
|
1804 | 1804 | script.append( |
|
1805 | 1805 | b'echo START %s %s >> "$HGTESTCATAPULTSERVERPIPE"\n' |
|
1806 | 1806 | % (session, quoted) |
|
1807 | 1807 | ) |
|
1808 | 1808 | activetrace[0:] = [quoted] |
|
1809 | 1809 | |
|
1810 | 1810 | script = [] |
|
1811 | 1811 | |
|
1812 | 1812 | # After we run the shell script, we re-unify the script output |
|
1813 | 1813 | # with non-active parts of the source, with synchronization by our |
|
1814 | 1814 | # SALT line number markers. The after table contains the non-active |
|
1815 | 1815 | # components, ordered by line number. |
|
1816 | 1816 | after = {} |
|
1817 | 1817 | |
|
1818 | 1818 | # Expected shell script output. |
|
1819 | 1819 | expected = {} |
|
1820 | 1820 | |
|
1821 | 1821 | pos = prepos = -1 |
|
1822 | 1822 | |
|
1823 | 1823 | # True or False when in a true or false conditional section |
|
1824 | 1824 | skipping = None |
|
1825 | 1825 | |
|
1826 | 1826 | # We keep track of whether or not we're in a Python block so we |
|
1827 | 1827 | # can generate the surrounding doctest magic. |
|
1828 | 1828 | inpython = False |
|
1829 | 1829 | |
|
1830 | 1830 | if self._debug: |
|
1831 | 1831 | script.append(b'set -x\n') |
|
1832 | 1832 | if self._hgcommand != b'hg': |
|
1833 | 1833 | script.append(b'alias hg="%s"\n' % self._hgcommand) |
|
1834 | 1834 | if os.getenv('MSYSTEM'): |
|
1835 | 1835 | script.append(b'alias pwd="pwd -W"\n') |
|
1836 | 1836 | |
|
1837 | 1837 | if hgcatapult and hgcatapult != os.devnull: |
|
1838 | 1838 | if PYTHON3: |
|
1839 | 1839 | hgcatapult = hgcatapult.encode('utf8') |
|
1840 | 1840 | cataname = self.name.encode('utf8') |
|
1841 | 1841 | else: |
|
1842 | 1842 | cataname = self.name |
|
1843 | 1843 | |
|
1844 | 1844 | # Kludge: use a while loop to keep the pipe from getting |
|
1845 | 1845 | # closed by our echo commands. The still-running file gets |
|
1846 | 1846 | # reaped at the end of the script, which causes the while |
|
1847 | 1847 | # loop to exit and closes the pipe. Sigh. |
|
1848 | 1848 | script.append( |
|
1849 | 1849 | b'rtendtracing() {\n' |
|
1850 | 1850 | b' echo END %(session)s %(name)s >> %(catapult)s\n' |
|
1851 | 1851 | b' rm -f "$TESTTMP/.still-running"\n' |
|
1852 | 1852 | b'}\n' |
|
1853 | 1853 | b'trap "rtendtracing" 0\n' |
|
1854 | 1854 | b'touch "$TESTTMP/.still-running"\n' |
|
1855 | 1855 | b'while [ -f "$TESTTMP/.still-running" ]; do sleep 1; done ' |
|
1856 | 1856 | b'> %(catapult)s &\n' |
|
1857 | 1857 | b'HGCATAPULTSESSION=%(session)s ; export HGCATAPULTSESSION\n' |
|
1858 | 1858 | b'echo START %(session)s %(name)s >> %(catapult)s\n' |
|
1859 | 1859 | % { |
|
1860 | 1860 | b'name': cataname, |
|
1861 | 1861 | b'session': session, |
|
1862 | 1862 | b'catapult': hgcatapult, |
|
1863 | 1863 | } |
|
1864 | 1864 | ) |
|
1865 | 1865 | |
|
1866 | 1866 | if self._case: |
|
1867 | 1867 | casestr = b'#'.join(self._case) |
|
1868 | 1868 | if isinstance(casestr, str): |
|
1869 | 1869 | quoted = shellquote(casestr) |
|
1870 | 1870 | else: |
|
1871 | 1871 | quoted = shellquote(casestr.decode('utf8')).encode('utf8') |
|
1872 | 1872 | script.append(b'TESTCASE=%s\n' % quoted) |
|
1873 | 1873 | script.append(b'export TESTCASE\n') |
|
1874 | 1874 | |
|
1875 | 1875 | n = 0 |
|
1876 | 1876 | for n, l in enumerate(lines): |
|
1877 | 1877 | if not l.endswith(b'\n'): |
|
1878 | 1878 | l += b'\n' |
|
1879 | 1879 | if l.startswith(b'#require'): |
|
1880 | 1880 | lsplit = l.split() |
|
1881 | 1881 | if len(lsplit) < 2 or lsplit[0] != b'#require': |
|
1882 | 1882 | after.setdefault(pos, []).append( |
|
1883 | 1883 | b' !!! invalid #require\n' |
|
1884 | 1884 | ) |
|
1885 | 1885 | if not skipping: |
|
1886 | 1886 | haveresult, message = self._hghave(lsplit[1:]) |
|
1887 | 1887 | if not haveresult: |
|
1888 | 1888 | script = [b'echo "%s"\nexit 80\n' % message] |
|
1889 | 1889 | break |
|
1890 | 1890 | after.setdefault(pos, []).append(l) |
|
1891 | 1891 | elif l.startswith(b'#if'): |
|
1892 | 1892 | lsplit = l.split() |
|
1893 | 1893 | if len(lsplit) < 2 or lsplit[0] != b'#if': |
|
1894 | 1894 | after.setdefault(pos, []).append(b' !!! invalid #if\n') |
|
1895 | 1895 | if skipping is not None: |
|
1896 | 1896 | after.setdefault(pos, []).append(b' !!! nested #if\n') |
|
1897 | 1897 | skipping = not self._iftest(lsplit[1:]) |
|
1898 | 1898 | after.setdefault(pos, []).append(l) |
|
1899 | 1899 | elif l.startswith(b'#else'): |
|
1900 | 1900 | if skipping is None: |
|
1901 | 1901 | after.setdefault(pos, []).append(b' !!! missing #if\n') |
|
1902 | 1902 | skipping = not skipping |
|
1903 | 1903 | after.setdefault(pos, []).append(l) |
|
1904 | 1904 | elif l.startswith(b'#endif'): |
|
1905 | 1905 | if skipping is None: |
|
1906 | 1906 | after.setdefault(pos, []).append(b' !!! missing #if\n') |
|
1907 | 1907 | skipping = None |
|
1908 | 1908 | after.setdefault(pos, []).append(l) |
|
1909 | 1909 | elif skipping: |
|
1910 | 1910 | after.setdefault(pos, []).append(l) |
|
1911 | 1911 | elif l.startswith(b' >>> '): # python inlines |
|
1912 | 1912 | after.setdefault(pos, []).append(l) |
|
1913 | 1913 | prepos = pos |
|
1914 | 1914 | pos = n |
|
1915 | 1915 | if not inpython: |
|
1916 | 1916 | # We've just entered a Python block. Add the header. |
|
1917 | 1917 | inpython = True |
|
1918 | 1918 | addsalt(prepos, False) # Make sure we report the exit code. |
|
1919 | 1919 | script.append(b'"%s" -m heredoctest <<EOF\n' % PYTHON) |
|
1920 | 1920 | addsalt(n, True) |
|
1921 | 1921 | script.append(l[2:]) |
|
1922 | 1922 | elif l.startswith(b' ... '): # python inlines |
|
1923 | 1923 | after.setdefault(prepos, []).append(l) |
|
1924 | 1924 | script.append(l[2:]) |
|
1925 | 1925 | elif l.startswith(b' $ '): # commands |
|
1926 | 1926 | if inpython: |
|
1927 | 1927 | script.append(b'EOF\n') |
|
1928 | 1928 | inpython = False |
|
1929 | 1929 | after.setdefault(pos, []).append(l) |
|
1930 | 1930 | prepos = pos |
|
1931 | 1931 | pos = n |
|
1932 | 1932 | addsalt(n, False) |
|
1933 | 1933 | rawcmd = l[4:] |
|
1934 | 1934 | cmd = rawcmd.split() |
|
1935 | 1935 | toggletrace(rawcmd) |
|
1936 | 1936 | if len(cmd) == 2 and cmd[0] == b'cd': |
|
1937 | 1937 | rawcmd = b'cd %s || exit 1\n' % cmd[1] |
|
1938 | 1938 | script.append(rawcmd) |
|
1939 | 1939 | elif l.startswith(b' > '): # continuations |
|
1940 | 1940 | after.setdefault(prepos, []).append(l) |
|
1941 | 1941 | script.append(l[4:]) |
|
1942 | 1942 | elif l.startswith(b' '): # results |
|
1943 | 1943 | # Queue up a list of expected results. |
|
1944 | 1944 | expected.setdefault(pos, []).append(l[2:]) |
|
1945 | 1945 | else: |
|
1946 | 1946 | if inpython: |
|
1947 | 1947 | script.append(b'EOF\n') |
|
1948 | 1948 | inpython = False |
|
1949 | 1949 | # Non-command/result. Queue up for merged output. |
|
1950 | 1950 | after.setdefault(pos, []).append(l) |
|
1951 | 1951 | |
|
1952 | 1952 | if inpython: |
|
1953 | 1953 | script.append(b'EOF\n') |
|
1954 | 1954 | if skipping is not None: |
|
1955 | 1955 | after.setdefault(pos, []).append(b' !!! missing #endif\n') |
|
1956 | 1956 | addsalt(n + 1, False) |
|
1957 | 1957 | # Need to end any current per-command trace |
|
1958 | 1958 | if activetrace: |
|
1959 | 1959 | toggletrace() |
|
1960 | 1960 | return salt, script, after, expected |
|
1961 | 1961 | |
|
1962 | 1962 | def _processoutput(self, exitcode, output, salt, after, expected): |
|
1963 | 1963 | # Merge the script output back into a unified test. |
|
1964 | 1964 | warnonly = WARN_UNDEFINED # 1: not yet; 2: yes; 3: for sure not |
|
1965 | 1965 | if exitcode != 0: |
|
1966 | 1966 | warnonly = WARN_NO |
|
1967 | 1967 | |
|
1968 | 1968 | pos = -1 |
|
1969 | 1969 | postout = [] |
|
1970 | 1970 | for out_rawline in output: |
|
1971 | 1971 | out_line, cmd_line = out_rawline, None |
|
1972 | 1972 | if salt in out_rawline: |
|
1973 | 1973 | out_line, cmd_line = out_rawline.split(salt, 1) |
|
1974 | 1974 | |
|
1975 | 1975 | pos, postout, warnonly = self._process_out_line( |
|
1976 | 1976 | out_line, pos, postout, expected, warnonly |
|
1977 | 1977 | ) |
|
1978 | 1978 | pos, postout = self._process_cmd_line(cmd_line, pos, postout, after) |
|
1979 | 1979 | |
|
1980 | 1980 | if pos in after: |
|
1981 | 1981 | postout += after.pop(pos) |
|
1982 | 1982 | |
|
1983 | 1983 | if warnonly == WARN_YES: |
|
1984 | 1984 | exitcode = False # Set exitcode to warned. |
|
1985 | 1985 | |
|
1986 | 1986 | return exitcode, postout |
|
1987 | 1987 | |
|
1988 | 1988 | def _process_out_line(self, out_line, pos, postout, expected, warnonly): |
|
1989 | 1989 | while out_line: |
|
1990 | 1990 | if not out_line.endswith(b'\n'): |
|
1991 | 1991 | out_line += b' (no-eol)\n' |
|
1992 | 1992 | |
|
1993 | 1993 | # Find the expected output at the current position. |
|
1994 | 1994 | els = [None] |
|
1995 | 1995 | if expected.get(pos, None): |
|
1996 | 1996 | els = expected[pos] |
|
1997 | 1997 | |
|
1998 | 1998 | optional = [] |
|
1999 | 1999 | for i, el in enumerate(els): |
|
2000 | 2000 | r = False |
|
2001 | 2001 | if el: |
|
2002 | 2002 | r, exact = self.linematch(el, out_line) |
|
2003 | 2003 | if isinstance(r, str): |
|
2004 | 2004 | if r == '-glob': |
|
2005 | 2005 | out_line = ''.join(el.rsplit(' (glob)', 1)) |
|
2006 | 2006 | r = '' # Warn only this line. |
|
2007 | 2007 | elif r == "retry": |
|
2008 | 2008 | postout.append(b' ' + el) |
|
2009 | 2009 | else: |
|
2010 | 2010 | log('\ninfo, unknown linematch result: %r\n' % r) |
|
2011 | 2011 | r = False |
|
2012 | 2012 | if r: |
|
2013 | 2013 | els.pop(i) |
|
2014 | 2014 | break |
|
2015 | 2015 | if el: |
|
2016 | 2016 | if isoptional(el): |
|
2017 | 2017 | optional.append(i) |
|
2018 | 2018 | else: |
|
2019 | 2019 | m = optline.match(el) |
|
2020 | 2020 | if m: |
|
2021 | 2021 | conditions = [c for c in m.group(2).split(b' ')] |
|
2022 | 2022 | |
|
2023 | 2023 | if not self._iftest(conditions): |
|
2024 | 2024 | optional.append(i) |
|
2025 | 2025 | if exact: |
|
2026 | 2026 | # Don't allow line to be matches against a later |
|
2027 | 2027 | # line in the output |
|
2028 | 2028 | els.pop(i) |
|
2029 | 2029 | break |
|
2030 | 2030 | |
|
2031 | 2031 | if r: |
|
2032 | 2032 | if r == "retry": |
|
2033 | 2033 | continue |
|
2034 | 2034 | # clean up any optional leftovers |
|
2035 | 2035 | for i in optional: |
|
2036 | 2036 | postout.append(b' ' + els[i]) |
|
2037 | 2037 | for i in reversed(optional): |
|
2038 | 2038 | del els[i] |
|
2039 | 2039 | postout.append(b' ' + el) |
|
2040 | 2040 | else: |
|
2041 | 2041 | if self.NEEDESCAPE(out_line): |
|
2042 | 2042 | out_line = TTest._stringescape( |
|
2043 | 2043 | b'%s (esc)\n' % out_line.rstrip(b'\n') |
|
2044 | 2044 | ) |
|
2045 | 2045 | postout.append(b' ' + out_line) # Let diff deal with it. |
|
2046 | 2046 | if r != '': # If line failed. |
|
2047 | 2047 | warnonly = WARN_NO |
|
2048 | 2048 | elif warnonly == WARN_UNDEFINED: |
|
2049 | 2049 | warnonly = WARN_YES |
|
2050 | 2050 | break |
|
2051 | 2051 | else: |
|
2052 | 2052 | # clean up any optional leftovers |
|
2053 | 2053 | while expected.get(pos, None): |
|
2054 | 2054 | el = expected[pos].pop(0) |
|
2055 | 2055 | if el: |
|
2056 | 2056 | if not isoptional(el): |
|
2057 | 2057 | m = optline.match(el) |
|
2058 | 2058 | if m: |
|
2059 | 2059 | conditions = [c for c in m.group(2).split(b' ')] |
|
2060 | 2060 | |
|
2061 | 2061 | if self._iftest(conditions): |
|
2062 | 2062 | # Don't append as optional line |
|
2063 | 2063 | continue |
|
2064 | 2064 | else: |
|
2065 | 2065 | continue |
|
2066 | 2066 | postout.append(b' ' + el) |
|
2067 | 2067 | return pos, postout, warnonly |
|
2068 | 2068 | |
|
2069 | 2069 | def _process_cmd_line(self, cmd_line, pos, postout, after): |
|
2070 | 2070 | """process a "command" part of a line from unified test output""" |
|
2071 | 2071 | if cmd_line: |
|
2072 | 2072 | # Add on last return code. |
|
2073 | 2073 | ret = int(cmd_line.split()[1]) |
|
2074 | 2074 | if ret != 0: |
|
2075 | 2075 | postout.append(b' [%d]\n' % ret) |
|
2076 | 2076 | if pos in after: |
|
2077 | 2077 | # Merge in non-active test bits. |
|
2078 | 2078 | postout += after.pop(pos) |
|
2079 | 2079 | pos = int(cmd_line.split()[0]) |
|
2080 | 2080 | return pos, postout |
|
2081 | 2081 | |
|
2082 | 2082 | @staticmethod |
|
2083 | 2083 | def rematch(el, l): |
|
2084 | 2084 | try: |
|
2085 | 2085 | # parse any flags at the beginning of the regex. Only 'i' is |
|
2086 | 2086 | # supported right now, but this should be easy to extend. |
|
2087 | 2087 | flags, el = re.match(br'^(\(\?i\))?(.*)', el).groups()[0:2] |
|
2088 | 2088 | flags = flags or b'' |
|
2089 | 2089 | el = flags + b'(?:' + el + b')' |
|
2090 | 2090 | # use \Z to ensure that the regex matches to the end of the string |
|
2091 | 2091 | if WINDOWS: |
|
2092 | 2092 | return re.match(el + br'\r?\n\Z', l) |
|
2093 | 2093 | return re.match(el + br'\n\Z', l) |
|
2094 | 2094 | except re.error: |
|
2095 | 2095 | # el is an invalid regex |
|
2096 | 2096 | return False |
|
2097 | 2097 | |
|
2098 | 2098 | @staticmethod |
|
2099 | 2099 | def globmatch(el, l): |
|
2100 | 2100 | # The only supported special characters are * and ? plus / which also |
|
2101 | 2101 | # matches \ on windows. Escaping of these characters is supported. |
|
2102 | 2102 | if el + b'\n' == l: |
|
2103 | 2103 | if os.altsep: |
|
2104 | 2104 | # matching on "/" is not needed for this line |
|
2105 | 2105 | for pat in checkcodeglobpats: |
|
2106 | 2106 | if pat.match(el): |
|
2107 | 2107 | return True |
|
2108 | 2108 | return b'-glob' |
|
2109 | 2109 | return True |
|
2110 | 2110 | el = el.replace(b'$LOCALIP', b'*') |
|
2111 | 2111 | i, n = 0, len(el) |
|
2112 | 2112 | res = b'' |
|
2113 | 2113 | while i < n: |
|
2114 | 2114 | c = el[i : i + 1] |
|
2115 | 2115 | i += 1 |
|
2116 | 2116 | if c == b'\\' and i < n and el[i : i + 1] in b'*?\\/': |
|
2117 | 2117 | res += el[i - 1 : i + 1] |
|
2118 | 2118 | i += 1 |
|
2119 | 2119 | elif c == b'*': |
|
2120 | 2120 | res += b'.*' |
|
2121 | 2121 | elif c == b'?': |
|
2122 | 2122 | res += b'.' |
|
2123 | 2123 | elif c == b'/' and os.altsep: |
|
2124 | 2124 | res += b'[/\\\\]' |
|
2125 | 2125 | else: |
|
2126 | 2126 | res += re.escape(c) |
|
2127 | 2127 | return TTest.rematch(res, l) |
|
2128 | 2128 | |
|
2129 | 2129 | def linematch(self, el, l): |
|
2130 | 2130 | if el == l: # perfect match (fast) |
|
2131 | 2131 | return True, True |
|
2132 | 2132 | retry = False |
|
2133 | 2133 | if isoptional(el): |
|
2134 | 2134 | retry = "retry" |
|
2135 | 2135 | el = el[: -len(MARK_OPTIONAL)] + b"\n" |
|
2136 | 2136 | else: |
|
2137 | 2137 | m = optline.match(el) |
|
2138 | 2138 | if m: |
|
2139 | 2139 | conditions = [c for c in m.group(2).split(b' ')] |
|
2140 | 2140 | |
|
2141 | 2141 | el = m.group(1) + b"\n" |
|
2142 | 2142 | if not self._iftest(conditions): |
|
2143 | 2143 | # listed feature missing, should not match |
|
2144 | 2144 | return "retry", False |
|
2145 | 2145 | |
|
2146 | 2146 | if el.endswith(b" (esc)\n"): |
|
2147 | 2147 | if PYTHON3: |
|
2148 | 2148 | el = el[:-7].decode('unicode_escape') + '\n' |
|
2149 | 2149 | el = el.encode('latin-1') |
|
2150 | 2150 | else: |
|
2151 | 2151 | el = el[:-7].decode('string-escape') + '\n' |
|
2152 | 2152 | if el == l or WINDOWS and el[:-1] + b'\r\n' == l: |
|
2153 | 2153 | return True, True |
|
2154 | 2154 | if el.endswith(b" (re)\n"): |
|
2155 | 2155 | return (TTest.rematch(el[:-6], l) or retry), False |
|
2156 | 2156 | if el.endswith(b" (glob)\n"): |
|
2157 | 2157 | # ignore '(glob)' added to l by 'replacements' |
|
2158 | 2158 | if l.endswith(b" (glob)\n"): |
|
2159 | 2159 | l = l[:-8] + b"\n" |
|
2160 | 2160 | return (TTest.globmatch(el[:-8], l) or retry), False |
|
2161 | 2161 | if os.altsep: |
|
2162 | 2162 | _l = l.replace(b'\\', b'/') |
|
2163 | 2163 | if el == _l or WINDOWS and el[:-1] + b'\r\n' == _l: |
|
2164 | 2164 | return True, True |
|
2165 | 2165 | return retry, True |
|
2166 | 2166 | |
|
2167 | 2167 | @staticmethod |
|
2168 | 2168 | def parsehghaveoutput(lines): |
|
2169 | 2169 | """Parse hghave log lines. |
|
2170 | 2170 | |
|
2171 | 2171 | Return tuple of lists (missing, failed): |
|
2172 | 2172 | * the missing/unknown features |
|
2173 | 2173 | * the features for which existence check failed""" |
|
2174 | 2174 | missing = [] |
|
2175 | 2175 | failed = [] |
|
2176 | 2176 | for line in lines: |
|
2177 | 2177 | if line.startswith(TTest.SKIPPED_PREFIX): |
|
2178 | 2178 | line = line.splitlines()[0] |
|
2179 | 2179 | missing.append(_bytes2sys(line[len(TTest.SKIPPED_PREFIX) :])) |
|
2180 | 2180 | elif line.startswith(TTest.FAILED_PREFIX): |
|
2181 | 2181 | line = line.splitlines()[0] |
|
2182 | 2182 | failed.append(_bytes2sys(line[len(TTest.FAILED_PREFIX) :])) |
|
2183 | 2183 | |
|
2184 | 2184 | return missing, failed |
|
2185 | 2185 | |
|
2186 | 2186 | @staticmethod |
|
2187 | 2187 | def _escapef(m): |
|
2188 | 2188 | return TTest.ESCAPEMAP[m.group(0)] |
|
2189 | 2189 | |
|
2190 | 2190 | @staticmethod |
|
2191 | 2191 | def _stringescape(s): |
|
2192 | 2192 | return TTest.ESCAPESUB(TTest._escapef, s) |
|
2193 | 2193 | |
|
2194 | 2194 | |
|
2195 | 2195 | iolock = threading.RLock() |
|
2196 | 2196 | firstlock = threading.RLock() |
|
2197 | 2197 | firsterror = False |
|
2198 | 2198 | |
|
2199 | 2199 | |
|
2200 | 2200 | class TestResult(unittest._TextTestResult): |
|
2201 | 2201 | """Holds results when executing via unittest.""" |
|
2202 | 2202 | |
|
2203 | 2203 | # Don't worry too much about accessing the non-public _TextTestResult. |
|
2204 | 2204 | # It is relatively common in Python testing tools. |
|
2205 | 2205 | def __init__(self, options, *args, **kwargs): |
|
2206 | 2206 | super(TestResult, self).__init__(*args, **kwargs) |
|
2207 | 2207 | |
|
2208 | 2208 | self._options = options |
|
2209 | 2209 | |
|
2210 | 2210 | # unittest.TestResult didn't have skipped until 2.7. We need to |
|
2211 | 2211 | # polyfill it. |
|
2212 | 2212 | self.skipped = [] |
|
2213 | 2213 | |
|
2214 | 2214 | # We have a custom "ignored" result that isn't present in any Python |
|
2215 | 2215 | # unittest implementation. It is very similar to skipped. It may make |
|
2216 | 2216 | # sense to map it into skip some day. |
|
2217 | 2217 | self.ignored = [] |
|
2218 | 2218 | |
|
2219 | 2219 | self.times = [] |
|
2220 | 2220 | self._firststarttime = None |
|
2221 | 2221 | # Data stored for the benefit of generating xunit reports. |
|
2222 | 2222 | self.successes = [] |
|
2223 | 2223 | self.faildata = {} |
|
2224 | 2224 | |
|
2225 | 2225 | if options.color == 'auto': |
|
2226 | 2226 | isatty = self.stream.isatty() |
|
2227 | 2227 | # For some reason, redirecting stdout on Windows disables the ANSI |
|
2228 | 2228 | # color processing of stderr, which is what is used to print the |
|
2229 | 2229 | # output. Therefore, both must be tty on Windows to enable color. |
|
2230 | 2230 | if WINDOWS: |
|
2231 | 2231 | isatty = isatty and sys.stdout.isatty() |
|
2232 | 2232 | self.color = pygmentspresent and isatty |
|
2233 | 2233 | elif options.color == 'never': |
|
2234 | 2234 | self.color = False |
|
2235 | 2235 | else: # 'always', for testing purposes |
|
2236 | 2236 | self.color = pygmentspresent |
|
2237 | 2237 | |
|
2238 | 2238 | def onStart(self, test): |
|
2239 | 2239 | """Can be overriden by custom TestResult""" |
|
2240 | 2240 | |
|
2241 | 2241 | def onEnd(self): |
|
2242 | 2242 | """Can be overriden by custom TestResult""" |
|
2243 | 2243 | |
|
2244 | 2244 | def addFailure(self, test, reason): |
|
2245 | 2245 | self.failures.append((test, reason)) |
|
2246 | 2246 | |
|
2247 | 2247 | if self._options.first: |
|
2248 | 2248 | self.stop() |
|
2249 | 2249 | else: |
|
2250 | 2250 | with iolock: |
|
2251 | 2251 | if reason == "timed out": |
|
2252 | 2252 | self.stream.write('t') |
|
2253 | 2253 | else: |
|
2254 | 2254 | if not self._options.nodiff: |
|
2255 | 2255 | self.stream.write('\n') |
|
2256 | 2256 | # Exclude the '\n' from highlighting to lex correctly |
|
2257 | 2257 | formatted = 'ERROR: %s output changed\n' % test |
|
2258 | 2258 | self.stream.write(highlightmsg(formatted, self.color)) |
|
2259 | 2259 | self.stream.write('!') |
|
2260 | 2260 | |
|
2261 | 2261 | self.stream.flush() |
|
2262 | 2262 | |
|
2263 | 2263 | def addSuccess(self, test): |
|
2264 | 2264 | with iolock: |
|
2265 | 2265 | super(TestResult, self).addSuccess(test) |
|
2266 | 2266 | self.successes.append(test) |
|
2267 | 2267 | |
|
2268 | 2268 | def addError(self, test, err): |
|
2269 | 2269 | super(TestResult, self).addError(test, err) |
|
2270 | 2270 | if self._options.first: |
|
2271 | 2271 | self.stop() |
|
2272 | 2272 | |
|
2273 | 2273 | # Polyfill. |
|
2274 | 2274 | def addSkip(self, test, reason): |
|
2275 | 2275 | self.skipped.append((test, reason)) |
|
2276 | 2276 | with iolock: |
|
2277 | 2277 | if self.showAll: |
|
2278 | 2278 | self.stream.writeln('skipped %s' % reason) |
|
2279 | 2279 | else: |
|
2280 | 2280 | self.stream.write('s') |
|
2281 | 2281 | self.stream.flush() |
|
2282 | 2282 | |
|
2283 | 2283 | def addIgnore(self, test, reason): |
|
2284 | 2284 | self.ignored.append((test, reason)) |
|
2285 | 2285 | with iolock: |
|
2286 | 2286 | if self.showAll: |
|
2287 | 2287 | self.stream.writeln('ignored %s' % reason) |
|
2288 | 2288 | else: |
|
2289 | 2289 | if reason not in ('not retesting', "doesn't match keyword"): |
|
2290 | 2290 | self.stream.write('i') |
|
2291 | 2291 | else: |
|
2292 | 2292 | self.testsRun += 1 |
|
2293 | 2293 | self.stream.flush() |
|
2294 | 2294 | |
|
2295 | 2295 | def addOutputMismatch(self, test, ret, got, expected): |
|
2296 | 2296 | """Record a mismatch in test output for a particular test.""" |
|
2297 | 2297 | if self.shouldStop or firsterror: |
|
2298 | 2298 | # don't print, some other test case already failed and |
|
2299 | 2299 | # printed, we're just stale and probably failed due to our |
|
2300 | 2300 | # temp dir getting cleaned up. |
|
2301 | 2301 | return |
|
2302 | 2302 | |
|
2303 | 2303 | accepted = False |
|
2304 | 2304 | lines = [] |
|
2305 | 2305 | |
|
2306 | 2306 | with iolock: |
|
2307 | 2307 | if self._options.nodiff: |
|
2308 | 2308 | pass |
|
2309 | 2309 | elif self._options.view: |
|
2310 | 2310 | v = self._options.view |
|
2311 | 2311 | subprocess.call( |
|
2312 | 2312 | r'"%s" "%s" "%s"' |
|
2313 | 2313 | % (v, _bytes2sys(test.refpath), _bytes2sys(test.errpath)), |
|
2314 | 2314 | shell=True, |
|
2315 | 2315 | ) |
|
2316 | 2316 | else: |
|
2317 | 2317 | servefail, lines = getdiff( |
|
2318 | 2318 | expected, got, test.refpath, test.errpath |
|
2319 | 2319 | ) |
|
2320 | 2320 | self.stream.write('\n') |
|
2321 | 2321 | for line in lines: |
|
2322 | 2322 | line = highlightdiff(line, self.color) |
|
2323 | 2323 | if PYTHON3: |
|
2324 | 2324 | self.stream.flush() |
|
2325 | 2325 | self.stream.buffer.write(line) |
|
2326 | 2326 | self.stream.buffer.flush() |
|
2327 | 2327 | else: |
|
2328 | 2328 | self.stream.write(line) |
|
2329 | 2329 | self.stream.flush() |
|
2330 | 2330 | |
|
2331 | 2331 | if servefail: |
|
2332 | 2332 | raise test.failureException( |
|
2333 | 2333 | 'server failed to start (HGPORT=%s)' % test._startport |
|
2334 | 2334 | ) |
|
2335 | 2335 | |
|
2336 | 2336 | # handle interactive prompt without releasing iolock |
|
2337 | 2337 | if self._options.interactive: |
|
2338 | 2338 | if test.readrefout() != expected: |
|
2339 | 2339 | self.stream.write( |
|
2340 | 2340 | 'Reference output has changed (run again to prompt ' |
|
2341 | 2341 | 'changes)' |
|
2342 | 2342 | ) |
|
2343 | 2343 | else: |
|
2344 | 2344 | self.stream.write('Accept this change? [y/N] ') |
|
2345 | 2345 | self.stream.flush() |
|
2346 | 2346 | answer = sys.stdin.readline().strip() |
|
2347 | 2347 | if answer.lower() in ('y', 'yes'): |
|
2348 | 2348 | if test.path.endswith(b'.t'): |
|
2349 | 2349 | rename(test.errpath, test.path) |
|
2350 | 2350 | else: |
|
2351 | 2351 | rename(test.errpath, b'%s.out' % test.path) |
|
2352 | 2352 | accepted = True |
|
2353 | 2353 | if not accepted: |
|
2354 | 2354 | self.faildata[test.name] = b''.join(lines) |
|
2355 | 2355 | |
|
2356 | 2356 | return accepted |
|
2357 | 2357 | |
|
2358 | 2358 | def startTest(self, test): |
|
2359 | 2359 | super(TestResult, self).startTest(test) |
|
2360 | 2360 | |
|
2361 | 2361 | # os.times module computes the user time and system time spent by |
|
2362 | 2362 | # child's processes along with real elapsed time taken by a process. |
|
2363 | 2363 | # This module has one limitation. It can only work for Linux user |
|
2364 | 2364 | # and not for Windows. Hence why we fall back to another function |
|
2365 | 2365 | # for wall time calculations. |
|
2366 | 2366 | test.started_times = os.times() |
|
2367 | 2367 | # TODO use a monotonic clock once support for Python 2.7 is dropped. |
|
2368 | 2368 | test.started_time = time.time() |
|
2369 | 2369 | if self._firststarttime is None: # thread racy but irrelevant |
|
2370 | 2370 | self._firststarttime = test.started_time |
|
2371 | 2371 | |
|
2372 | 2372 | def stopTest(self, test, interrupted=False): |
|
2373 | 2373 | super(TestResult, self).stopTest(test) |
|
2374 | 2374 | |
|
2375 | 2375 | test.stopped_times = os.times() |
|
2376 | 2376 | stopped_time = time.time() |
|
2377 | 2377 | |
|
2378 | 2378 | starttime = test.started_times |
|
2379 | 2379 | endtime = test.stopped_times |
|
2380 | 2380 | origin = self._firststarttime |
|
2381 | 2381 | self.times.append( |
|
2382 | 2382 | ( |
|
2383 | 2383 | test.name, |
|
2384 | 2384 | endtime[2] - starttime[2], # user space CPU time |
|
2385 | 2385 | endtime[3] - starttime[3], # sys space CPU time |
|
2386 | 2386 | stopped_time - test.started_time, # real time |
|
2387 | 2387 | test.started_time - origin, # start date in run context |
|
2388 | 2388 | stopped_time - origin, # end date in run context |
|
2389 | 2389 | ) |
|
2390 | 2390 | ) |
|
2391 | 2391 | |
|
2392 | 2392 | if interrupted: |
|
2393 | 2393 | with iolock: |
|
2394 | 2394 | self.stream.writeln( |
|
2395 | 2395 | 'INTERRUPTED: %s (after %d seconds)' |
|
2396 | 2396 | % (test.name, self.times[-1][3]) |
|
2397 | 2397 | ) |
|
2398 | 2398 | |
|
2399 | 2399 | |
|
2400 | 2400 | def getTestResult(): |
|
2401 | 2401 | """ |
|
2402 | 2402 | Returns the relevant test result |
|
2403 | 2403 | """ |
|
2404 | 2404 | if "CUSTOM_TEST_RESULT" in os.environ: |
|
2405 | 2405 | testresultmodule = __import__(os.environ["CUSTOM_TEST_RESULT"]) |
|
2406 | 2406 | return testresultmodule.TestResult |
|
2407 | 2407 | else: |
|
2408 | 2408 | return TestResult |
|
2409 | 2409 | |
|
2410 | 2410 | |
|
2411 | 2411 | class TestSuite(unittest.TestSuite): |
|
2412 | 2412 | """Custom unittest TestSuite that knows how to execute Mercurial tests.""" |
|
2413 | 2413 | |
|
2414 | 2414 | def __init__( |
|
2415 | 2415 | self, |
|
2416 | 2416 | testdir, |
|
2417 | 2417 | jobs=1, |
|
2418 | 2418 | whitelist=None, |
|
2419 | 2419 | blacklist=None, |
|
2420 | 2420 | keywords=None, |
|
2421 | 2421 | loop=False, |
|
2422 | 2422 | runs_per_test=1, |
|
2423 | 2423 | loadtest=None, |
|
2424 | 2424 | showchannels=False, |
|
2425 | 2425 | *args, |
|
2426 | 2426 | **kwargs |
|
2427 | 2427 | ): |
|
2428 | 2428 | """Create a new instance that can run tests with a configuration. |
|
2429 | 2429 | |
|
2430 | 2430 | testdir specifies the directory where tests are executed from. This |
|
2431 | 2431 | is typically the ``tests`` directory from Mercurial's source |
|
2432 | 2432 | repository. |
|
2433 | 2433 | |
|
2434 | 2434 | jobs specifies the number of jobs to run concurrently. Each test |
|
2435 | 2435 | executes on its own thread. Tests actually spawn new processes, so |
|
2436 | 2436 | state mutation should not be an issue. |
|
2437 | 2437 | |
|
2438 | 2438 | If there is only one job, it will use the main thread. |
|
2439 | 2439 | |
|
2440 | 2440 | whitelist and blacklist denote tests that have been whitelisted and |
|
2441 | 2441 | blacklisted, respectively. These arguments don't belong in TestSuite. |
|
2442 | 2442 | Instead, whitelist and blacklist should be handled by the thing that |
|
2443 | 2443 | populates the TestSuite with tests. They are present to preserve |
|
2444 | 2444 | backwards compatible behavior which reports skipped tests as part |
|
2445 | 2445 | of the results. |
|
2446 | 2446 | |
|
2447 | 2447 | keywords denotes key words that will be used to filter which tests |
|
2448 | 2448 | to execute. This arguably belongs outside of TestSuite. |
|
2449 | 2449 | |
|
2450 | 2450 | loop denotes whether to loop over tests forever. |
|
2451 | 2451 | """ |
|
2452 | 2452 | super(TestSuite, self).__init__(*args, **kwargs) |
|
2453 | 2453 | |
|
2454 | 2454 | self._jobs = jobs |
|
2455 | 2455 | self._whitelist = whitelist |
|
2456 | 2456 | self._blacklist = blacklist |
|
2457 | 2457 | self._keywords = keywords |
|
2458 | 2458 | self._loop = loop |
|
2459 | 2459 | self._runs_per_test = runs_per_test |
|
2460 | 2460 | self._loadtest = loadtest |
|
2461 | 2461 | self._showchannels = showchannels |
|
2462 | 2462 | |
|
2463 | 2463 | def run(self, result): |
|
2464 | 2464 | # We have a number of filters that need to be applied. We do this |
|
2465 | 2465 | # here instead of inside Test because it makes the running logic for |
|
2466 | 2466 | # Test simpler. |
|
2467 | 2467 | tests = [] |
|
2468 | 2468 | num_tests = [0] |
|
2469 | 2469 | for test in self._tests: |
|
2470 | 2470 | |
|
2471 | 2471 | def get(): |
|
2472 | 2472 | num_tests[0] += 1 |
|
2473 | 2473 | if getattr(test, 'should_reload', False): |
|
2474 | 2474 | return self._loadtest(test, num_tests[0]) |
|
2475 | 2475 | return test |
|
2476 | 2476 | |
|
2477 | 2477 | if not os.path.exists(test.path): |
|
2478 | 2478 | result.addSkip(test, "Doesn't exist") |
|
2479 | 2479 | continue |
|
2480 | 2480 | |
|
2481 | 2481 | is_whitelisted = self._whitelist and ( |
|
2482 | 2482 | test.relpath in self._whitelist or test.bname in self._whitelist |
|
2483 | 2483 | ) |
|
2484 | 2484 | if not is_whitelisted: |
|
2485 | 2485 | is_blacklisted = self._blacklist and ( |
|
2486 | 2486 | test.relpath in self._blacklist |
|
2487 | 2487 | or test.bname in self._blacklist |
|
2488 | 2488 | ) |
|
2489 | 2489 | if is_blacklisted: |
|
2490 | 2490 | result.addSkip(test, 'blacklisted') |
|
2491 | 2491 | continue |
|
2492 | 2492 | if self._keywords: |
|
2493 | 2493 | with open(test.path, 'rb') as f: |
|
2494 | 2494 | t = f.read().lower() + test.bname.lower() |
|
2495 | 2495 | ignored = False |
|
2496 | 2496 | for k in self._keywords.lower().split(): |
|
2497 | 2497 | if k not in t: |
|
2498 | 2498 | result.addIgnore(test, "doesn't match keyword") |
|
2499 | 2499 | ignored = True |
|
2500 | 2500 | break |
|
2501 | 2501 | |
|
2502 | 2502 | if ignored: |
|
2503 | 2503 | continue |
|
2504 | 2504 | for _ in xrange(self._runs_per_test): |
|
2505 | 2505 | tests.append(get()) |
|
2506 | 2506 | |
|
2507 | 2507 | runtests = list(tests) |
|
2508 | 2508 | done = queue.Queue() |
|
2509 | 2509 | running = 0 |
|
2510 | 2510 | |
|
2511 | 2511 | channels = [""] * self._jobs |
|
2512 | 2512 | |
|
2513 | 2513 | def job(test, result): |
|
2514 | 2514 | for n, v in enumerate(channels): |
|
2515 | 2515 | if not v: |
|
2516 | 2516 | channel = n |
|
2517 | 2517 | break |
|
2518 | 2518 | else: |
|
2519 | 2519 | raise ValueError('Could not find output channel') |
|
2520 | 2520 | channels[channel] = "=" + test.name[5:].split(".")[0] |
|
2521 | 2521 | try: |
|
2522 | 2522 | test(result) |
|
2523 | 2523 | done.put(None) |
|
2524 | 2524 | except KeyboardInterrupt: |
|
2525 | 2525 | pass |
|
2526 | 2526 | except: # re-raises |
|
2527 | 2527 | done.put(('!', test, 'run-test raised an error, see traceback')) |
|
2528 | 2528 | raise |
|
2529 | 2529 | finally: |
|
2530 | 2530 | try: |
|
2531 | 2531 | channels[channel] = '' |
|
2532 | 2532 | except IndexError: |
|
2533 | 2533 | pass |
|
2534 | 2534 | |
|
2535 | 2535 | def stat(): |
|
2536 | 2536 | count = 0 |
|
2537 | 2537 | while channels: |
|
2538 | 2538 | d = '\n%03s ' % count |
|
2539 | 2539 | for n, v in enumerate(channels): |
|
2540 | 2540 | if v: |
|
2541 | 2541 | d += v[0] |
|
2542 | 2542 | channels[n] = v[1:] or '.' |
|
2543 | 2543 | else: |
|
2544 | 2544 | d += ' ' |
|
2545 | 2545 | d += ' ' |
|
2546 | 2546 | with iolock: |
|
2547 | 2547 | sys.stdout.write(d + ' ') |
|
2548 | 2548 | sys.stdout.flush() |
|
2549 | 2549 | for x in xrange(10): |
|
2550 | 2550 | if channels: |
|
2551 | 2551 | time.sleep(0.1) |
|
2552 | 2552 | count += 1 |
|
2553 | 2553 | |
|
2554 | 2554 | stoppedearly = False |
|
2555 | 2555 | |
|
2556 | 2556 | if self._showchannels: |
|
2557 | 2557 | statthread = threading.Thread(target=stat, name="stat") |
|
2558 | 2558 | statthread.start() |
|
2559 | 2559 | |
|
2560 | 2560 | try: |
|
2561 | 2561 | while tests or running: |
|
2562 | 2562 | if not done.empty() or running == self._jobs or not tests: |
|
2563 | 2563 | try: |
|
2564 | 2564 | done.get(True, 1) |
|
2565 | 2565 | running -= 1 |
|
2566 | 2566 | if result and result.shouldStop: |
|
2567 | 2567 | stoppedearly = True |
|
2568 | 2568 | break |
|
2569 | 2569 | except queue.Empty: |
|
2570 | 2570 | continue |
|
2571 | 2571 | if tests and not running == self._jobs: |
|
2572 | 2572 | test = tests.pop(0) |
|
2573 | 2573 | if self._loop: |
|
2574 | 2574 | if getattr(test, 'should_reload', False): |
|
2575 | 2575 | num_tests[0] += 1 |
|
2576 | 2576 | tests.append(self._loadtest(test, num_tests[0])) |
|
2577 | 2577 | else: |
|
2578 | 2578 | tests.append(test) |
|
2579 | 2579 | if self._jobs == 1: |
|
2580 | 2580 | job(test, result) |
|
2581 | 2581 | else: |
|
2582 | 2582 | t = threading.Thread( |
|
2583 | 2583 | target=job, name=test.name, args=(test, result) |
|
2584 | 2584 | ) |
|
2585 | 2585 | t.start() |
|
2586 | 2586 | running += 1 |
|
2587 | 2587 | |
|
2588 | 2588 | # If we stop early we still need to wait on started tests to |
|
2589 | 2589 | # finish. Otherwise, there is a race between the test completing |
|
2590 | 2590 | # and the test's cleanup code running. This could result in the |
|
2591 | 2591 | # test reporting incorrect. |
|
2592 | 2592 | if stoppedearly: |
|
2593 | 2593 | while running: |
|
2594 | 2594 | try: |
|
2595 | 2595 | done.get(True, 1) |
|
2596 | 2596 | running -= 1 |
|
2597 | 2597 | except queue.Empty: |
|
2598 | 2598 | continue |
|
2599 | 2599 | except KeyboardInterrupt: |
|
2600 | 2600 | for test in runtests: |
|
2601 | 2601 | test.abort() |
|
2602 | 2602 | |
|
2603 | 2603 | channels = [] |
|
2604 | 2604 | |
|
2605 | 2605 | return result |
|
2606 | 2606 | |
|
2607 | 2607 | |
|
2608 | 2608 | # Save the most recent 5 wall-clock runtimes of each test to a |
|
2609 | 2609 | # human-readable text file named .testtimes. Tests are sorted |
|
2610 | 2610 | # alphabetically, while times for each test are listed from oldest to |
|
2611 | 2611 | # newest. |
|
2612 | 2612 | |
|
2613 | 2613 | |
|
2614 | 2614 | def loadtimes(outputdir): |
|
2615 | 2615 | times = [] |
|
2616 | 2616 | try: |
|
2617 | 2617 | with open(os.path.join(outputdir, b'.testtimes')) as fp: |
|
2618 | 2618 | for line in fp: |
|
2619 | 2619 | m = re.match('(.*?) ([0-9. ]+)', line) |
|
2620 | 2620 | times.append( |
|
2621 | 2621 | (m.group(1), [float(t) for t in m.group(2).split()]) |
|
2622 | 2622 | ) |
|
2623 | 2623 | except IOError as err: |
|
2624 | 2624 | if err.errno != errno.ENOENT: |
|
2625 | 2625 | raise |
|
2626 | 2626 | return times |
|
2627 | 2627 | |
|
2628 | 2628 | |
|
2629 | 2629 | def savetimes(outputdir, result): |
|
2630 | 2630 | saved = dict(loadtimes(outputdir)) |
|
2631 | 2631 | maxruns = 5 |
|
2632 | 2632 | skipped = {str(t[0]) for t in result.skipped} |
|
2633 | 2633 | for tdata in result.times: |
|
2634 | 2634 | test, real = tdata[0], tdata[3] |
|
2635 | 2635 | if test not in skipped: |
|
2636 | 2636 | ts = saved.setdefault(test, []) |
|
2637 | 2637 | ts.append(real) |
|
2638 | 2638 | ts[:] = ts[-maxruns:] |
|
2639 | 2639 | |
|
2640 | 2640 | fd, tmpname = tempfile.mkstemp( |
|
2641 | 2641 | prefix=b'.testtimes', dir=outputdir, text=True |
|
2642 | 2642 | ) |
|
2643 | 2643 | with os.fdopen(fd, 'w') as fp: |
|
2644 | 2644 | for name, ts in sorted(saved.items()): |
|
2645 | 2645 | fp.write('%s %s\n' % (name, ' '.join(['%.3f' % (t,) for t in ts]))) |
|
2646 | 2646 | timepath = os.path.join(outputdir, b'.testtimes') |
|
2647 | 2647 | try: |
|
2648 | 2648 | os.unlink(timepath) |
|
2649 | 2649 | except OSError: |
|
2650 | 2650 | pass |
|
2651 | 2651 | try: |
|
2652 | 2652 | os.rename(tmpname, timepath) |
|
2653 | 2653 | except OSError: |
|
2654 | 2654 | pass |
|
2655 | 2655 | |
|
2656 | 2656 | |
|
2657 | 2657 | class TextTestRunner(unittest.TextTestRunner): |
|
2658 | 2658 | """Custom unittest test runner that uses appropriate settings.""" |
|
2659 | 2659 | |
|
2660 | 2660 | def __init__(self, runner, *args, **kwargs): |
|
2661 | 2661 | super(TextTestRunner, self).__init__(*args, **kwargs) |
|
2662 | 2662 | |
|
2663 | 2663 | self._runner = runner |
|
2664 | 2664 | |
|
2665 | 2665 | self._result = getTestResult()( |
|
2666 | 2666 | self._runner.options, self.stream, self.descriptions, self.verbosity |
|
2667 | 2667 | ) |
|
2668 | 2668 | |
|
2669 | 2669 | def listtests(self, test): |
|
2670 | 2670 | test = sorted(test, key=lambda t: t.name) |
|
2671 | 2671 | |
|
2672 | 2672 | self._result.onStart(test) |
|
2673 | 2673 | |
|
2674 | 2674 | for t in test: |
|
2675 | 2675 | print(t.name) |
|
2676 | 2676 | self._result.addSuccess(t) |
|
2677 | 2677 | |
|
2678 | 2678 | if self._runner.options.xunit: |
|
2679 | 2679 | with open(self._runner.options.xunit, "wb") as xuf: |
|
2680 | 2680 | self._writexunit(self._result, xuf) |
|
2681 | 2681 | |
|
2682 | 2682 | if self._runner.options.json: |
|
2683 | 2683 | jsonpath = os.path.join(self._runner._outputdir, b'report.json') |
|
2684 | 2684 | with open(jsonpath, 'w') as fp: |
|
2685 | 2685 | self._writejson(self._result, fp) |
|
2686 | 2686 | |
|
2687 | 2687 | return self._result |
|
2688 | 2688 | |
|
2689 | 2689 | def run(self, test): |
|
2690 | 2690 | self._result.onStart(test) |
|
2691 | 2691 | test(self._result) |
|
2692 | 2692 | |
|
2693 | 2693 | failed = len(self._result.failures) |
|
2694 | 2694 | skipped = len(self._result.skipped) |
|
2695 | 2695 | ignored = len(self._result.ignored) |
|
2696 | 2696 | |
|
2697 | 2697 | with iolock: |
|
2698 | 2698 | self.stream.writeln('') |
|
2699 | 2699 | |
|
2700 | 2700 | if not self._runner.options.noskips: |
|
2701 | 2701 | for test, msg in sorted( |
|
2702 | 2702 | self._result.skipped, key=lambda s: s[0].name |
|
2703 | 2703 | ): |
|
2704 | 2704 | formatted = 'Skipped %s: %s\n' % (test.name, msg) |
|
2705 | 2705 | msg = highlightmsg(formatted, self._result.color) |
|
2706 | 2706 | self.stream.write(msg) |
|
2707 | 2707 | for test, msg in sorted( |
|
2708 | 2708 | self._result.failures, key=lambda f: f[0].name |
|
2709 | 2709 | ): |
|
2710 | 2710 | formatted = 'Failed %s: %s\n' % (test.name, msg) |
|
2711 | 2711 | self.stream.write(highlightmsg(formatted, self._result.color)) |
|
2712 | 2712 | for test, msg in sorted( |
|
2713 | 2713 | self._result.errors, key=lambda e: e[0].name |
|
2714 | 2714 | ): |
|
2715 | 2715 | self.stream.writeln('Errored %s: %s' % (test.name, msg)) |
|
2716 | 2716 | |
|
2717 | 2717 | if self._runner.options.xunit: |
|
2718 | 2718 | with open(self._runner.options.xunit, "wb") as xuf: |
|
2719 | 2719 | self._writexunit(self._result, xuf) |
|
2720 | 2720 | |
|
2721 | 2721 | if self._runner.options.json: |
|
2722 | 2722 | jsonpath = os.path.join(self._runner._outputdir, b'report.json') |
|
2723 | 2723 | with open(jsonpath, 'w') as fp: |
|
2724 | 2724 | self._writejson(self._result, fp) |
|
2725 | 2725 | |
|
2726 | 2726 | self._runner._checkhglib('Tested') |
|
2727 | 2727 | |
|
2728 | 2728 | savetimes(self._runner._outputdir, self._result) |
|
2729 | 2729 | |
|
2730 | 2730 | if failed and self._runner.options.known_good_rev: |
|
2731 | 2731 | self._bisecttests(t for t, m in self._result.failures) |
|
2732 | 2732 | self.stream.writeln( |
|
2733 | 2733 | '# Ran %d tests, %d skipped, %d failed.' |
|
2734 | 2734 | % (self._result.testsRun, skipped + ignored, failed) |
|
2735 | 2735 | ) |
|
2736 | 2736 | if failed: |
|
2737 | 2737 | self.stream.writeln( |
|
2738 | 2738 | 'python hash seed: %s' % os.environ['PYTHONHASHSEED'] |
|
2739 | 2739 | ) |
|
2740 | 2740 | if self._runner.options.time: |
|
2741 | 2741 | self.printtimes(self._result.times) |
|
2742 | 2742 | |
|
2743 | 2743 | if self._runner.options.exceptions: |
|
2744 | 2744 | exceptions = aggregateexceptions( |
|
2745 | 2745 | os.path.join(self._runner._outputdir, b'exceptions') |
|
2746 | 2746 | ) |
|
2747 | 2747 | |
|
2748 | 2748 | self.stream.writeln('Exceptions Report:') |
|
2749 | 2749 | self.stream.writeln( |
|
2750 | 2750 | '%d total from %d frames' |
|
2751 | 2751 | % (exceptions['total'], len(exceptions['exceptioncounts'])) |
|
2752 | 2752 | ) |
|
2753 | 2753 | combined = exceptions['combined'] |
|
2754 | 2754 | for key in sorted(combined, key=combined.get, reverse=True): |
|
2755 | 2755 | frame, line, exc = key |
|
2756 | 2756 | totalcount, testcount, leastcount, leasttest = combined[key] |
|
2757 | 2757 | |
|
2758 | 2758 | self.stream.writeln( |
|
2759 | 2759 | '%d (%d tests)\t%s: %s (%s - %d total)' |
|
2760 | 2760 | % ( |
|
2761 | 2761 | totalcount, |
|
2762 | 2762 | testcount, |
|
2763 | 2763 | frame, |
|
2764 | 2764 | exc, |
|
2765 | 2765 | leasttest, |
|
2766 | 2766 | leastcount, |
|
2767 | 2767 | ) |
|
2768 | 2768 | ) |
|
2769 | 2769 | |
|
2770 | 2770 | self.stream.flush() |
|
2771 | 2771 | |
|
2772 | 2772 | return self._result |
|
2773 | 2773 | |
|
2774 | 2774 | def _bisecttests(self, tests): |
|
2775 | 2775 | bisectcmd = ['hg', 'bisect'] |
|
2776 | 2776 | bisectrepo = self._runner.options.bisect_repo |
|
2777 | 2777 | if bisectrepo: |
|
2778 | 2778 | bisectcmd.extend(['-R', os.path.abspath(bisectrepo)]) |
|
2779 | 2779 | |
|
2780 | 2780 | def pread(args): |
|
2781 | 2781 | env = os.environ.copy() |
|
2782 | 2782 | env['HGPLAIN'] = '1' |
|
2783 | 2783 | p = subprocess.Popen( |
|
2784 | 2784 | args, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, env=env |
|
2785 | 2785 | ) |
|
2786 | 2786 | data = p.stdout.read() |
|
2787 | 2787 | p.wait() |
|
2788 | 2788 | return data |
|
2789 | 2789 | |
|
2790 | 2790 | for test in tests: |
|
2791 | 2791 | pread(bisectcmd + ['--reset']), |
|
2792 | 2792 | pread(bisectcmd + ['--bad', '.']) |
|
2793 | 2793 | pread(bisectcmd + ['--good', self._runner.options.known_good_rev]) |
|
2794 | 2794 | # TODO: we probably need to forward more options |
|
2795 | 2795 | # that alter hg's behavior inside the tests. |
|
2796 | 2796 | opts = '' |
|
2797 | 2797 | withhg = self._runner.options.with_hg |
|
2798 | 2798 | if withhg: |
|
2799 | 2799 | opts += ' --with-hg=%s ' % shellquote(_bytes2sys(withhg)) |
|
2800 | 2800 | rtc = '%s %s %s %s' % (sysexecutable, sys.argv[0], opts, test) |
|
2801 | 2801 | data = pread(bisectcmd + ['--command', rtc]) |
|
2802 | 2802 | m = re.search( |
|
2803 | 2803 | ( |
|
2804 | 2804 | br'\nThe first (?P<goodbad>bad|good) revision ' |
|
2805 | 2805 | br'is:\nchangeset: +\d+:(?P<node>[a-f0-9]+)\n.*\n' |
|
2806 | 2806 | br'summary: +(?P<summary>[^\n]+)\n' |
|
2807 | 2807 | ), |
|
2808 | 2808 | data, |
|
2809 | 2809 | (re.MULTILINE | re.DOTALL), |
|
2810 | 2810 | ) |
|
2811 | 2811 | if m is None: |
|
2812 | 2812 | self.stream.writeln( |
|
2813 | 2813 | 'Failed to identify failure point for %s' % test |
|
2814 | 2814 | ) |
|
2815 | 2815 | continue |
|
2816 | 2816 | dat = m.groupdict() |
|
2817 | 2817 | verb = 'broken' if dat['goodbad'] == b'bad' else 'fixed' |
|
2818 | 2818 | self.stream.writeln( |
|
2819 | 2819 | '%s %s by %s (%s)' |
|
2820 | 2820 | % ( |
|
2821 | 2821 | test, |
|
2822 | 2822 | verb, |
|
2823 | 2823 | dat['node'].decode('ascii'), |
|
2824 | 2824 | dat['summary'].decode('utf8', 'ignore'), |
|
2825 | 2825 | ) |
|
2826 | 2826 | ) |
|
2827 | 2827 | |
|
2828 | 2828 | def printtimes(self, times): |
|
2829 | 2829 | # iolock held by run |
|
2830 | 2830 | self.stream.writeln('# Producing time report') |
|
2831 | 2831 | times.sort(key=lambda t: (t[3])) |
|
2832 | 2832 | cols = '%7.3f %7.3f %7.3f %7.3f %7.3f %s' |
|
2833 | 2833 | self.stream.writeln( |
|
2834 | 2834 | '%-7s %-7s %-7s %-7s %-7s %s' |
|
2835 | 2835 | % ('start', 'end', 'cuser', 'csys', 'real', 'Test') |
|
2836 | 2836 | ) |
|
2837 | 2837 | for tdata in times: |
|
2838 | 2838 | test = tdata[0] |
|
2839 | 2839 | cuser, csys, real, start, end = tdata[1:6] |
|
2840 | 2840 | self.stream.writeln(cols % (start, end, cuser, csys, real, test)) |
|
2841 | 2841 | |
|
2842 | 2842 | @staticmethod |
|
2843 | 2843 | def _writexunit(result, outf): |
|
2844 | 2844 | # See http://llg.cubic.org/docs/junit/ for a reference. |
|
2845 | 2845 | timesd = {t[0]: t[3] for t in result.times} |
|
2846 | 2846 | doc = minidom.Document() |
|
2847 | 2847 | s = doc.createElement('testsuite') |
|
2848 | 2848 | s.setAttribute('errors', "0") # TODO |
|
2849 | 2849 | s.setAttribute('failures', str(len(result.failures))) |
|
2850 | 2850 | s.setAttribute('name', 'run-tests') |
|
2851 | 2851 | s.setAttribute( |
|
2852 | 2852 | 'skipped', str(len(result.skipped) + len(result.ignored)) |
|
2853 | 2853 | ) |
|
2854 | 2854 | s.setAttribute('tests', str(result.testsRun)) |
|
2855 | 2855 | doc.appendChild(s) |
|
2856 | 2856 | for tc in result.successes: |
|
2857 | 2857 | t = doc.createElement('testcase') |
|
2858 | 2858 | t.setAttribute('name', tc.name) |
|
2859 | 2859 | tctime = timesd.get(tc.name) |
|
2860 | 2860 | if tctime is not None: |
|
2861 | 2861 | t.setAttribute('time', '%.3f' % tctime) |
|
2862 | 2862 | s.appendChild(t) |
|
2863 | 2863 | for tc, err in sorted(result.faildata.items()): |
|
2864 | 2864 | t = doc.createElement('testcase') |
|
2865 | 2865 | t.setAttribute('name', tc) |
|
2866 | 2866 | tctime = timesd.get(tc) |
|
2867 | 2867 | if tctime is not None: |
|
2868 | 2868 | t.setAttribute('time', '%.3f' % tctime) |
|
2869 | 2869 | # createCDATASection expects a unicode or it will |
|
2870 | 2870 | # convert using default conversion rules, which will |
|
2871 | 2871 | # fail if string isn't ASCII. |
|
2872 | 2872 | err = cdatasafe(err).decode('utf-8', 'replace') |
|
2873 | 2873 | cd = doc.createCDATASection(err) |
|
2874 | 2874 | # Use 'failure' here instead of 'error' to match errors = 0, |
|
2875 | 2875 | # failures = len(result.failures) in the testsuite element. |
|
2876 | 2876 | failelem = doc.createElement('failure') |
|
2877 | 2877 | failelem.setAttribute('message', 'output changed') |
|
2878 | 2878 | failelem.setAttribute('type', 'output-mismatch') |
|
2879 | 2879 | failelem.appendChild(cd) |
|
2880 | 2880 | t.appendChild(failelem) |
|
2881 | 2881 | s.appendChild(t) |
|
2882 | 2882 | for tc, message in result.skipped: |
|
2883 | 2883 | # According to the schema, 'skipped' has no attributes. So store |
|
2884 | 2884 | # the skip message as a text node instead. |
|
2885 | 2885 | t = doc.createElement('testcase') |
|
2886 | 2886 | t.setAttribute('name', tc.name) |
|
2887 | 2887 | binmessage = message.encode('utf-8') |
|
2888 | 2888 | message = cdatasafe(binmessage).decode('utf-8', 'replace') |
|
2889 | 2889 | cd = doc.createCDATASection(message) |
|
2890 | 2890 | skipelem = doc.createElement('skipped') |
|
2891 | 2891 | skipelem.appendChild(cd) |
|
2892 | 2892 | t.appendChild(skipelem) |
|
2893 | 2893 | s.appendChild(t) |
|
2894 | 2894 | outf.write(doc.toprettyxml(indent=' ', encoding='utf-8')) |
|
2895 | 2895 | |
|
2896 | 2896 | @staticmethod |
|
2897 | 2897 | def _writejson(result, outf): |
|
2898 | 2898 | timesd = {} |
|
2899 | 2899 | for tdata in result.times: |
|
2900 | 2900 | test = tdata[0] |
|
2901 | 2901 | timesd[test] = tdata[1:] |
|
2902 | 2902 | |
|
2903 | 2903 | outcome = {} |
|
2904 | 2904 | groups = [ |
|
2905 | 2905 | ('success', ((tc, None) for tc in result.successes)), |
|
2906 | 2906 | ('failure', result.failures), |
|
2907 | 2907 | ('skip', result.skipped), |
|
2908 | 2908 | ] |
|
2909 | 2909 | for res, testcases in groups: |
|
2910 | 2910 | for tc, __ in testcases: |
|
2911 | 2911 | if tc.name in timesd: |
|
2912 | 2912 | diff = result.faildata.get(tc.name, b'') |
|
2913 | 2913 | try: |
|
2914 | 2914 | diff = diff.decode('unicode_escape') |
|
2915 | 2915 | except UnicodeDecodeError as e: |
|
2916 | 2916 | diff = '%r decoding diff, sorry' % e |
|
2917 | 2917 | tres = { |
|
2918 | 2918 | 'result': res, |
|
2919 | 2919 | 'time': ('%0.3f' % timesd[tc.name][2]), |
|
2920 | 2920 | 'cuser': ('%0.3f' % timesd[tc.name][0]), |
|
2921 | 2921 | 'csys': ('%0.3f' % timesd[tc.name][1]), |
|
2922 | 2922 | 'start': ('%0.3f' % timesd[tc.name][3]), |
|
2923 | 2923 | 'end': ('%0.3f' % timesd[tc.name][4]), |
|
2924 | 2924 | 'diff': diff, |
|
2925 | 2925 | } |
|
2926 | 2926 | else: |
|
2927 | 2927 | # blacklisted test |
|
2928 | 2928 | tres = {'result': res} |
|
2929 | 2929 | |
|
2930 | 2930 | outcome[tc.name] = tres |
|
2931 | 2931 | jsonout = json.dumps( |
|
2932 | 2932 | outcome, sort_keys=True, indent=4, separators=(',', ': ') |
|
2933 | 2933 | ) |
|
2934 | 2934 | outf.writelines(("testreport =", jsonout)) |
|
2935 | 2935 | |
|
2936 | 2936 | |
|
2937 | 2937 | def sorttests(testdescs, previoustimes, shuffle=False): |
|
2938 | 2938 | """Do an in-place sort of tests.""" |
|
2939 | 2939 | if shuffle: |
|
2940 | 2940 | random.shuffle(testdescs) |
|
2941 | 2941 | return |
|
2942 | 2942 | |
|
2943 | 2943 | if previoustimes: |
|
2944 | 2944 | |
|
2945 | 2945 | def sortkey(f): |
|
2946 | 2946 | f = f['path'] |
|
2947 | 2947 | if f in previoustimes: |
|
2948 | 2948 | # Use most recent time as estimate |
|
2949 | 2949 | return -(previoustimes[f][-1]) |
|
2950 | 2950 | else: |
|
2951 | 2951 | # Default to a rather arbitrary value of 1 second for new tests |
|
2952 | 2952 | return -1.0 |
|
2953 | 2953 | |
|
2954 | 2954 | else: |
|
2955 | 2955 | # keywords for slow tests |
|
2956 | 2956 | slow = { |
|
2957 | 2957 | b'svn': 10, |
|
2958 | 2958 | b'cvs': 10, |
|
2959 | 2959 | b'hghave': 10, |
|
2960 | 2960 | b'largefiles-update': 10, |
|
2961 | 2961 | b'run-tests': 10, |
|
2962 | 2962 | b'corruption': 10, |
|
2963 | 2963 | b'race': 10, |
|
2964 | 2964 | b'i18n': 10, |
|
2965 | 2965 | b'check': 100, |
|
2966 | 2966 | b'gendoc': 100, |
|
2967 | 2967 | b'contrib-perf': 200, |
|
2968 | 2968 | b'merge-combination': 100, |
|
2969 | 2969 | } |
|
2970 | 2970 | perf = {} |
|
2971 | 2971 | |
|
2972 | 2972 | def sortkey(f): |
|
2973 | 2973 | # run largest tests first, as they tend to take the longest |
|
2974 | 2974 | f = f['path'] |
|
2975 | 2975 | try: |
|
2976 | 2976 | return perf[f] |
|
2977 | 2977 | except KeyError: |
|
2978 | 2978 | try: |
|
2979 | 2979 | val = -os.stat(f).st_size |
|
2980 | 2980 | except OSError as e: |
|
2981 | 2981 | if e.errno != errno.ENOENT: |
|
2982 | 2982 | raise |
|
2983 | 2983 | perf[f] = -1e9 # file does not exist, tell early |
|
2984 | 2984 | return -1e9 |
|
2985 | 2985 | for kw, mul in slow.items(): |
|
2986 | 2986 | if kw in f: |
|
2987 | 2987 | val *= mul |
|
2988 | 2988 | if f.endswith(b'.py'): |
|
2989 | 2989 | val /= 10.0 |
|
2990 | 2990 | perf[f] = val / 1000.0 |
|
2991 | 2991 | return perf[f] |
|
2992 | 2992 | |
|
2993 | 2993 | testdescs.sort(key=sortkey) |
|
2994 | 2994 | |
|
2995 | 2995 | |
|
2996 | 2996 | class TestRunner(object): |
|
2997 | 2997 | """Holds context for executing tests. |
|
2998 | 2998 | |
|
2999 | 2999 | Tests rely on a lot of state. This object holds it for them. |
|
3000 | 3000 | """ |
|
3001 | 3001 | |
|
3002 | 3002 | # Programs required to run tests. |
|
3003 | 3003 | REQUIREDTOOLS = [ |
|
3004 | 3004 | b'diff', |
|
3005 | 3005 | b'grep', |
|
3006 | 3006 | b'unzip', |
|
3007 | 3007 | b'gunzip', |
|
3008 | 3008 | b'bunzip2', |
|
3009 | 3009 | b'sed', |
|
3010 | 3010 | ] |
|
3011 | 3011 | |
|
3012 | 3012 | # Maps file extensions to test class. |
|
3013 | 3013 | TESTTYPES = [ |
|
3014 | 3014 | (b'.py', PythonTest), |
|
3015 | 3015 | (b'.t', TTest), |
|
3016 | 3016 | ] |
|
3017 | 3017 | |
|
3018 | 3018 | def __init__(self): |
|
3019 | 3019 | self.options = None |
|
3020 | 3020 | self._hgroot = None |
|
3021 | 3021 | self._testdir = None |
|
3022 | 3022 | self._outputdir = None |
|
3023 | 3023 | self._hgtmp = None |
|
3024 | 3024 | self._installdir = None |
|
3025 | 3025 | self._bindir = None |
|
3026 | 3026 | # a place for run-tests.py to generate executable it needs |
|
3027 | 3027 | self._custom_bin_dir = None |
|
3028 | 3028 | self._pythondir = None |
|
3029 | 3029 | # True if we had to infer the pythondir from --with-hg |
|
3030 | 3030 | self._pythondir_inferred = False |
|
3031 | 3031 | self._coveragefile = None |
|
3032 | 3032 | self._createdfiles = [] |
|
3033 | 3033 | self._hgcommand = None |
|
3034 | 3034 | self._hgpath = None |
|
3035 | 3035 | self._portoffset = 0 |
|
3036 | 3036 | self._ports = {} |
|
3037 | 3037 | |
|
3038 | 3038 | def run(self, args, parser=None): |
|
3039 | 3039 | """Run the test suite.""" |
|
3040 | 3040 | oldmask = os.umask(0o22) |
|
3041 | 3041 | try: |
|
3042 | 3042 | parser = parser or getparser() |
|
3043 | 3043 | options = parseargs(args, parser) |
|
3044 | 3044 | tests = [_sys2bytes(a) for a in options.tests] |
|
3045 | 3045 | if options.test_list is not None: |
|
3046 | 3046 | for listfile in options.test_list: |
|
3047 | 3047 | with open(listfile, 'rb') as f: |
|
3048 | 3048 | tests.extend(t for t in f.read().splitlines() if t) |
|
3049 | 3049 | self.options = options |
|
3050 | 3050 | |
|
3051 | 3051 | self._checktools() |
|
3052 | 3052 | testdescs = self.findtests(tests) |
|
3053 | 3053 | if options.profile_runner: |
|
3054 | 3054 | import statprof |
|
3055 | 3055 | |
|
3056 | 3056 | statprof.start() |
|
3057 | 3057 | result = self._run(testdescs) |
|
3058 | 3058 | if options.profile_runner: |
|
3059 | 3059 | statprof.stop() |
|
3060 | 3060 | statprof.display() |
|
3061 | 3061 | return result |
|
3062 | 3062 | |
|
3063 | 3063 | finally: |
|
3064 | 3064 | os.umask(oldmask) |
|
3065 | 3065 | |
|
3066 | 3066 | def _run(self, testdescs): |
|
3067 | 3067 | testdir = getcwdb() |
|
3068 | 3068 | self._testdir = osenvironb[b'TESTDIR'] = getcwdb() |
|
3069 | 3069 | # assume all tests in same folder for now |
|
3070 | 3070 | if testdescs: |
|
3071 | 3071 | pathname = os.path.dirname(testdescs[0]['path']) |
|
3072 | 3072 | if pathname: |
|
3073 | 3073 | testdir = os.path.join(testdir, pathname) |
|
3074 | 3074 | self._testdir = osenvironb[b'TESTDIR'] = testdir |
|
3075 | 3075 | if self.options.outputdir: |
|
3076 | 3076 | self._outputdir = canonpath(_sys2bytes(self.options.outputdir)) |
|
3077 | 3077 | else: |
|
3078 | 3078 | self._outputdir = getcwdb() |
|
3079 | 3079 | if testdescs and pathname: |
|
3080 | 3080 | self._outputdir = os.path.join(self._outputdir, pathname) |
|
3081 | 3081 | previoustimes = {} |
|
3082 | 3082 | if self.options.order_by_runtime: |
|
3083 | 3083 | previoustimes = dict(loadtimes(self._outputdir)) |
|
3084 | 3084 | sorttests(testdescs, previoustimes, shuffle=self.options.random) |
|
3085 | 3085 | |
|
3086 | 3086 | if 'PYTHONHASHSEED' not in os.environ: |
|
3087 | 3087 | # use a random python hash seed all the time |
|
3088 | 3088 | # we do the randomness ourself to know what seed is used |
|
3089 | 3089 | os.environ['PYTHONHASHSEED'] = str(random.getrandbits(32)) |
|
3090 | 3090 | |
|
3091 | 3091 | # Rayon (Rust crate for multi-threading) will use all logical CPU cores |
|
3092 | 3092 | # by default, causing thrashing on high-cpu-count systems. |
|
3093 | 3093 | # Setting its limit to 3 during tests should still let us uncover |
|
3094 | 3094 | # multi-threading bugs while keeping the thrashing reasonable. |
|
3095 | 3095 | os.environ.setdefault("RAYON_NUM_THREADS", "3") |
|
3096 | 3096 | |
|
3097 | 3097 | if self.options.tmpdir: |
|
3098 | 3098 | self.options.keep_tmpdir = True |
|
3099 | 3099 | tmpdir = _sys2bytes(self.options.tmpdir) |
|
3100 | 3100 | if os.path.exists(tmpdir): |
|
3101 | 3101 | # Meaning of tmpdir has changed since 1.3: we used to create |
|
3102 | 3102 | # HGTMP inside tmpdir; now HGTMP is tmpdir. So fail if |
|
3103 | 3103 | # tmpdir already exists. |
|
3104 | 3104 | print("error: temp dir %r already exists" % tmpdir) |
|
3105 | 3105 | return 1 |
|
3106 | 3106 | |
|
3107 | 3107 | os.makedirs(tmpdir) |
|
3108 | 3108 | else: |
|
3109 | 3109 | d = None |
|
3110 | 3110 | if WINDOWS: |
|
3111 | 3111 | # without this, we get the default temp dir location, but |
|
3112 | 3112 | # in all lowercase, which causes troubles with paths (issue3490) |
|
3113 | 3113 | d = osenvironb.get(b'TMP', None) |
|
3114 | 3114 | tmpdir = tempfile.mkdtemp(b'', b'hgtests.', d) |
|
3115 | 3115 | |
|
3116 | 3116 | self._hgtmp = osenvironb[b'HGTMP'] = os.path.realpath(tmpdir) |
|
3117 | 3117 | |
|
3118 | 3118 | self._custom_bin_dir = os.path.join(self._hgtmp, b'custom-bin') |
|
3119 | 3119 | os.makedirs(self._custom_bin_dir) |
|
3120 | 3120 | |
|
3121 | 3121 | if self.options.with_hg: |
|
3122 | 3122 | self._installdir = None |
|
3123 | 3123 | whg = self.options.with_hg |
|
3124 | 3124 | self._bindir = os.path.dirname(os.path.realpath(whg)) |
|
3125 | 3125 | assert isinstance(self._bindir, bytes) |
|
3126 | 3126 | self._hgcommand = os.path.basename(whg) |
|
3127 | 3127 | |
|
3128 | 3128 | normbin = os.path.normpath(os.path.abspath(whg)) |
|
3129 | 3129 | normbin = normbin.replace(_sys2bytes(os.sep), b'/') |
|
3130 | 3130 | |
|
3131 | 3131 | # Other Python scripts in the test harness need to |
|
3132 | 3132 | # `import mercurial`. If `hg` is a Python script, we assume |
|
3133 | 3133 | # the Mercurial modules are relative to its path and tell the tests |
|
3134 | 3134 | # to load Python modules from its directory. |
|
3135 | 3135 | with open(whg, 'rb') as fh: |
|
3136 | 3136 | initial = fh.read(1024) |
|
3137 | 3137 | |
|
3138 | 3138 | if re.match(b'#!.*python', initial): |
|
3139 | 3139 | self._pythondir = self._bindir |
|
3140 | 3140 | # If it looks like our in-repo Rust binary, use the source root. |
|
3141 | 3141 | # This is a bit hacky. But rhg is still not supported outside the |
|
3142 | 3142 | # source directory. So until it is, do the simple thing. |
|
3143 | 3143 | elif re.search(b'/rust/target/[^/]+/hg', normbin): |
|
3144 | 3144 | self._pythondir = os.path.dirname(self._testdir) |
|
3145 | 3145 | # Fall back to the legacy behavior. |
|
3146 | 3146 | else: |
|
3147 | 3147 | self._pythondir = self._bindir |
|
3148 | 3148 | self._pythondir_inferred = True |
|
3149 | 3149 | |
|
3150 | 3150 | else: |
|
3151 | 3151 | self._installdir = os.path.join(self._hgtmp, b"install") |
|
3152 | 3152 | self._bindir = os.path.join(self._installdir, b"bin") |
|
3153 | 3153 | self._hgcommand = b'hg' |
|
3154 | 3154 | self._pythondir = os.path.join(self._installdir, b"lib", b"python") |
|
3155 | 3155 | |
|
3156 | 3156 | # Force the use of hg.exe instead of relying on MSYS to recognize hg is |
|
3157 | 3157 | # a python script and feed it to python.exe. Legacy stdio is force |
|
3158 | 3158 | # enabled by hg.exe, and this is a more realistic way to launch hg |
|
3159 | 3159 | # anyway. |
|
3160 | 3160 | if WINDOWS and not self._hgcommand.endswith(b'.exe'): |
|
3161 | 3161 | self._hgcommand += b'.exe' |
|
3162 | 3162 | |
|
3163 | real_hg = os.path.join(self._bindir, self._hgcommand) | |
|
3164 | osenvironb[b'HGTEST_REAL_HG'] = real_hg | |
|
3163 | 3165 | # set CHGHG, then replace "hg" command by "chg" |
|
3164 | 3166 | chgbindir = self._bindir |
|
3165 | 3167 | if self.options.chg or self.options.with_chg: |
|
3166 |
osenvironb[b'CHGHG'] = |
|
|
3168 | osenvironb[b'CHGHG'] = real_hg | |
|
3167 | 3169 | else: |
|
3168 | 3170 | osenvironb.pop(b'CHGHG', None) # drop flag for hghave |
|
3169 | 3171 | if self.options.chg: |
|
3170 | 3172 | self._hgcommand = b'chg' |
|
3171 | 3173 | elif self.options.with_chg: |
|
3172 | 3174 | chgbindir = os.path.dirname(os.path.realpath(self.options.with_chg)) |
|
3173 | 3175 | self._hgcommand = os.path.basename(self.options.with_chg) |
|
3174 | 3176 | |
|
3175 | 3177 | # configure fallback and replace "hg" command by "rhg" |
|
3176 | 3178 | rhgbindir = self._bindir |
|
3177 | 3179 | if self.options.rhg or self.options.with_rhg: |
|
3178 | 3180 | # Affects hghave.py |
|
3179 | 3181 | osenvironb[b'RHG_INSTALLED_AS_HG'] = b'1' |
|
3180 | 3182 | # Affects configuration. Alternatives would be setting configuration through |
|
3181 | 3183 | # `$HGRCPATH` but some tests override that, or changing `_hgcommand` to include |
|
3182 | 3184 | # `--config` but that disrupts tests that print command lines and check expected |
|
3183 | 3185 | # output. |
|
3184 | 3186 | osenvironb[b'RHG_ON_UNSUPPORTED'] = b'fallback' |
|
3185 |
osenvironb[b'RHG_FALLBACK_EXECUTABLE'] = |
|
|
3186 | self._bindir, self._hgcommand | |
|
3187 | ) | |
|
3187 | osenvironb[b'RHG_FALLBACK_EXECUTABLE'] = real_hg | |
|
3188 | 3188 | if self.options.rhg: |
|
3189 | 3189 | self._hgcommand = b'rhg' |
|
3190 | 3190 | elif self.options.with_rhg: |
|
3191 | 3191 | rhgbindir = os.path.dirname(os.path.realpath(self.options.with_rhg)) |
|
3192 | 3192 | self._hgcommand = os.path.basename(self.options.with_rhg) |
|
3193 | 3193 | |
|
3194 | 3194 | osenvironb[b"BINDIR"] = self._bindir |
|
3195 | 3195 | osenvironb[b"PYTHON"] = PYTHON |
|
3196 | 3196 | |
|
3197 | 3197 | fileb = _sys2bytes(__file__) |
|
3198 | 3198 | runtestdir = os.path.abspath(os.path.dirname(fileb)) |
|
3199 | 3199 | osenvironb[b'RUNTESTDIR'] = runtestdir |
|
3200 | 3200 | if PYTHON3: |
|
3201 | 3201 | sepb = _sys2bytes(os.pathsep) |
|
3202 | 3202 | else: |
|
3203 | 3203 | sepb = os.pathsep |
|
3204 | 3204 | path = [self._bindir, runtestdir] + osenvironb[b"PATH"].split(sepb) |
|
3205 | 3205 | if os.path.islink(__file__): |
|
3206 | 3206 | # test helper will likely be at the end of the symlink |
|
3207 | 3207 | realfile = os.path.realpath(fileb) |
|
3208 | 3208 | realdir = os.path.abspath(os.path.dirname(realfile)) |
|
3209 | 3209 | path.insert(2, realdir) |
|
3210 | 3210 | if chgbindir != self._bindir: |
|
3211 | 3211 | path.insert(1, chgbindir) |
|
3212 | 3212 | if rhgbindir != self._bindir: |
|
3213 | 3213 | path.insert(1, rhgbindir) |
|
3214 | 3214 | if self._testdir != runtestdir: |
|
3215 | 3215 | path = [self._testdir] + path |
|
3216 | 3216 | path = [self._custom_bin_dir] + path |
|
3217 | 3217 | osenvironb[b"PATH"] = sepb.join(path) |
|
3218 | 3218 | |
|
3219 | 3219 | # Include TESTDIR in PYTHONPATH so that out-of-tree extensions |
|
3220 | 3220 | # can run .../tests/run-tests.py test-foo where test-foo |
|
3221 | 3221 | # adds an extension to HGRC. Also include run-test.py directory to |
|
3222 | 3222 | # import modules like heredoctest. |
|
3223 | 3223 | pypath = [self._pythondir, self._testdir, runtestdir] |
|
3224 | 3224 | # We have to augment PYTHONPATH, rather than simply replacing |
|
3225 | 3225 | # it, in case external libraries are only available via current |
|
3226 | 3226 | # PYTHONPATH. (In particular, the Subversion bindings on OS X |
|
3227 | 3227 | # are in /opt/subversion.) |
|
3228 | 3228 | oldpypath = osenvironb.get(IMPL_PATH) |
|
3229 | 3229 | if oldpypath: |
|
3230 | 3230 | pypath.append(oldpypath) |
|
3231 | 3231 | osenvironb[IMPL_PATH] = sepb.join(pypath) |
|
3232 | 3232 | |
|
3233 | 3233 | if self.options.pure: |
|
3234 | 3234 | os.environ["HGTEST_RUN_TESTS_PURE"] = "--pure" |
|
3235 | 3235 | os.environ["HGMODULEPOLICY"] = "py" |
|
3236 | 3236 | if self.options.rust: |
|
3237 | 3237 | os.environ["HGMODULEPOLICY"] = "rust+c" |
|
3238 | 3238 | if self.options.no_rust: |
|
3239 | 3239 | current_policy = os.environ.get("HGMODULEPOLICY", "") |
|
3240 | 3240 | if current_policy.startswith("rust+"): |
|
3241 | 3241 | os.environ["HGMODULEPOLICY"] = current_policy[len("rust+") :] |
|
3242 | 3242 | os.environ.pop("HGWITHRUSTEXT", None) |
|
3243 | 3243 | |
|
3244 | 3244 | if self.options.allow_slow_tests: |
|
3245 | 3245 | os.environ["HGTEST_SLOW"] = "slow" |
|
3246 | 3246 | elif 'HGTEST_SLOW' in os.environ: |
|
3247 | 3247 | del os.environ['HGTEST_SLOW'] |
|
3248 | 3248 | |
|
3249 | 3249 | self._coveragefile = os.path.join(self._testdir, b'.coverage') |
|
3250 | 3250 | |
|
3251 | 3251 | if self.options.exceptions: |
|
3252 | 3252 | exceptionsdir = os.path.join(self._outputdir, b'exceptions') |
|
3253 | 3253 | try: |
|
3254 | 3254 | os.makedirs(exceptionsdir) |
|
3255 | 3255 | except OSError as e: |
|
3256 | 3256 | if e.errno != errno.EEXIST: |
|
3257 | 3257 | raise |
|
3258 | 3258 | |
|
3259 | 3259 | # Remove all existing exception reports. |
|
3260 | 3260 | for f in os.listdir(exceptionsdir): |
|
3261 | 3261 | os.unlink(os.path.join(exceptionsdir, f)) |
|
3262 | 3262 | |
|
3263 | 3263 | osenvironb[b'HGEXCEPTIONSDIR'] = exceptionsdir |
|
3264 | 3264 | logexceptions = os.path.join(self._testdir, b'logexceptions.py') |
|
3265 | 3265 | self.options.extra_config_opt.append( |
|
3266 | 3266 | 'extensions.logexceptions=%s' % logexceptions.decode('utf-8') |
|
3267 | 3267 | ) |
|
3268 | 3268 | |
|
3269 | 3269 | vlog("# Using TESTDIR", _bytes2sys(self._testdir)) |
|
3270 | 3270 | vlog("# Using RUNTESTDIR", _bytes2sys(osenvironb[b'RUNTESTDIR'])) |
|
3271 | 3271 | vlog("# Using HGTMP", _bytes2sys(self._hgtmp)) |
|
3272 | 3272 | vlog("# Using PATH", os.environ["PATH"]) |
|
3273 | 3273 | vlog( |
|
3274 | 3274 | "# Using", |
|
3275 | 3275 | _bytes2sys(IMPL_PATH), |
|
3276 | 3276 | _bytes2sys(osenvironb[IMPL_PATH]), |
|
3277 | 3277 | ) |
|
3278 | 3278 | vlog("# Writing to directory", _bytes2sys(self._outputdir)) |
|
3279 | 3279 | |
|
3280 | 3280 | try: |
|
3281 | 3281 | return self._runtests(testdescs) or 0 |
|
3282 | 3282 | finally: |
|
3283 | 3283 | time.sleep(0.1) |
|
3284 | 3284 | self._cleanup() |
|
3285 | 3285 | |
|
3286 | 3286 | def findtests(self, args): |
|
3287 | 3287 | """Finds possible test files from arguments. |
|
3288 | 3288 | |
|
3289 | 3289 | If you wish to inject custom tests into the test harness, this would |
|
3290 | 3290 | be a good function to monkeypatch or override in a derived class. |
|
3291 | 3291 | """ |
|
3292 | 3292 | if not args: |
|
3293 | 3293 | if self.options.changed: |
|
3294 | 3294 | proc = Popen4( |
|
3295 | 3295 | b'hg st --rev "%s" -man0 .' |
|
3296 | 3296 | % _sys2bytes(self.options.changed), |
|
3297 | 3297 | None, |
|
3298 | 3298 | 0, |
|
3299 | 3299 | ) |
|
3300 | 3300 | stdout, stderr = proc.communicate() |
|
3301 | 3301 | args = stdout.strip(b'\0').split(b'\0') |
|
3302 | 3302 | else: |
|
3303 | 3303 | args = os.listdir(b'.') |
|
3304 | 3304 | |
|
3305 | 3305 | expanded_args = [] |
|
3306 | 3306 | for arg in args: |
|
3307 | 3307 | if os.path.isdir(arg): |
|
3308 | 3308 | if not arg.endswith(b'/'): |
|
3309 | 3309 | arg += b'/' |
|
3310 | 3310 | expanded_args.extend([arg + a for a in os.listdir(arg)]) |
|
3311 | 3311 | else: |
|
3312 | 3312 | expanded_args.append(arg) |
|
3313 | 3313 | args = expanded_args |
|
3314 | 3314 | |
|
3315 | 3315 | testcasepattern = re.compile(br'([\w-]+\.t|py)(?:#([a-zA-Z0-9_\-.#]+))') |
|
3316 | 3316 | tests = [] |
|
3317 | 3317 | for t in args: |
|
3318 | 3318 | case = [] |
|
3319 | 3319 | |
|
3320 | 3320 | if not ( |
|
3321 | 3321 | os.path.basename(t).startswith(b'test-') |
|
3322 | 3322 | and (t.endswith(b'.py') or t.endswith(b'.t')) |
|
3323 | 3323 | ): |
|
3324 | 3324 | |
|
3325 | 3325 | m = testcasepattern.match(os.path.basename(t)) |
|
3326 | 3326 | if m is not None: |
|
3327 | 3327 | t_basename, casestr = m.groups() |
|
3328 | 3328 | t = os.path.join(os.path.dirname(t), t_basename) |
|
3329 | 3329 | if casestr: |
|
3330 | 3330 | case = casestr.split(b'#') |
|
3331 | 3331 | else: |
|
3332 | 3332 | continue |
|
3333 | 3333 | |
|
3334 | 3334 | if t.endswith(b'.t'): |
|
3335 | 3335 | # .t file may contain multiple test cases |
|
3336 | 3336 | casedimensions = parsettestcases(t) |
|
3337 | 3337 | if casedimensions: |
|
3338 | 3338 | cases = [] |
|
3339 | 3339 | |
|
3340 | 3340 | def addcases(case, casedimensions): |
|
3341 | 3341 | if not casedimensions: |
|
3342 | 3342 | cases.append(case) |
|
3343 | 3343 | else: |
|
3344 | 3344 | for c in casedimensions[0]: |
|
3345 | 3345 | addcases(case + [c], casedimensions[1:]) |
|
3346 | 3346 | |
|
3347 | 3347 | addcases([], casedimensions) |
|
3348 | 3348 | if case and case in cases: |
|
3349 | 3349 | cases = [case] |
|
3350 | 3350 | elif case: |
|
3351 | 3351 | # Ignore invalid cases |
|
3352 | 3352 | cases = [] |
|
3353 | 3353 | else: |
|
3354 | 3354 | pass |
|
3355 | 3355 | tests += [{'path': t, 'case': c} for c in sorted(cases)] |
|
3356 | 3356 | else: |
|
3357 | 3357 | tests.append({'path': t}) |
|
3358 | 3358 | else: |
|
3359 | 3359 | tests.append({'path': t}) |
|
3360 | 3360 | |
|
3361 | 3361 | if self.options.retest: |
|
3362 | 3362 | retest_args = [] |
|
3363 | 3363 | for test in tests: |
|
3364 | 3364 | errpath = self._geterrpath(test) |
|
3365 | 3365 | if os.path.exists(errpath): |
|
3366 | 3366 | retest_args.append(test) |
|
3367 | 3367 | tests = retest_args |
|
3368 | 3368 | return tests |
|
3369 | 3369 | |
|
3370 | 3370 | def _runtests(self, testdescs): |
|
3371 | 3371 | def _reloadtest(test, i): |
|
3372 | 3372 | # convert a test back to its description dict |
|
3373 | 3373 | desc = {'path': test.path} |
|
3374 | 3374 | case = getattr(test, '_case', []) |
|
3375 | 3375 | if case: |
|
3376 | 3376 | desc['case'] = case |
|
3377 | 3377 | return self._gettest(desc, i) |
|
3378 | 3378 | |
|
3379 | 3379 | try: |
|
3380 | 3380 | if self.options.restart: |
|
3381 | 3381 | orig = list(testdescs) |
|
3382 | 3382 | while testdescs: |
|
3383 | 3383 | desc = testdescs[0] |
|
3384 | 3384 | errpath = self._geterrpath(desc) |
|
3385 | 3385 | if os.path.exists(errpath): |
|
3386 | 3386 | break |
|
3387 | 3387 | testdescs.pop(0) |
|
3388 | 3388 | if not testdescs: |
|
3389 | 3389 | print("running all tests") |
|
3390 | 3390 | testdescs = orig |
|
3391 | 3391 | |
|
3392 | 3392 | tests = [self._gettest(d, i) for i, d in enumerate(testdescs)] |
|
3393 | 3393 | num_tests = len(tests) * self.options.runs_per_test |
|
3394 | 3394 | |
|
3395 | 3395 | jobs = min(num_tests, self.options.jobs) |
|
3396 | 3396 | |
|
3397 | 3397 | failed = False |
|
3398 | 3398 | kws = self.options.keywords |
|
3399 | 3399 | if kws is not None and PYTHON3: |
|
3400 | 3400 | kws = kws.encode('utf-8') |
|
3401 | 3401 | |
|
3402 | 3402 | suite = TestSuite( |
|
3403 | 3403 | self._testdir, |
|
3404 | 3404 | jobs=jobs, |
|
3405 | 3405 | whitelist=self.options.whitelisted, |
|
3406 | 3406 | blacklist=self.options.blacklist, |
|
3407 | 3407 | keywords=kws, |
|
3408 | 3408 | loop=self.options.loop, |
|
3409 | 3409 | runs_per_test=self.options.runs_per_test, |
|
3410 | 3410 | showchannels=self.options.showchannels, |
|
3411 | 3411 | tests=tests, |
|
3412 | 3412 | loadtest=_reloadtest, |
|
3413 | 3413 | ) |
|
3414 | 3414 | verbosity = 1 |
|
3415 | 3415 | if self.options.list_tests: |
|
3416 | 3416 | verbosity = 0 |
|
3417 | 3417 | elif self.options.verbose: |
|
3418 | 3418 | verbosity = 2 |
|
3419 | 3419 | runner = TextTestRunner(self, verbosity=verbosity) |
|
3420 | 3420 | |
|
3421 | 3421 | if self.options.list_tests: |
|
3422 | 3422 | result = runner.listtests(suite) |
|
3423 | 3423 | else: |
|
3424 | 3424 | self._usecorrectpython() |
|
3425 | 3425 | if self._installdir: |
|
3426 | 3426 | self._installhg() |
|
3427 | 3427 | self._checkhglib("Testing") |
|
3428 | 3428 | if self.options.chg: |
|
3429 | 3429 | assert self._installdir |
|
3430 | 3430 | self._installchg() |
|
3431 | 3431 | if self.options.rhg: |
|
3432 | 3432 | assert self._installdir |
|
3433 | 3433 | self._installrhg() |
|
3434 | 3434 | |
|
3435 | 3435 | log( |
|
3436 | 3436 | 'running %d tests using %d parallel processes' |
|
3437 | 3437 | % (num_tests, jobs) |
|
3438 | 3438 | ) |
|
3439 | 3439 | |
|
3440 | 3440 | result = runner.run(suite) |
|
3441 | 3441 | |
|
3442 | 3442 | if result.failures or result.errors: |
|
3443 | 3443 | failed = True |
|
3444 | 3444 | |
|
3445 | 3445 | result.onEnd() |
|
3446 | 3446 | |
|
3447 | 3447 | if self.options.anycoverage: |
|
3448 | 3448 | self._outputcoverage() |
|
3449 | 3449 | except KeyboardInterrupt: |
|
3450 | 3450 | failed = True |
|
3451 | 3451 | print("\ninterrupted!") |
|
3452 | 3452 | |
|
3453 | 3453 | if failed: |
|
3454 | 3454 | return 1 |
|
3455 | 3455 | |
|
3456 | 3456 | def _geterrpath(self, test): |
|
3457 | 3457 | # test['path'] is a relative path |
|
3458 | 3458 | if 'case' in test: |
|
3459 | 3459 | # for multiple dimensions test cases |
|
3460 | 3460 | casestr = b'#'.join(test['case']) |
|
3461 | 3461 | errpath = b'%s#%s.err' % (test['path'], casestr) |
|
3462 | 3462 | else: |
|
3463 | 3463 | errpath = b'%s.err' % test['path'] |
|
3464 | 3464 | if self.options.outputdir: |
|
3465 | 3465 | self._outputdir = canonpath(_sys2bytes(self.options.outputdir)) |
|
3466 | 3466 | errpath = os.path.join(self._outputdir, errpath) |
|
3467 | 3467 | return errpath |
|
3468 | 3468 | |
|
3469 | 3469 | def _getport(self, count): |
|
3470 | 3470 | port = self._ports.get(count) # do we have a cached entry? |
|
3471 | 3471 | if port is None: |
|
3472 | 3472 | portneeded = 3 |
|
3473 | 3473 | # above 100 tries we just give up and let test reports failure |
|
3474 | 3474 | for tries in xrange(100): |
|
3475 | 3475 | allfree = True |
|
3476 | 3476 | port = self.options.port + self._portoffset |
|
3477 | 3477 | for idx in xrange(portneeded): |
|
3478 | 3478 | if not checkportisavailable(port + idx): |
|
3479 | 3479 | allfree = False |
|
3480 | 3480 | break |
|
3481 | 3481 | self._portoffset += portneeded |
|
3482 | 3482 | if allfree: |
|
3483 | 3483 | break |
|
3484 | 3484 | self._ports[count] = port |
|
3485 | 3485 | return port |
|
3486 | 3486 | |
|
3487 | 3487 | def _gettest(self, testdesc, count): |
|
3488 | 3488 | """Obtain a Test by looking at its filename. |
|
3489 | 3489 | |
|
3490 | 3490 | Returns a Test instance. The Test may not be runnable if it doesn't |
|
3491 | 3491 | map to a known type. |
|
3492 | 3492 | """ |
|
3493 | 3493 | path = testdesc['path'] |
|
3494 | 3494 | lctest = path.lower() |
|
3495 | 3495 | testcls = Test |
|
3496 | 3496 | |
|
3497 | 3497 | for ext, cls in self.TESTTYPES: |
|
3498 | 3498 | if lctest.endswith(ext): |
|
3499 | 3499 | testcls = cls |
|
3500 | 3500 | break |
|
3501 | 3501 | |
|
3502 | 3502 | refpath = os.path.join(getcwdb(), path) |
|
3503 | 3503 | tmpdir = os.path.join(self._hgtmp, b'child%d' % count) |
|
3504 | 3504 | |
|
3505 | 3505 | # extra keyword parameters. 'case' is used by .t tests |
|
3506 | 3506 | kwds = {k: testdesc[k] for k in ['case'] if k in testdesc} |
|
3507 | 3507 | |
|
3508 | 3508 | t = testcls( |
|
3509 | 3509 | refpath, |
|
3510 | 3510 | self._outputdir, |
|
3511 | 3511 | tmpdir, |
|
3512 | 3512 | keeptmpdir=self.options.keep_tmpdir, |
|
3513 | 3513 | debug=self.options.debug, |
|
3514 | 3514 | first=self.options.first, |
|
3515 | 3515 | timeout=self.options.timeout, |
|
3516 | 3516 | startport=self._getport(count), |
|
3517 | 3517 | extraconfigopts=self.options.extra_config_opt, |
|
3518 | 3518 | shell=self.options.shell, |
|
3519 | 3519 | hgcommand=self._hgcommand, |
|
3520 | 3520 | usechg=bool(self.options.with_chg or self.options.chg), |
|
3521 | 3521 | chgdebug=self.options.chg_debug, |
|
3522 | 3522 | useipv6=useipv6, |
|
3523 | 3523 | **kwds |
|
3524 | 3524 | ) |
|
3525 | 3525 | t.should_reload = True |
|
3526 | 3526 | return t |
|
3527 | 3527 | |
|
3528 | 3528 | def _cleanup(self): |
|
3529 | 3529 | """Clean up state from this test invocation.""" |
|
3530 | 3530 | if self.options.keep_tmpdir: |
|
3531 | 3531 | return |
|
3532 | 3532 | |
|
3533 | 3533 | vlog("# Cleaning up HGTMP", _bytes2sys(self._hgtmp)) |
|
3534 | 3534 | shutil.rmtree(self._hgtmp, True) |
|
3535 | 3535 | for f in self._createdfiles: |
|
3536 | 3536 | try: |
|
3537 | 3537 | os.remove(f) |
|
3538 | 3538 | except OSError: |
|
3539 | 3539 | pass |
|
3540 | 3540 | |
|
3541 | 3541 | def _usecorrectpython(self): |
|
3542 | 3542 | """Configure the environment to use the appropriate Python in tests.""" |
|
3543 | 3543 | # Tests must use the same interpreter as us or bad things will happen. |
|
3544 | 3544 | if sys.platform == 'win32': |
|
3545 | 3545 | pyexe_names = [b'python', b'python.exe'] |
|
3546 | 3546 | elif sys.version_info[0] < 3: |
|
3547 | 3547 | pyexe_names = [b'python', b'python2'] |
|
3548 | 3548 | else: |
|
3549 | 3549 | pyexe_names = [b'python', b'python3'] |
|
3550 | 3550 | |
|
3551 | 3551 | # os.symlink() is a thing with py3 on Windows, but it requires |
|
3552 | 3552 | # Administrator rights. |
|
3553 | 3553 | if getattr(os, 'symlink', None) and not WINDOWS: |
|
3554 | 3554 | msg = "# Making python executable in test path a symlink to '%s'" |
|
3555 | 3555 | msg %= sysexecutable |
|
3556 | 3556 | vlog(msg) |
|
3557 | 3557 | for pyexename in pyexe_names: |
|
3558 | 3558 | mypython = os.path.join(self._custom_bin_dir, pyexename) |
|
3559 | 3559 | try: |
|
3560 | 3560 | if os.readlink(mypython) == sysexecutable: |
|
3561 | 3561 | continue |
|
3562 | 3562 | os.unlink(mypython) |
|
3563 | 3563 | except OSError as err: |
|
3564 | 3564 | if err.errno != errno.ENOENT: |
|
3565 | 3565 | raise |
|
3566 | 3566 | if self._findprogram(pyexename) != sysexecutable: |
|
3567 | 3567 | try: |
|
3568 | 3568 | os.symlink(sysexecutable, mypython) |
|
3569 | 3569 | self._createdfiles.append(mypython) |
|
3570 | 3570 | except OSError as err: |
|
3571 | 3571 | # child processes may race, which is harmless |
|
3572 | 3572 | if err.errno != errno.EEXIST: |
|
3573 | 3573 | raise |
|
3574 | 3574 | else: |
|
3575 | 3575 | # Windows doesn't have `python3.exe`, and MSYS cannot understand the |
|
3576 | 3576 | # reparse point with that name provided by Microsoft. Create a |
|
3577 | 3577 | # simple script on PATH with that name that delegates to the py3 |
|
3578 | 3578 | # launcher so the shebang lines work. |
|
3579 | 3579 | if os.getenv('MSYSTEM'): |
|
3580 | 3580 | py3exe_name = os.path.join(self._custom_bin_dir, b'python3') |
|
3581 | 3581 | with open(py3exe_name, 'wb') as f: |
|
3582 | 3582 | f.write(b'#!/bin/sh\n') |
|
3583 | 3583 | f.write(b'py -3.%d "$@"\n' % sys.version_info[1]) |
|
3584 | 3584 | |
|
3585 | 3585 | pyexe_name = os.path.join(self._custom_bin_dir, b'python') |
|
3586 | 3586 | with open(pyexe_name, 'wb') as f: |
|
3587 | 3587 | f.write(b'#!/bin/sh\n') |
|
3588 | 3588 | f.write(b'py -%d.%d "$@"\n' % sys.version_info[0:2]) |
|
3589 | 3589 | |
|
3590 | 3590 | exedir, exename = os.path.split(sysexecutable) |
|
3591 | 3591 | for pyexename in pyexe_names: |
|
3592 | 3592 | msg = "# Modifying search path to find %s as %s in '%s'" |
|
3593 | 3593 | msg %= (exename, pyexename, exedir) |
|
3594 | 3594 | vlog(msg) |
|
3595 | 3595 | path = os.environ['PATH'].split(os.pathsep) |
|
3596 | 3596 | while exedir in path: |
|
3597 | 3597 | path.remove(exedir) |
|
3598 | 3598 | |
|
3599 | 3599 | # Binaries installed by pip into the user area like pylint.exe may |
|
3600 | 3600 | # not be in PATH by default. |
|
3601 | 3601 | extra_paths = [exedir] |
|
3602 | 3602 | vi = sys.version_info |
|
3603 | 3603 | appdata = os.environ.get('APPDATA') |
|
3604 | 3604 | if appdata is not None: |
|
3605 | 3605 | scripts_dir = os.path.join( |
|
3606 | 3606 | appdata, |
|
3607 | 3607 | 'Python', |
|
3608 | 3608 | 'Python%d%d' % (vi[0], vi[1]), |
|
3609 | 3609 | 'Scripts', |
|
3610 | 3610 | ) |
|
3611 | 3611 | |
|
3612 | 3612 | if vi.major == 2: |
|
3613 | 3613 | scripts_dir = os.path.join( |
|
3614 | 3614 | appdata, |
|
3615 | 3615 | 'Python', |
|
3616 | 3616 | 'Scripts', |
|
3617 | 3617 | ) |
|
3618 | 3618 | |
|
3619 | 3619 | extra_paths.append(scripts_dir) |
|
3620 | 3620 | |
|
3621 | 3621 | os.environ['PATH'] = os.pathsep.join(extra_paths + path) |
|
3622 | 3622 | for pyexename in pyexe_names: |
|
3623 | 3623 | if not self._findprogram(pyexename): |
|
3624 | 3624 | print("WARNING: Cannot find %s in search path" % pyexename) |
|
3625 | 3625 | |
|
3626 | 3626 | def _installhg(self): |
|
3627 | 3627 | """Install hg into the test environment. |
|
3628 | 3628 | |
|
3629 | 3629 | This will also configure hg with the appropriate testing settings. |
|
3630 | 3630 | """ |
|
3631 | 3631 | vlog("# Performing temporary installation of HG") |
|
3632 | 3632 | installerrs = os.path.join(self._hgtmp, b"install.err") |
|
3633 | 3633 | compiler = '' |
|
3634 | 3634 | if self.options.compiler: |
|
3635 | 3635 | compiler = '--compiler ' + self.options.compiler |
|
3636 | 3636 | setup_opts = b"" |
|
3637 | 3637 | if self.options.pure: |
|
3638 | 3638 | setup_opts = b"--pure" |
|
3639 | 3639 | elif self.options.rust: |
|
3640 | 3640 | setup_opts = b"--rust" |
|
3641 | 3641 | elif self.options.no_rust: |
|
3642 | 3642 | setup_opts = b"--no-rust" |
|
3643 | 3643 | |
|
3644 | 3644 | # Run installer in hg root |
|
3645 | 3645 | script = os.path.realpath(sys.argv[0]) |
|
3646 | 3646 | exe = sysexecutable |
|
3647 | 3647 | if PYTHON3: |
|
3648 | 3648 | compiler = _sys2bytes(compiler) |
|
3649 | 3649 | script = _sys2bytes(script) |
|
3650 | 3650 | exe = _sys2bytes(exe) |
|
3651 | 3651 | hgroot = os.path.dirname(os.path.dirname(script)) |
|
3652 | 3652 | self._hgroot = hgroot |
|
3653 | 3653 | os.chdir(hgroot) |
|
3654 | 3654 | nohome = b'--home=""' |
|
3655 | 3655 | if WINDOWS: |
|
3656 | 3656 | # The --home="" trick works only on OS where os.sep == '/' |
|
3657 | 3657 | # because of a distutils convert_path() fast-path. Avoid it at |
|
3658 | 3658 | # least on Windows for now, deal with .pydistutils.cfg bugs |
|
3659 | 3659 | # when they happen. |
|
3660 | 3660 | nohome = b'' |
|
3661 | 3661 | cmd = ( |
|
3662 | 3662 | b'"%(exe)s" setup.py %(setup_opts)s clean --all' |
|
3663 | 3663 | b' build %(compiler)s --build-base="%(base)s"' |
|
3664 | 3664 | b' install --force --prefix="%(prefix)s"' |
|
3665 | 3665 | b' --install-lib="%(libdir)s"' |
|
3666 | 3666 | b' --install-scripts="%(bindir)s" %(nohome)s >%(logfile)s 2>&1' |
|
3667 | 3667 | % { |
|
3668 | 3668 | b'exe': exe, |
|
3669 | 3669 | b'setup_opts': setup_opts, |
|
3670 | 3670 | b'compiler': compiler, |
|
3671 | 3671 | b'base': os.path.join(self._hgtmp, b"build"), |
|
3672 | 3672 | b'prefix': self._installdir, |
|
3673 | 3673 | b'libdir': self._pythondir, |
|
3674 | 3674 | b'bindir': self._bindir, |
|
3675 | 3675 | b'nohome': nohome, |
|
3676 | 3676 | b'logfile': installerrs, |
|
3677 | 3677 | } |
|
3678 | 3678 | ) |
|
3679 | 3679 | |
|
3680 | 3680 | # setuptools requires install directories to exist. |
|
3681 | 3681 | def makedirs(p): |
|
3682 | 3682 | try: |
|
3683 | 3683 | os.makedirs(p) |
|
3684 | 3684 | except OSError as e: |
|
3685 | 3685 | if e.errno != errno.EEXIST: |
|
3686 | 3686 | raise |
|
3687 | 3687 | |
|
3688 | 3688 | makedirs(self._pythondir) |
|
3689 | 3689 | makedirs(self._bindir) |
|
3690 | 3690 | |
|
3691 | 3691 | vlog("# Running", cmd.decode("utf-8")) |
|
3692 | 3692 | if subprocess.call(_bytes2sys(cmd), shell=True) == 0: |
|
3693 | 3693 | if not self.options.verbose: |
|
3694 | 3694 | try: |
|
3695 | 3695 | os.remove(installerrs) |
|
3696 | 3696 | except OSError as e: |
|
3697 | 3697 | if e.errno != errno.ENOENT: |
|
3698 | 3698 | raise |
|
3699 | 3699 | else: |
|
3700 | 3700 | with open(installerrs, 'rb') as f: |
|
3701 | 3701 | for line in f: |
|
3702 | 3702 | if PYTHON3: |
|
3703 | 3703 | sys.stdout.buffer.write(line) |
|
3704 | 3704 | else: |
|
3705 | 3705 | sys.stdout.write(line) |
|
3706 | 3706 | sys.exit(1) |
|
3707 | 3707 | os.chdir(self._testdir) |
|
3708 | 3708 | |
|
3709 | 3709 | hgbat = os.path.join(self._bindir, b'hg.bat') |
|
3710 | 3710 | if os.path.isfile(hgbat): |
|
3711 | 3711 | # hg.bat expects to be put in bin/scripts while run-tests.py |
|
3712 | 3712 | # installation layout put it in bin/ directly. Fix it |
|
3713 | 3713 | with open(hgbat, 'rb') as f: |
|
3714 | 3714 | data = f.read() |
|
3715 | 3715 | if br'"%~dp0..\python" "%~dp0hg" %*' in data: |
|
3716 | 3716 | data = data.replace( |
|
3717 | 3717 | br'"%~dp0..\python" "%~dp0hg" %*', |
|
3718 | 3718 | b'"%~dp0python" "%~dp0hg" %*', |
|
3719 | 3719 | ) |
|
3720 | 3720 | with open(hgbat, 'wb') as f: |
|
3721 | 3721 | f.write(data) |
|
3722 | 3722 | else: |
|
3723 | 3723 | print('WARNING: cannot fix hg.bat reference to python.exe') |
|
3724 | 3724 | |
|
3725 | 3725 | if self.options.anycoverage: |
|
3726 | 3726 | custom = os.path.join( |
|
3727 | 3727 | osenvironb[b'RUNTESTDIR'], b'sitecustomize.py' |
|
3728 | 3728 | ) |
|
3729 | 3729 | target = os.path.join(self._pythondir, b'sitecustomize.py') |
|
3730 | 3730 | vlog('# Installing coverage trigger to %s' % target) |
|
3731 | 3731 | shutil.copyfile(custom, target) |
|
3732 | 3732 | rc = os.path.join(self._testdir, b'.coveragerc') |
|
3733 | 3733 | vlog('# Installing coverage rc to %s' % rc) |
|
3734 | 3734 | osenvironb[b'COVERAGE_PROCESS_START'] = rc |
|
3735 | 3735 | covdir = os.path.join(self._installdir, b'..', b'coverage') |
|
3736 | 3736 | try: |
|
3737 | 3737 | os.mkdir(covdir) |
|
3738 | 3738 | except OSError as e: |
|
3739 | 3739 | if e.errno != errno.EEXIST: |
|
3740 | 3740 | raise |
|
3741 | 3741 | |
|
3742 | 3742 | osenvironb[b'COVERAGE_DIR'] = covdir |
|
3743 | 3743 | |
|
3744 | 3744 | def _checkhglib(self, verb): |
|
3745 | 3745 | """Ensure that the 'mercurial' package imported by python is |
|
3746 | 3746 | the one we expect it to be. If not, print a warning to stderr.""" |
|
3747 | 3747 | if self._pythondir_inferred: |
|
3748 | 3748 | # The pythondir has been inferred from --with-hg flag. |
|
3749 | 3749 | # We cannot expect anything sensible here. |
|
3750 | 3750 | return |
|
3751 | 3751 | expecthg = os.path.join(self._pythondir, b'mercurial') |
|
3752 | 3752 | actualhg = self._gethgpath() |
|
3753 | 3753 | if os.path.abspath(actualhg) != os.path.abspath(expecthg): |
|
3754 | 3754 | sys.stderr.write( |
|
3755 | 3755 | 'warning: %s with unexpected mercurial lib: %s\n' |
|
3756 | 3756 | ' (expected %s)\n' % (verb, actualhg, expecthg) |
|
3757 | 3757 | ) |
|
3758 | 3758 | |
|
3759 | 3759 | def _gethgpath(self): |
|
3760 | 3760 | """Return the path to the mercurial package that is actually found by |
|
3761 | 3761 | the current Python interpreter.""" |
|
3762 | 3762 | if self._hgpath is not None: |
|
3763 | 3763 | return self._hgpath |
|
3764 | 3764 | |
|
3765 | 3765 | cmd = b'"%s" -c "import mercurial; print (mercurial.__path__[0])"' |
|
3766 | 3766 | cmd = cmd % PYTHON |
|
3767 | 3767 | if PYTHON3: |
|
3768 | 3768 | cmd = _bytes2sys(cmd) |
|
3769 | 3769 | |
|
3770 | 3770 | p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) |
|
3771 | 3771 | out, err = p.communicate() |
|
3772 | 3772 | |
|
3773 | 3773 | self._hgpath = out.strip() |
|
3774 | 3774 | |
|
3775 | 3775 | return self._hgpath |
|
3776 | 3776 | |
|
3777 | 3777 | def _installchg(self): |
|
3778 | 3778 | """Install chg into the test environment""" |
|
3779 | 3779 | vlog('# Performing temporary installation of CHG') |
|
3780 | 3780 | assert os.path.dirname(self._bindir) == self._installdir |
|
3781 | 3781 | assert self._hgroot, 'must be called after _installhg()' |
|
3782 | 3782 | cmd = b'"%(make)s" clean install PREFIX="%(prefix)s"' % { |
|
3783 | 3783 | b'make': b'make', # TODO: switch by option or environment? |
|
3784 | 3784 | b'prefix': self._installdir, |
|
3785 | 3785 | } |
|
3786 | 3786 | cwd = os.path.join(self._hgroot, b'contrib', b'chg') |
|
3787 | 3787 | vlog("# Running", cmd) |
|
3788 | 3788 | proc = subprocess.Popen( |
|
3789 | 3789 | cmd, |
|
3790 | 3790 | shell=True, |
|
3791 | 3791 | cwd=cwd, |
|
3792 | 3792 | stdin=subprocess.PIPE, |
|
3793 | 3793 | stdout=subprocess.PIPE, |
|
3794 | 3794 | stderr=subprocess.STDOUT, |
|
3795 | 3795 | ) |
|
3796 | 3796 | out, _err = proc.communicate() |
|
3797 | 3797 | if proc.returncode != 0: |
|
3798 | 3798 | if PYTHON3: |
|
3799 | 3799 | sys.stdout.buffer.write(out) |
|
3800 | 3800 | else: |
|
3801 | 3801 | sys.stdout.write(out) |
|
3802 | 3802 | sys.exit(1) |
|
3803 | 3803 | |
|
3804 | 3804 | def _installrhg(self): |
|
3805 | 3805 | """Install rhg into the test environment""" |
|
3806 | 3806 | vlog('# Performing temporary installation of rhg') |
|
3807 | 3807 | assert os.path.dirname(self._bindir) == self._installdir |
|
3808 | 3808 | assert self._hgroot, 'must be called after _installhg()' |
|
3809 | 3809 | cmd = b'"%(make)s" install-rhg PREFIX="%(prefix)s"' % { |
|
3810 | 3810 | b'make': b'make', # TODO: switch by option or environment? |
|
3811 | 3811 | b'prefix': self._installdir, |
|
3812 | 3812 | } |
|
3813 | 3813 | cwd = self._hgroot |
|
3814 | 3814 | vlog("# Running", cmd) |
|
3815 | 3815 | proc = subprocess.Popen( |
|
3816 | 3816 | cmd, |
|
3817 | 3817 | shell=True, |
|
3818 | 3818 | cwd=cwd, |
|
3819 | 3819 | stdin=subprocess.PIPE, |
|
3820 | 3820 | stdout=subprocess.PIPE, |
|
3821 | 3821 | stderr=subprocess.STDOUT, |
|
3822 | 3822 | ) |
|
3823 | 3823 | out, _err = proc.communicate() |
|
3824 | 3824 | if proc.returncode != 0: |
|
3825 | 3825 | if PYTHON3: |
|
3826 | 3826 | sys.stdout.buffer.write(out) |
|
3827 | 3827 | else: |
|
3828 | 3828 | sys.stdout.write(out) |
|
3829 | 3829 | sys.exit(1) |
|
3830 | 3830 | |
|
3831 | 3831 | def _outputcoverage(self): |
|
3832 | 3832 | """Produce code coverage output.""" |
|
3833 | 3833 | import coverage |
|
3834 | 3834 | |
|
3835 | 3835 | coverage = coverage.coverage |
|
3836 | 3836 | |
|
3837 | 3837 | vlog('# Producing coverage report') |
|
3838 | 3838 | # chdir is the easiest way to get short, relative paths in the |
|
3839 | 3839 | # output. |
|
3840 | 3840 | os.chdir(self._hgroot) |
|
3841 | 3841 | covdir = os.path.join(_bytes2sys(self._installdir), '..', 'coverage') |
|
3842 | 3842 | cov = coverage(data_file=os.path.join(covdir, 'cov')) |
|
3843 | 3843 | |
|
3844 | 3844 | # Map install directory paths back to source directory. |
|
3845 | 3845 | cov.config.paths['srcdir'] = ['.', _bytes2sys(self._pythondir)] |
|
3846 | 3846 | |
|
3847 | 3847 | cov.combine() |
|
3848 | 3848 | |
|
3849 | 3849 | omit = [ |
|
3850 | 3850 | _bytes2sys(os.path.join(x, b'*')) |
|
3851 | 3851 | for x in [self._bindir, self._testdir] |
|
3852 | 3852 | ] |
|
3853 | 3853 | cov.report(ignore_errors=True, omit=omit) |
|
3854 | 3854 | |
|
3855 | 3855 | if self.options.htmlcov: |
|
3856 | 3856 | htmldir = os.path.join(_bytes2sys(self._outputdir), 'htmlcov') |
|
3857 | 3857 | cov.html_report(directory=htmldir, omit=omit) |
|
3858 | 3858 | if self.options.annotate: |
|
3859 | 3859 | adir = os.path.join(_bytes2sys(self._outputdir), 'annotated') |
|
3860 | 3860 | if not os.path.isdir(adir): |
|
3861 | 3861 | os.mkdir(adir) |
|
3862 | 3862 | cov.annotate(directory=adir, omit=omit) |
|
3863 | 3863 | |
|
3864 | 3864 | def _findprogram(self, program): |
|
3865 | 3865 | """Search PATH for a executable program""" |
|
3866 | 3866 | dpb = _sys2bytes(os.defpath) |
|
3867 | 3867 | sepb = _sys2bytes(os.pathsep) |
|
3868 | 3868 | for p in osenvironb.get(b'PATH', dpb).split(sepb): |
|
3869 | 3869 | name = os.path.join(p, program) |
|
3870 | 3870 | if WINDOWS or os.access(name, os.X_OK): |
|
3871 | 3871 | return _bytes2sys(name) |
|
3872 | 3872 | return None |
|
3873 | 3873 | |
|
3874 | 3874 | def _checktools(self): |
|
3875 | 3875 | """Ensure tools required to run tests are present.""" |
|
3876 | 3876 | for p in self.REQUIREDTOOLS: |
|
3877 | 3877 | if WINDOWS and not p.endswith(b'.exe'): |
|
3878 | 3878 | p += b'.exe' |
|
3879 | 3879 | found = self._findprogram(p) |
|
3880 | 3880 | p = p.decode("utf-8") |
|
3881 | 3881 | if found: |
|
3882 | 3882 | vlog("# Found prerequisite", p, "at", found) |
|
3883 | 3883 | else: |
|
3884 | 3884 | print("WARNING: Did not find prerequisite tool: %s " % p) |
|
3885 | 3885 | |
|
3886 | 3886 | |
|
3887 | 3887 | def aggregateexceptions(path): |
|
3888 | 3888 | exceptioncounts = collections.Counter() |
|
3889 | 3889 | testsbyfailure = collections.defaultdict(set) |
|
3890 | 3890 | failuresbytest = collections.defaultdict(set) |
|
3891 | 3891 | |
|
3892 | 3892 | for f in os.listdir(path): |
|
3893 | 3893 | with open(os.path.join(path, f), 'rb') as fh: |
|
3894 | 3894 | data = fh.read().split(b'\0') |
|
3895 | 3895 | if len(data) != 5: |
|
3896 | 3896 | continue |
|
3897 | 3897 | |
|
3898 | 3898 | exc, mainframe, hgframe, hgline, testname = data |
|
3899 | 3899 | exc = exc.decode('utf-8') |
|
3900 | 3900 | mainframe = mainframe.decode('utf-8') |
|
3901 | 3901 | hgframe = hgframe.decode('utf-8') |
|
3902 | 3902 | hgline = hgline.decode('utf-8') |
|
3903 | 3903 | testname = testname.decode('utf-8') |
|
3904 | 3904 | |
|
3905 | 3905 | key = (hgframe, hgline, exc) |
|
3906 | 3906 | exceptioncounts[key] += 1 |
|
3907 | 3907 | testsbyfailure[key].add(testname) |
|
3908 | 3908 | failuresbytest[testname].add(key) |
|
3909 | 3909 | |
|
3910 | 3910 | # Find test having fewest failures for each failure. |
|
3911 | 3911 | leastfailing = {} |
|
3912 | 3912 | for key, tests in testsbyfailure.items(): |
|
3913 | 3913 | fewesttest = None |
|
3914 | 3914 | fewestcount = 99999999 |
|
3915 | 3915 | for test in sorted(tests): |
|
3916 | 3916 | if len(failuresbytest[test]) < fewestcount: |
|
3917 | 3917 | fewesttest = test |
|
3918 | 3918 | fewestcount = len(failuresbytest[test]) |
|
3919 | 3919 | |
|
3920 | 3920 | leastfailing[key] = (fewestcount, fewesttest) |
|
3921 | 3921 | |
|
3922 | 3922 | # Create a combined counter so we can sort by total occurrences and |
|
3923 | 3923 | # impacted tests. |
|
3924 | 3924 | combined = {} |
|
3925 | 3925 | for key in exceptioncounts: |
|
3926 | 3926 | combined[key] = ( |
|
3927 | 3927 | exceptioncounts[key], |
|
3928 | 3928 | len(testsbyfailure[key]), |
|
3929 | 3929 | leastfailing[key][0], |
|
3930 | 3930 | leastfailing[key][1], |
|
3931 | 3931 | ) |
|
3932 | 3932 | |
|
3933 | 3933 | return { |
|
3934 | 3934 | 'exceptioncounts': exceptioncounts, |
|
3935 | 3935 | 'total': sum(exceptioncounts.values()), |
|
3936 | 3936 | 'combined': combined, |
|
3937 | 3937 | 'leastfailing': leastfailing, |
|
3938 | 3938 | 'byfailure': testsbyfailure, |
|
3939 | 3939 | 'bytest': failuresbytest, |
|
3940 | 3940 | } |
|
3941 | 3941 | |
|
3942 | 3942 | |
|
3943 | 3943 | if __name__ == '__main__': |
|
3944 | 3944 | runner = TestRunner() |
|
3945 | 3945 | |
|
3946 | 3946 | try: |
|
3947 | 3947 | import msvcrt |
|
3948 | 3948 | |
|
3949 | 3949 | msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
|
3950 | 3950 | msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
|
3951 | 3951 | msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) |
|
3952 | 3952 | except ImportError: |
|
3953 | 3953 | pass |
|
3954 | 3954 | |
|
3955 | 3955 | sys.exit(runner.run(sys.argv[1:])) |
@@ -1,46 +1,46 | |||
|
1 | 1 | $ . "$TESTDIR/helpers-testrepo.sh" |
|
2 | 2 | |
|
3 | 3 | Testing that hghave does not crash when checking features |
|
4 | 4 | |
|
5 | 5 | $ hghave --test-features 2>/dev/null |
|
6 | 6 | |
|
7 | 7 | Testing hghave extensibility for third party tools |
|
8 | 8 | |
|
9 | 9 | $ cat > hghaveaddon.py <<EOF |
|
10 | 10 | > import hghave |
|
11 | 11 | > @hghave.check("custom", "custom hghave feature") |
|
12 | 12 | > def has_custom(): |
|
13 | 13 | > return True |
|
14 | 14 | > EOF |
|
15 | 15 | |
|
16 | 16 | (invocation via run-tests.py) |
|
17 | 17 | |
|
18 | 18 | $ cat > test-hghaveaddon.t <<EOF |
|
19 | 19 | > #require custom |
|
20 | 20 | > $ echo foo |
|
21 | 21 | > foo |
|
22 | 22 | > EOF |
|
23 | 23 | $ ( \ |
|
24 | 24 | > testrepohgenv; \ |
|
25 |
> "$PYTHON" $TESTDIR/run-tests.py --with-hg= |
|
|
25 | > "$PYTHON" $TESTDIR/run-tests.py --with-hg=$HGTEST_REAL_HG -j 1 \ | |
|
26 | 26 | > $HGTEST_RUN_TESTS_PURE test-hghaveaddon.t \ |
|
27 | 27 | > ) |
|
28 | 28 | running 1 tests using 1 parallel processes |
|
29 | 29 | . |
|
30 | 30 | # Ran 1 tests, 0 skipped, 0 failed. |
|
31 | 31 | |
|
32 | 32 | (invocation via command line) |
|
33 | 33 | |
|
34 | 34 | $ unset TESTDIR |
|
35 | 35 | $ hghave custom |
|
36 | 36 | |
|
37 | 37 | (terminate with exit code 2 at failure of importing hghaveaddon.py) |
|
38 | 38 | |
|
39 | 39 | $ rm hghaveaddon.* |
|
40 | 40 | $ cat > hghaveaddon.py <<NO_CHECK_EOF |
|
41 | 41 | > importing this file should cause syntax error |
|
42 | 42 | > NO_CHECK_EOF |
|
43 | 43 | |
|
44 | 44 | $ hghave custom |
|
45 | 45 | failed to import hghaveaddon.py from '.': invalid syntax (hghaveaddon.py, line 1) |
|
46 | 46 | [2] |
@@ -1,2087 +1,2087 | |||
|
1 | 1 | This file tests the behavior of run-tests.py itself. |
|
2 | 2 | |
|
3 | 3 | Avoid interference from actual test env: |
|
4 | 4 | |
|
5 | 5 | $ . "$TESTDIR/helper-runtests.sh" |
|
6 | 6 | |
|
7 | 7 | Smoke test with install |
|
8 | 8 | ============ |
|
9 | 9 | $ "$PYTHON" $TESTDIR/run-tests.py $HGTEST_RUN_TESTS_PURE -l |
|
10 | 10 | running 0 tests using 0 parallel processes |
|
11 | 11 | |
|
12 | 12 | # Ran 0 tests, 0 skipped, 0 failed. |
|
13 | 13 | |
|
14 | 14 | Define a helper to avoid the install step |
|
15 | 15 | ============= |
|
16 | 16 | $ rt() |
|
17 | 17 | > { |
|
18 |
> "$PYTHON" $TESTDIR/run-tests.py --with-hg= |
|
|
18 | > "$PYTHON" $TESTDIR/run-tests.py --with-hg=$HGTEST_REAL_HG -j1 "$@" | |
|
19 | 19 | > } |
|
20 | 20 | |
|
21 | 21 | error paths |
|
22 | 22 | |
|
23 | 23 | #if symlink |
|
24 | 24 | $ ln -s `which true` hg |
|
25 | 25 | $ "$PYTHON" $TESTDIR/run-tests.py --with-hg=./hg |
|
26 | 26 | warning: --with-hg should specify an hg script, not: true |
|
27 | 27 | running 0 tests using 0 parallel processes |
|
28 | 28 | |
|
29 | 29 | # Ran 0 tests, 0 skipped, 0 failed. |
|
30 | 30 | $ rm hg |
|
31 | 31 | #endif |
|
32 | 32 | |
|
33 | 33 | #if execbit |
|
34 | 34 | $ touch hg |
|
35 | 35 | $ "$PYTHON" $TESTDIR/run-tests.py --with-hg=./hg |
|
36 | 36 | usage: run-tests.py [options] [tests] |
|
37 | 37 | run-tests.py: error: --with-hg must specify an executable hg script |
|
38 | 38 | [2] |
|
39 | 39 | $ rm hg |
|
40 | 40 | #endif |
|
41 | 41 | |
|
42 | 42 | Features for testing optional lines |
|
43 | 43 | =================================== |
|
44 | 44 | |
|
45 | 45 | $ cat > hghaveaddon.py <<EOF |
|
46 | 46 | > import hghave |
|
47 | 47 | > @hghave.check("custom", "custom hghave feature") |
|
48 | 48 | > def has_custom(): |
|
49 | 49 | > return True |
|
50 | 50 | > @hghave.check("missing", "missing hghave feature") |
|
51 | 51 | > def has_missing(): |
|
52 | 52 | > return False |
|
53 | 53 | > EOF |
|
54 | 54 | |
|
55 | 55 | an empty test |
|
56 | 56 | ======================= |
|
57 | 57 | |
|
58 | 58 | $ touch test-empty.t |
|
59 | 59 | $ rt |
|
60 | 60 | running 1 tests using 1 parallel processes |
|
61 | 61 | . |
|
62 | 62 | # Ran 1 tests, 0 skipped, 0 failed. |
|
63 | 63 | $ rm test-empty.t |
|
64 | 64 | |
|
65 | 65 | a succesful test |
|
66 | 66 | ======================= |
|
67 | 67 | |
|
68 | 68 | $ cat > test-success.t << EOF |
|
69 | 69 | > $ echo babar |
|
70 | 70 | > babar |
|
71 | 71 | > $ echo xyzzy |
|
72 | 72 | > dont_print (?) |
|
73 | 73 | > nothing[42]line (re) (?) |
|
74 | 74 | > never*happens (glob) (?) |
|
75 | 75 | > more_nothing (?) |
|
76 | 76 | > xyzzy |
|
77 | 77 | > nor this (?) |
|
78 | 78 | > $ printf 'abc\ndef\nxyz\n' |
|
79 | 79 | > 123 (?) |
|
80 | 80 | > abc |
|
81 | 81 | > def (?) |
|
82 | 82 | > 456 (?) |
|
83 | 83 | > xyz |
|
84 | 84 | > $ printf 'zyx\nwvu\ntsr\n' |
|
85 | 85 | > abc (?) |
|
86 | 86 | > zyx (custom !) |
|
87 | 87 | > wvu |
|
88 | 88 | > no_print (no-custom !) |
|
89 | 89 | > tsr (no-missing !) |
|
90 | 90 | > missing (missing !) |
|
91 | 91 | > EOF |
|
92 | 92 | |
|
93 | 93 | $ rt |
|
94 | 94 | running 1 tests using 1 parallel processes |
|
95 | 95 | . |
|
96 | 96 | # Ran 1 tests, 0 skipped, 0 failed. |
|
97 | 97 | |
|
98 | 98 | failing test |
|
99 | 99 | ================== |
|
100 | 100 | |
|
101 | 101 | test churn with globs |
|
102 | 102 | $ cat > test-failure.t <<EOF |
|
103 | 103 | > $ echo "bar-baz"; echo "bar-bad"; echo foo |
|
104 | 104 | > bar*bad (glob) |
|
105 | 105 | > bar*baz (glob) |
|
106 | 106 | > | fo (re) |
|
107 | 107 | > EOF |
|
108 | 108 | $ rt test-failure.t |
|
109 | 109 | running 1 tests using 1 parallel processes |
|
110 | 110 | |
|
111 | 111 | --- $TESTTMP/test-failure.t |
|
112 | 112 | +++ $TESTTMP/test-failure.t.err |
|
113 | 113 | @@ -1,4 +1,4 @@ |
|
114 | 114 | $ echo "bar-baz"; echo "bar-bad"; echo foo |
|
115 | 115 | + bar*baz (glob) |
|
116 | 116 | bar*bad (glob) |
|
117 | 117 | - bar*baz (glob) |
|
118 | 118 | - | fo (re) |
|
119 | 119 | + foo |
|
120 | 120 | |
|
121 | 121 | ERROR: test-failure.t output changed |
|
122 | 122 | ! |
|
123 | 123 | Failed test-failure.t: output changed |
|
124 | 124 | # Ran 1 tests, 0 skipped, 1 failed. |
|
125 | 125 | python hash seed: * (glob) |
|
126 | 126 | [1] |
|
127 | 127 | |
|
128 | 128 | test how multiple globs gets matched with lines in output |
|
129 | 129 | $ cat > test-failure-globs.t <<EOF |
|
130 | 130 | > $ echo "context"; echo "context"; \ |
|
131 | 131 | > echo "key: 1"; echo "value: not a"; \ |
|
132 | 132 | > echo "key: 2"; echo "value: not b"; \ |
|
133 | 133 | > echo "key: 3"; echo "value: c"; \ |
|
134 | 134 | > echo "key: 4"; echo "value: d" |
|
135 | 135 | > context |
|
136 | 136 | > context |
|
137 | 137 | > key: 1 |
|
138 | 138 | > value: a |
|
139 | 139 | > key: 2 |
|
140 | 140 | > value: b |
|
141 | 141 | > key: 3 |
|
142 | 142 | > value: * (glob) |
|
143 | 143 | > key: 4 |
|
144 | 144 | > value: * (glob) |
|
145 | 145 | > EOF |
|
146 | 146 | $ rt test-failure-globs.t |
|
147 | 147 | running 1 tests using 1 parallel processes |
|
148 | 148 | |
|
149 | 149 | --- $TESTTMP/test-failure-globs.t |
|
150 | 150 | +++ $TESTTMP/test-failure-globs.t.err |
|
151 | 151 | @@ -2,9 +2,9 @@ |
|
152 | 152 | context |
|
153 | 153 | context |
|
154 | 154 | key: 1 |
|
155 | 155 | - value: a |
|
156 | 156 | + value: not a |
|
157 | 157 | key: 2 |
|
158 | 158 | - value: b |
|
159 | 159 | + value: not b |
|
160 | 160 | key: 3 |
|
161 | 161 | value: * (glob) |
|
162 | 162 | key: 4 |
|
163 | 163 | |
|
164 | 164 | ERROR: test-failure-globs.t output changed |
|
165 | 165 | ! |
|
166 | 166 | Failed test-failure-globs.t: output changed |
|
167 | 167 | # Ran 1 tests, 0 skipped, 1 failed. |
|
168 | 168 | python hash seed: * (glob) |
|
169 | 169 | [1] |
|
170 | 170 | $ rm test-failure-globs.t |
|
171 | 171 | |
|
172 | 172 | test diff colorisation |
|
173 | 173 | |
|
174 | 174 | #if no-windows pygments |
|
175 | 175 | $ rt test-failure.t --color always |
|
176 | 176 | running 1 tests using 1 parallel processes |
|
177 | 177 | |
|
178 | 178 | \x1b[38;5;124m--- $TESTTMP/test-failure.t\x1b[39m (esc) |
|
179 | 179 | \x1b[38;5;34m+++ $TESTTMP/test-failure.t.err\x1b[39m (esc) |
|
180 | 180 | \x1b[38;5;90;01m@@ -1,4 +1,4 @@\x1b[39;00m (esc) |
|
181 | 181 | $ echo "bar-baz"; echo "bar-bad"; echo foo |
|
182 | 182 | \x1b[38;5;34m+ bar*baz (glob)\x1b[39m (esc) |
|
183 | 183 | bar*bad (glob) |
|
184 | 184 | \x1b[38;5;124m- bar*baz (glob)\x1b[39m (esc) |
|
185 | 185 | \x1b[38;5;124m- | fo (re)\x1b[39m (esc) |
|
186 | 186 | \x1b[38;5;34m+ foo\x1b[39m (esc) |
|
187 | 187 | |
|
188 | 188 | \x1b[38;5;88mERROR: \x1b[39m\x1b[38;5;9mtest-failure.t\x1b[39m\x1b[38;5;88m output changed\x1b[39m (esc) |
|
189 | 189 | ! |
|
190 | 190 | \x1b[38;5;88mFailed \x1b[39m\x1b[38;5;9mtest-failure.t\x1b[39m\x1b[38;5;88m: output changed\x1b[39m (esc) |
|
191 | 191 | # Ran 1 tests, 0 skipped, 1 failed. |
|
192 | 192 | python hash seed: * (glob) |
|
193 | 193 | [1] |
|
194 | 194 | |
|
195 | 195 | $ rt test-failure.t 2> tmp.log |
|
196 | 196 | running 1 tests using 1 parallel processes |
|
197 | 197 | [1] |
|
198 | 198 | $ cat tmp.log |
|
199 | 199 | |
|
200 | 200 | --- $TESTTMP/test-failure.t |
|
201 | 201 | +++ $TESTTMP/test-failure.t.err |
|
202 | 202 | @@ -1,4 +1,4 @@ |
|
203 | 203 | $ echo "bar-baz"; echo "bar-bad"; echo foo |
|
204 | 204 | + bar*baz (glob) |
|
205 | 205 | bar*bad (glob) |
|
206 | 206 | - bar*baz (glob) |
|
207 | 207 | - | fo (re) |
|
208 | 208 | + foo |
|
209 | 209 | |
|
210 | 210 | ERROR: test-failure.t output changed |
|
211 | 211 | ! |
|
212 | 212 | Failed test-failure.t: output changed |
|
213 | 213 | # Ran 1 tests, 0 skipped, 1 failed. |
|
214 | 214 | python hash seed: * (glob) |
|
215 | 215 | #endif |
|
216 | 216 | |
|
217 | 217 | $ cat > test-failure.t << EOF |
|
218 | 218 | > $ true |
|
219 | 219 | > should go away (true !) |
|
220 | 220 | > $ true |
|
221 | 221 | > should stay (false !) |
|
222 | 222 | > |
|
223 | 223 | > Should remove first line, not second or third |
|
224 | 224 | > $ echo 'testing' |
|
225 | 225 | > baz*foo (glob) (true !) |
|
226 | 226 | > foobar*foo (glob) (false !) |
|
227 | 227 | > te*ting (glob) (true !) |
|
228 | 228 | > |
|
229 | 229 | > Should keep first two lines, remove third and last |
|
230 | 230 | > $ echo 'testing' |
|
231 | 231 | > test.ng (re) (true !) |
|
232 | 232 | > foo.ar (re) (false !) |
|
233 | 233 | > b.r (re) (true !) |
|
234 | 234 | > missing (?) |
|
235 | 235 | > awol (true !) |
|
236 | 236 | > |
|
237 | 237 | > The "missing" line should stay, even though awol is dropped |
|
238 | 238 | > $ echo 'testing' |
|
239 | 239 | > test.ng (re) (true !) |
|
240 | 240 | > foo.ar (?) |
|
241 | 241 | > awol |
|
242 | 242 | > missing (?) |
|
243 | 243 | > EOF |
|
244 | 244 | $ rt test-failure.t |
|
245 | 245 | running 1 tests using 1 parallel processes |
|
246 | 246 | |
|
247 | 247 | --- $TESTTMP/test-failure.t |
|
248 | 248 | +++ $TESTTMP/test-failure.t.err |
|
249 | 249 | @@ -1,11 +1,9 @@ |
|
250 | 250 | $ true |
|
251 | 251 | - should go away (true !) |
|
252 | 252 | $ true |
|
253 | 253 | should stay (false !) |
|
254 | 254 | |
|
255 | 255 | Should remove first line, not second or third |
|
256 | 256 | $ echo 'testing' |
|
257 | 257 | - baz*foo (glob) (true !) |
|
258 | 258 | foobar*foo (glob) (false !) |
|
259 | 259 | te*ting (glob) (true !) |
|
260 | 260 | |
|
261 | 261 | foo.ar (re) (false !) |
|
262 | 262 | missing (?) |
|
263 | 263 | @@ -13,13 +11,10 @@ |
|
264 | 264 | $ echo 'testing' |
|
265 | 265 | test.ng (re) (true !) |
|
266 | 266 | foo.ar (re) (false !) |
|
267 | 267 | - b.r (re) (true !) |
|
268 | 268 | missing (?) |
|
269 | 269 | - awol (true !) |
|
270 | 270 | |
|
271 | 271 | The "missing" line should stay, even though awol is dropped |
|
272 | 272 | $ echo 'testing' |
|
273 | 273 | test.ng (re) (true !) |
|
274 | 274 | foo.ar (?) |
|
275 | 275 | - awol |
|
276 | 276 | missing (?) |
|
277 | 277 | |
|
278 | 278 | ERROR: test-failure.t output changed |
|
279 | 279 | ! |
|
280 | 280 | Failed test-failure.t: output changed |
|
281 | 281 | # Ran 1 tests, 0 skipped, 1 failed. |
|
282 | 282 | python hash seed: * (glob) |
|
283 | 283 | [1] |
|
284 | 284 | |
|
285 | 285 | basic failing test |
|
286 | 286 | $ cat > test-failure.t << EOF |
|
287 | 287 | > $ echo babar |
|
288 | 288 | > rataxes |
|
289 | 289 | > This is a noop statement so that |
|
290 | 290 | > this test is still more bytes than success. |
|
291 | 291 | > pad pad pad pad............................................................ |
|
292 | 292 | > pad pad pad pad............................................................ |
|
293 | 293 | > pad pad pad pad............................................................ |
|
294 | 294 | > pad pad pad pad............................................................ |
|
295 | 295 | > pad pad pad pad............................................................ |
|
296 | 296 | > pad pad pad pad............................................................ |
|
297 | 297 | > EOF |
|
298 | 298 | |
|
299 | 299 | >>> fh = open('test-failure-unicode.t', 'wb') |
|
300 | 300 | >>> fh.write(u' $ echo babar\u03b1\n'.encode('utf-8')) and None |
|
301 | 301 | >>> fh.write(u' l\u03b5\u03b5t\n'.encode('utf-8')) and None |
|
302 | 302 | |
|
303 | 303 | $ rt |
|
304 | 304 | running 3 tests using 1 parallel processes |
|
305 | 305 | |
|
306 | 306 | --- $TESTTMP/test-failure.t |
|
307 | 307 | +++ $TESTTMP/test-failure.t.err |
|
308 | 308 | @@ -1,5 +1,5 @@ |
|
309 | 309 | $ echo babar |
|
310 | 310 | - rataxes |
|
311 | 311 | + babar |
|
312 | 312 | This is a noop statement so that |
|
313 | 313 | this test is still more bytes than success. |
|
314 | 314 | pad pad pad pad............................................................ |
|
315 | 315 | |
|
316 | 316 | ERROR: test-failure.t output changed |
|
317 | 317 | !. |
|
318 | 318 | --- $TESTTMP/test-failure-unicode.t |
|
319 | 319 | +++ $TESTTMP/test-failure-unicode.t.err |
|
320 | 320 | @@ -1,2 +1,2 @@ |
|
321 | 321 | $ echo babar\xce\xb1 (esc) |
|
322 | 322 | - l\xce\xb5\xce\xb5t (esc) |
|
323 | 323 | + babar\xce\xb1 (esc) |
|
324 | 324 | |
|
325 | 325 | ERROR: test-failure-unicode.t output changed |
|
326 | 326 | ! |
|
327 | 327 | Failed test-failure-unicode.t: output changed |
|
328 | 328 | Failed test-failure.t: output changed |
|
329 | 329 | # Ran 3 tests, 0 skipped, 2 failed. |
|
330 | 330 | python hash seed: * (glob) |
|
331 | 331 | [1] |
|
332 | 332 | |
|
333 | 333 | test --outputdir |
|
334 | 334 | $ mkdir output |
|
335 | 335 | $ rt --outputdir output |
|
336 | 336 | running 3 tests using 1 parallel processes |
|
337 | 337 | |
|
338 | 338 | --- $TESTTMP/test-failure.t |
|
339 | 339 | +++ $TESTTMP/output/test-failure.t.err |
|
340 | 340 | @@ -1,5 +1,5 @@ |
|
341 | 341 | $ echo babar |
|
342 | 342 | - rataxes |
|
343 | 343 | + babar |
|
344 | 344 | This is a noop statement so that |
|
345 | 345 | this test is still more bytes than success. |
|
346 | 346 | pad pad pad pad............................................................ |
|
347 | 347 | |
|
348 | 348 | ERROR: test-failure.t output changed |
|
349 | 349 | !. |
|
350 | 350 | --- $TESTTMP/test-failure-unicode.t |
|
351 | 351 | +++ $TESTTMP/output/test-failure-unicode.t.err |
|
352 | 352 | @@ -1,2 +1,2 @@ |
|
353 | 353 | $ echo babar\xce\xb1 (esc) |
|
354 | 354 | - l\xce\xb5\xce\xb5t (esc) |
|
355 | 355 | + babar\xce\xb1 (esc) |
|
356 | 356 | |
|
357 | 357 | ERROR: test-failure-unicode.t output changed |
|
358 | 358 | ! |
|
359 | 359 | Failed test-failure-unicode.t: output changed |
|
360 | 360 | Failed test-failure.t: output changed |
|
361 | 361 | # Ran 3 tests, 0 skipped, 2 failed. |
|
362 | 362 | python hash seed: * (glob) |
|
363 | 363 | [1] |
|
364 | 364 | $ ls -a output |
|
365 | 365 | . |
|
366 | 366 | .. |
|
367 | 367 | .testtimes |
|
368 | 368 | test-failure-unicode.t.err |
|
369 | 369 | test-failure.t.err |
|
370 | 370 | |
|
371 | 371 | test --xunit support |
|
372 | 372 | $ rt --xunit=xunit.xml |
|
373 | 373 | running 3 tests using 1 parallel processes |
|
374 | 374 | |
|
375 | 375 | --- $TESTTMP/test-failure.t |
|
376 | 376 | +++ $TESTTMP/test-failure.t.err |
|
377 | 377 | @@ -1,5 +1,5 @@ |
|
378 | 378 | $ echo babar |
|
379 | 379 | - rataxes |
|
380 | 380 | + babar |
|
381 | 381 | This is a noop statement so that |
|
382 | 382 | this test is still more bytes than success. |
|
383 | 383 | pad pad pad pad............................................................ |
|
384 | 384 | |
|
385 | 385 | ERROR: test-failure.t output changed |
|
386 | 386 | !. |
|
387 | 387 | --- $TESTTMP/test-failure-unicode.t |
|
388 | 388 | +++ $TESTTMP/test-failure-unicode.t.err |
|
389 | 389 | @@ -1,2 +1,2 @@ |
|
390 | 390 | $ echo babar\xce\xb1 (esc) |
|
391 | 391 | - l\xce\xb5\xce\xb5t (esc) |
|
392 | 392 | + babar\xce\xb1 (esc) |
|
393 | 393 | |
|
394 | 394 | ERROR: test-failure-unicode.t output changed |
|
395 | 395 | ! |
|
396 | 396 | Failed test-failure-unicode.t: output changed |
|
397 | 397 | Failed test-failure.t: output changed |
|
398 | 398 | # Ran 3 tests, 0 skipped, 2 failed. |
|
399 | 399 | python hash seed: * (glob) |
|
400 | 400 | [1] |
|
401 | 401 | $ cat xunit.xml |
|
402 | 402 | <?xml version="1.0" encoding="utf-8"?> |
|
403 | 403 | <testsuite errors="0" failures="2" name="run-tests" skipped="0" tests="3"> |
|
404 | 404 | <testcase name="test-success.t" time="*"/> (glob) |
|
405 | 405 | <testcase name="test-failure-unicode.t" time="*"> (glob) |
|
406 | 406 | <failure message="output changed" type="output-mismatch"><![CDATA[--- $TESTTMP/test-failure-unicode.t (py38 !) |
|
407 | 407 | <failure message="output changed" type="output-mismatch"> (no-py38 !) |
|
408 | 408 | <![CDATA[--- $TESTTMP/test-failure-unicode.t (no-py38 !) |
|
409 | 409 | +++ $TESTTMP/test-failure-unicode.t.err |
|
410 | 410 | @@ -1,2 +1,2 @@ |
|
411 | 411 | $ echo babar\xce\xb1 (esc) |
|
412 | 412 | - l\xce\xb5\xce\xb5t (esc) |
|
413 | 413 | + babar\xce\xb1 (esc) |
|
414 | 414 | ]]></failure> (py38 !) |
|
415 | 415 | ]]> </failure> (no-py38 !) |
|
416 | 416 | </testcase> |
|
417 | 417 | <testcase name="test-failure.t" time="*"> (glob) |
|
418 | 418 | <failure message="output changed" type="output-mismatch"><![CDATA[--- $TESTTMP/test-failure.t (py38 !) |
|
419 | 419 | <failure message="output changed" type="output-mismatch"> (no-py38 !) |
|
420 | 420 | <![CDATA[--- $TESTTMP/test-failure.t (no-py38 !) |
|
421 | 421 | +++ $TESTTMP/test-failure.t.err |
|
422 | 422 | @@ -1,5 +1,5 @@ |
|
423 | 423 | $ echo babar |
|
424 | 424 | - rataxes |
|
425 | 425 | + babar |
|
426 | 426 | This is a noop statement so that |
|
427 | 427 | this test is still more bytes than success. |
|
428 | 428 | pad pad pad pad............................................................ |
|
429 | 429 | ]]></failure> (py38 !) |
|
430 | 430 | ]]> </failure> (no-py38 !) |
|
431 | 431 | </testcase> |
|
432 | 432 | </testsuite> |
|
433 | 433 | |
|
434 | 434 | $ cat .testtimes |
|
435 | 435 | test-empty.t * (glob) |
|
436 | 436 | test-failure-globs.t * (glob) |
|
437 | 437 | test-failure-unicode.t * (glob) |
|
438 | 438 | test-failure.t * (glob) |
|
439 | 439 | test-success.t * (glob) |
|
440 | 440 | |
|
441 | 441 | $ rt --list-tests |
|
442 | 442 | test-failure-unicode.t |
|
443 | 443 | test-failure.t |
|
444 | 444 | test-success.t |
|
445 | 445 | |
|
446 | 446 | $ rt --list-tests --json |
|
447 | 447 | test-failure-unicode.t |
|
448 | 448 | test-failure.t |
|
449 | 449 | test-success.t |
|
450 | 450 | $ cat report.json |
|
451 | 451 | testreport ={ |
|
452 | 452 | "test-failure-unicode.t": { |
|
453 | 453 | "result": "success" |
|
454 | 454 | }, |
|
455 | 455 | "test-failure.t": { |
|
456 | 456 | "result": "success" |
|
457 | 457 | }, |
|
458 | 458 | "test-success.t": { |
|
459 | 459 | "result": "success" |
|
460 | 460 | } |
|
461 | 461 | } (no-eol) |
|
462 | 462 | |
|
463 | 463 | $ rt --list-tests --xunit=xunit.xml |
|
464 | 464 | test-failure-unicode.t |
|
465 | 465 | test-failure.t |
|
466 | 466 | test-success.t |
|
467 | 467 | $ cat xunit.xml |
|
468 | 468 | <?xml version="1.0" encoding="utf-8"?> |
|
469 | 469 | <testsuite errors="0" failures="0" name="run-tests" skipped="0" tests="0"> |
|
470 | 470 | <testcase name="test-failure-unicode.t"/> |
|
471 | 471 | <testcase name="test-failure.t"/> |
|
472 | 472 | <testcase name="test-success.t"/> |
|
473 | 473 | </testsuite> |
|
474 | 474 | |
|
475 | 475 | $ rt --list-tests test-failure* --json --xunit=xunit.xml --outputdir output |
|
476 | 476 | test-failure-unicode.t |
|
477 | 477 | test-failure.t |
|
478 | 478 | $ cat output/report.json |
|
479 | 479 | testreport ={ |
|
480 | 480 | "test-failure-unicode.t": { |
|
481 | 481 | "result": "success" |
|
482 | 482 | }, |
|
483 | 483 | "test-failure.t": { |
|
484 | 484 | "result": "success" |
|
485 | 485 | } |
|
486 | 486 | } (no-eol) |
|
487 | 487 | $ cat xunit.xml |
|
488 | 488 | <?xml version="1.0" encoding="utf-8"?> |
|
489 | 489 | <testsuite errors="0" failures="0" name="run-tests" skipped="0" tests="0"> |
|
490 | 490 | <testcase name="test-failure-unicode.t"/> |
|
491 | 491 | <testcase name="test-failure.t"/> |
|
492 | 492 | </testsuite> |
|
493 | 493 | |
|
494 | 494 | $ rm test-failure-unicode.t |
|
495 | 495 | |
|
496 | 496 | test for --retest |
|
497 | 497 | ==================== |
|
498 | 498 | |
|
499 | 499 | $ rt --retest |
|
500 | 500 | running 1 tests using 1 parallel processes |
|
501 | 501 | |
|
502 | 502 | --- $TESTTMP/test-failure.t |
|
503 | 503 | +++ $TESTTMP/test-failure.t.err |
|
504 | 504 | @@ -1,5 +1,5 @@ |
|
505 | 505 | $ echo babar |
|
506 | 506 | - rataxes |
|
507 | 507 | + babar |
|
508 | 508 | This is a noop statement so that |
|
509 | 509 | this test is still more bytes than success. |
|
510 | 510 | pad pad pad pad............................................................ |
|
511 | 511 | |
|
512 | 512 | ERROR: test-failure.t output changed |
|
513 | 513 | ! |
|
514 | 514 | Failed test-failure.t: output changed |
|
515 | 515 | # Ran 1 tests, 0 skipped, 1 failed. |
|
516 | 516 | python hash seed: * (glob) |
|
517 | 517 | [1] |
|
518 | 518 | |
|
519 | 519 | --retest works with --outputdir |
|
520 | 520 | $ rm -r output |
|
521 | 521 | $ mkdir output |
|
522 | 522 | $ mv test-failure.t.err output |
|
523 | 523 | $ rt --retest --outputdir output |
|
524 | 524 | running 1 tests using 1 parallel processes |
|
525 | 525 | |
|
526 | 526 | --- $TESTTMP/test-failure.t |
|
527 | 527 | +++ $TESTTMP/output/test-failure.t.err |
|
528 | 528 | @@ -1,5 +1,5 @@ |
|
529 | 529 | $ echo babar |
|
530 | 530 | - rataxes |
|
531 | 531 | + babar |
|
532 | 532 | This is a noop statement so that |
|
533 | 533 | this test is still more bytes than success. |
|
534 | 534 | pad pad pad pad............................................................ |
|
535 | 535 | |
|
536 | 536 | ERROR: test-failure.t output changed |
|
537 | 537 | ! |
|
538 | 538 | Failed test-failure.t: output changed |
|
539 | 539 | # Ran 1 tests, 0 skipped, 1 failed. |
|
540 | 540 | python hash seed: * (glob) |
|
541 | 541 | [1] |
|
542 | 542 | |
|
543 | 543 | Selecting Tests To Run |
|
544 | 544 | ====================== |
|
545 | 545 | |
|
546 | 546 | successful |
|
547 | 547 | |
|
548 | 548 | $ rt test-success.t |
|
549 | 549 | running 1 tests using 1 parallel processes |
|
550 | 550 | . |
|
551 | 551 | # Ran 1 tests, 0 skipped, 0 failed. |
|
552 | 552 | |
|
553 | 553 | success w/ keyword |
|
554 | 554 | $ rt -k xyzzy |
|
555 | 555 | running 2 tests using 1 parallel processes |
|
556 | 556 | . |
|
557 | 557 | # Ran 2 tests, 1 skipped, 0 failed. |
|
558 | 558 | |
|
559 | 559 | failed |
|
560 | 560 | |
|
561 | 561 | $ rt test-failure.t |
|
562 | 562 | running 1 tests using 1 parallel processes |
|
563 | 563 | |
|
564 | 564 | --- $TESTTMP/test-failure.t |
|
565 | 565 | +++ $TESTTMP/test-failure.t.err |
|
566 | 566 | @@ -1,5 +1,5 @@ |
|
567 | 567 | $ echo babar |
|
568 | 568 | - rataxes |
|
569 | 569 | + babar |
|
570 | 570 | This is a noop statement so that |
|
571 | 571 | this test is still more bytes than success. |
|
572 | 572 | pad pad pad pad............................................................ |
|
573 | 573 | |
|
574 | 574 | ERROR: test-failure.t output changed |
|
575 | 575 | ! |
|
576 | 576 | Failed test-failure.t: output changed |
|
577 | 577 | # Ran 1 tests, 0 skipped, 1 failed. |
|
578 | 578 | python hash seed: * (glob) |
|
579 | 579 | [1] |
|
580 | 580 | |
|
581 | 581 | failure w/ keyword |
|
582 | 582 | $ rt -k rataxes |
|
583 | 583 | running 2 tests using 1 parallel processes |
|
584 | 584 | |
|
585 | 585 | --- $TESTTMP/test-failure.t |
|
586 | 586 | +++ $TESTTMP/test-failure.t.err |
|
587 | 587 | @@ -1,5 +1,5 @@ |
|
588 | 588 | $ echo babar |
|
589 | 589 | - rataxes |
|
590 | 590 | + babar |
|
591 | 591 | This is a noop statement so that |
|
592 | 592 | this test is still more bytes than success. |
|
593 | 593 | pad pad pad pad............................................................ |
|
594 | 594 | |
|
595 | 595 | ERROR: test-failure.t output changed |
|
596 | 596 | ! |
|
597 | 597 | Failed test-failure.t: output changed |
|
598 | 598 | # Ran 2 tests, 1 skipped, 1 failed. |
|
599 | 599 | python hash seed: * (glob) |
|
600 | 600 | [1] |
|
601 | 601 | |
|
602 | 602 | Verify that when a process fails to start we show a useful message |
|
603 | 603 | ================================================================== |
|
604 | 604 | |
|
605 | 605 | $ cat > test-serve-fail.t <<EOF |
|
606 | 606 | > $ echo 'abort: child process failed to start blah' |
|
607 | 607 | > EOF |
|
608 | 608 | $ rt test-serve-fail.t |
|
609 | 609 | running 1 tests using 1 parallel processes |
|
610 | 610 | |
|
611 | 611 | --- $TESTTMP/test-serve-fail.t |
|
612 | 612 | +++ $TESTTMP/test-serve-fail.t.err |
|
613 | 613 | @@ -1* +1,2 @@ (glob) |
|
614 | 614 | $ echo 'abort: child process failed to start blah' |
|
615 | 615 | + abort: child process failed to start blah |
|
616 | 616 | |
|
617 | 617 | ERROR: test-serve-fail.t output changed |
|
618 | 618 | ! |
|
619 | 619 | Failed test-serve-fail.t: server failed to start (HGPORT=*) (glob) |
|
620 | 620 | # Ran 1 tests, 0 skipped, 1 failed. |
|
621 | 621 | python hash seed: * (glob) |
|
622 | 622 | [1] |
|
623 | 623 | $ rm test-serve-fail.t |
|
624 | 624 | |
|
625 | 625 | Verify that we can try other ports |
|
626 | 626 | =================================== |
|
627 | 627 | |
|
628 | 628 | Extensions aren't inherited by the invoked run-tests.py. An extension |
|
629 | 629 | introducing a repository requirement could cause this to fail. So we force |
|
630 | 630 | HGRCPATH to get a clean environment. |
|
631 | 631 | |
|
632 | 632 | $ HGRCPATH= hg init inuse |
|
633 | 633 | $ hg serve -R inuse -p $HGPORT -d --pid-file=blocks.pid |
|
634 | 634 | $ cat blocks.pid >> $DAEMON_PIDS |
|
635 | 635 | $ cat > test-serve-inuse.t <<EOF |
|
636 | 636 | > $ hg serve -R `pwd`/inuse -p \$HGPORT -d --pid-file=hg.pid |
|
637 | 637 | > $ cat hg.pid >> \$DAEMON_PIDS |
|
638 | 638 | > EOF |
|
639 | 639 | $ rt test-serve-inuse.t |
|
640 | 640 | running 1 tests using 1 parallel processes |
|
641 | 641 | . |
|
642 | 642 | # Ran 1 tests, 0 skipped, 0 failed. |
|
643 | 643 | $ rm test-serve-inuse.t |
|
644 | 644 | $ killdaemons.py $DAEMON_PIDS |
|
645 | 645 | |
|
646 | 646 | Running In Debug Mode |
|
647 | 647 | ====================== |
|
648 | 648 | |
|
649 | 649 | $ rt --debug 2>&1 | grep -v pwd |
|
650 | 650 | running 2 tests using 1 parallel processes |
|
651 | 651 | + alias hg=hg.exe (windows !) |
|
652 | 652 | + echo *SALT* 0 0 (glob) |
|
653 | 653 | *SALT* 0 0 (glob) |
|
654 | 654 | + echo babar |
|
655 | 655 | babar |
|
656 | 656 | + echo *SALT* 10 0 (glob) |
|
657 | 657 | *SALT* 10 0 (glob) |
|
658 | 658 | .+ alias hg=hg.exe (windows !) |
|
659 | 659 | *+ echo *SALT* 0 0 (glob) |
|
660 | 660 | *SALT* 0 0 (glob) |
|
661 | 661 | + echo babar |
|
662 | 662 | babar |
|
663 | 663 | + echo *SALT* 2 0 (glob) |
|
664 | 664 | *SALT* 2 0 (glob) |
|
665 | 665 | + echo xyzzy |
|
666 | 666 | xyzzy |
|
667 | 667 | + echo *SALT* 9 0 (glob) |
|
668 | 668 | *SALT* 9 0 (glob) |
|
669 | 669 | + printf *abc\ndef\nxyz\n* (glob) |
|
670 | 670 | abc |
|
671 | 671 | def |
|
672 | 672 | xyz |
|
673 | 673 | + echo *SALT* 15 0 (glob) |
|
674 | 674 | *SALT* 15 0 (glob) |
|
675 | 675 | + printf *zyx\nwvu\ntsr\n* (glob) |
|
676 | 676 | zyx |
|
677 | 677 | wvu |
|
678 | 678 | tsr |
|
679 | 679 | + echo *SALT* 22 0 (glob) |
|
680 | 680 | *SALT* 22 0 (glob) |
|
681 | 681 | . |
|
682 | 682 | # Ran 2 tests, 0 skipped, 0 failed. |
|
683 | 683 | |
|
684 | 684 | Parallel runs |
|
685 | 685 | ============== |
|
686 | 686 | |
|
687 | 687 | (duplicate the failing test to get predictable output) |
|
688 | 688 | $ cp test-failure.t test-failure-copy.t |
|
689 | 689 | |
|
690 | 690 | $ rt --jobs 2 test-failure*.t -n |
|
691 | 691 | running 2 tests using 2 parallel processes |
|
692 | 692 | !! |
|
693 | 693 | Failed test-failure*.t: output changed (glob) |
|
694 | 694 | Failed test-failure*.t: output changed (glob) |
|
695 | 695 | # Ran 2 tests, 0 skipped, 2 failed. |
|
696 | 696 | python hash seed: * (glob) |
|
697 | 697 | [1] |
|
698 | 698 | |
|
699 | 699 | failures in parallel with --first should only print one failure |
|
700 | 700 | $ rt --jobs 2 --first test-failure*.t |
|
701 | 701 | running 2 tests using 2 parallel processes |
|
702 | 702 | |
|
703 | 703 | --- $TESTTMP/test-failure*.t (glob) |
|
704 | 704 | +++ $TESTTMP/test-failure*.t.err (glob) |
|
705 | 705 | @@ -1,5 +1,5 @@ |
|
706 | 706 | $ echo babar |
|
707 | 707 | - rataxes |
|
708 | 708 | + babar |
|
709 | 709 | This is a noop statement so that |
|
710 | 710 | this test is still more bytes than success. |
|
711 | 711 | pad pad pad pad............................................................ |
|
712 | 712 | |
|
713 | 713 | Failed test-failure*.t: output changed (glob) |
|
714 | 714 | Failed test-failure*.t: output changed (glob) |
|
715 | 715 | # Ran 2 tests, 0 skipped, 2 failed. |
|
716 | 716 | python hash seed: * (glob) |
|
717 | 717 | [1] |
|
718 | 718 | |
|
719 | 719 | |
|
720 | 720 | (delete the duplicated test file) |
|
721 | 721 | $ rm test-failure-copy.t |
|
722 | 722 | |
|
723 | 723 | multiple runs per test should be parallelized |
|
724 | 724 | |
|
725 | 725 | $ rt --jobs 2 --runs-per-test 2 test-success.t |
|
726 | 726 | running 2 tests using 2 parallel processes |
|
727 | 727 | .. |
|
728 | 728 | # Ran 2 tests, 0 skipped, 0 failed. |
|
729 | 729 | |
|
730 | 730 | Interactive run |
|
731 | 731 | =============== |
|
732 | 732 | |
|
733 | 733 | (backup the failing test) |
|
734 | 734 | $ cp test-failure.t backup |
|
735 | 735 | |
|
736 | 736 | Refuse the fix |
|
737 | 737 | |
|
738 | 738 | $ echo 'n' | rt -i |
|
739 | 739 | running 2 tests using 1 parallel processes |
|
740 | 740 | |
|
741 | 741 | --- $TESTTMP/test-failure.t |
|
742 | 742 | +++ $TESTTMP/test-failure.t.err |
|
743 | 743 | @@ -1,5 +1,5 @@ |
|
744 | 744 | $ echo babar |
|
745 | 745 | - rataxes |
|
746 | 746 | + babar |
|
747 | 747 | This is a noop statement so that |
|
748 | 748 | this test is still more bytes than success. |
|
749 | 749 | pad pad pad pad............................................................ |
|
750 | 750 | Accept this change? [y/N] |
|
751 | 751 | ERROR: test-failure.t output changed |
|
752 | 752 | !. |
|
753 | 753 | Failed test-failure.t: output changed |
|
754 | 754 | # Ran 2 tests, 0 skipped, 1 failed. |
|
755 | 755 | python hash seed: * (glob) |
|
756 | 756 | [1] |
|
757 | 757 | |
|
758 | 758 | $ cat test-failure.t |
|
759 | 759 | $ echo babar |
|
760 | 760 | rataxes |
|
761 | 761 | This is a noop statement so that |
|
762 | 762 | this test is still more bytes than success. |
|
763 | 763 | pad pad pad pad............................................................ |
|
764 | 764 | pad pad pad pad............................................................ |
|
765 | 765 | pad pad pad pad............................................................ |
|
766 | 766 | pad pad pad pad............................................................ |
|
767 | 767 | pad pad pad pad............................................................ |
|
768 | 768 | pad pad pad pad............................................................ |
|
769 | 769 | |
|
770 | 770 | Interactive with custom view |
|
771 | 771 | |
|
772 | 772 | $ echo 'n' | rt -i --view echo |
|
773 | 773 | running 2 tests using 1 parallel processes |
|
774 | 774 | $TESTTMP/test-failure.t $TESTTMP/test-failure.t.err |
|
775 | 775 | Accept this change? [y/N]* (glob) |
|
776 | 776 | ERROR: test-failure.t output changed |
|
777 | 777 | !. |
|
778 | 778 | Failed test-failure.t: output changed |
|
779 | 779 | # Ran 2 tests, 0 skipped, 1 failed. |
|
780 | 780 | python hash seed: * (glob) |
|
781 | 781 | [1] |
|
782 | 782 | |
|
783 | 783 | View the fix |
|
784 | 784 | |
|
785 | 785 | $ echo 'y' | rt --view echo |
|
786 | 786 | running 2 tests using 1 parallel processes |
|
787 | 787 | $TESTTMP/test-failure.t $TESTTMP/test-failure.t.err |
|
788 | 788 | |
|
789 | 789 | ERROR: test-failure.t output changed |
|
790 | 790 | !. |
|
791 | 791 | Failed test-failure.t: output changed |
|
792 | 792 | # Ran 2 tests, 0 skipped, 1 failed. |
|
793 | 793 | python hash seed: * (glob) |
|
794 | 794 | [1] |
|
795 | 795 | |
|
796 | 796 | Accept the fix |
|
797 | 797 | |
|
798 | 798 | $ cat >> test-failure.t <<EOF |
|
799 | 799 | > $ echo 'saved backup bundle to \$TESTTMP/foo.hg' |
|
800 | 800 | > saved backup bundle to \$TESTTMP/foo.hg |
|
801 | 801 | > $ echo 'saved backup bundle to \$TESTTMP/foo.hg' |
|
802 | 802 | > saved backup bundle to $TESTTMP\\foo.hg |
|
803 | 803 | > $ echo 'saved backup bundle to \$TESTTMP/foo.hg' |
|
804 | 804 | > saved backup bundle to \$TESTTMP/*.hg (glob) |
|
805 | 805 | > EOF |
|
806 | 806 | $ echo 'y' | rt -i 2>&1 |
|
807 | 807 | running 2 tests using 1 parallel processes |
|
808 | 808 | |
|
809 | 809 | --- $TESTTMP/test-failure.t |
|
810 | 810 | +++ $TESTTMP/test-failure.t.err |
|
811 | 811 | @@ -1,5 +1,5 @@ |
|
812 | 812 | $ echo babar |
|
813 | 813 | - rataxes |
|
814 | 814 | + babar |
|
815 | 815 | This is a noop statement so that |
|
816 | 816 | this test is still more bytes than success. |
|
817 | 817 | pad pad pad pad............................................................ |
|
818 | 818 | @@ -11,6 +11,6 @@ |
|
819 | 819 | $ echo 'saved backup bundle to $TESTTMP/foo.hg' |
|
820 | 820 | saved backup bundle to $TESTTMP/foo.hg |
|
821 | 821 | $ echo 'saved backup bundle to $TESTTMP/foo.hg' |
|
822 | 822 | - saved backup bundle to $TESTTMP\foo.hg |
|
823 | 823 | + saved backup bundle to $TESTTMP/foo.hg |
|
824 | 824 | $ echo 'saved backup bundle to $TESTTMP/foo.hg' |
|
825 | 825 | saved backup bundle to $TESTTMP/*.hg (glob) |
|
826 | 826 | Accept this change? [y/N] .. |
|
827 | 827 | # Ran 2 tests, 0 skipped, 0 failed. |
|
828 | 828 | |
|
829 | 829 | $ sed -e 's,(glob)$,&<,g' test-failure.t |
|
830 | 830 | $ echo babar |
|
831 | 831 | babar |
|
832 | 832 | This is a noop statement so that |
|
833 | 833 | this test is still more bytes than success. |
|
834 | 834 | pad pad pad pad............................................................ |
|
835 | 835 | pad pad pad pad............................................................ |
|
836 | 836 | pad pad pad pad............................................................ |
|
837 | 837 | pad pad pad pad............................................................ |
|
838 | 838 | pad pad pad pad............................................................ |
|
839 | 839 | pad pad pad pad............................................................ |
|
840 | 840 | $ echo 'saved backup bundle to $TESTTMP/foo.hg' |
|
841 | 841 | saved backup bundle to $TESTTMP/foo.hg |
|
842 | 842 | $ echo 'saved backup bundle to $TESTTMP/foo.hg' |
|
843 | 843 | saved backup bundle to $TESTTMP/foo.hg |
|
844 | 844 | $ echo 'saved backup bundle to $TESTTMP/foo.hg' |
|
845 | 845 | saved backup bundle to $TESTTMP/*.hg (glob)< |
|
846 | 846 | |
|
847 | 847 | $ rm test-failure.t |
|
848 | 848 | |
|
849 | 849 | Race condition - test file was modified when test is running |
|
850 | 850 | |
|
851 | 851 | $ TESTRACEDIR=`pwd` |
|
852 | 852 | $ export TESTRACEDIR |
|
853 | 853 | $ cat > test-race.t <<EOF |
|
854 | 854 | > $ echo 1 |
|
855 | 855 | > $ echo "# a new line" >> $TESTRACEDIR/test-race.t |
|
856 | 856 | > EOF |
|
857 | 857 | |
|
858 | 858 | $ rt -i test-race.t |
|
859 | 859 | running 1 tests using 1 parallel processes |
|
860 | 860 | |
|
861 | 861 | --- $TESTTMP/test-race.t |
|
862 | 862 | +++ $TESTTMP/test-race.t.err |
|
863 | 863 | @@ -1,2 +1,3 @@ |
|
864 | 864 | $ echo 1 |
|
865 | 865 | + 1 |
|
866 | 866 | $ echo "# a new line" >> $TESTTMP/test-race.t |
|
867 | 867 | Reference output has changed (run again to prompt changes) |
|
868 | 868 | ERROR: test-race.t output changed |
|
869 | 869 | ! |
|
870 | 870 | Failed test-race.t: output changed |
|
871 | 871 | # Ran 1 tests, 0 skipped, 1 failed. |
|
872 | 872 | python hash seed: * (glob) |
|
873 | 873 | [1] |
|
874 | 874 | |
|
875 | 875 | $ rm test-race.t |
|
876 | 876 | |
|
877 | 877 | When "#testcases" is used in .t files |
|
878 | 878 | |
|
879 | 879 | $ cat >> test-cases.t <<EOF |
|
880 | 880 | > #testcases a b |
|
881 | 881 | > #if a |
|
882 | 882 | > $ echo 1 |
|
883 | 883 | > #endif |
|
884 | 884 | > #if b |
|
885 | 885 | > $ echo 2 |
|
886 | 886 | > #endif |
|
887 | 887 | > EOF |
|
888 | 888 | |
|
889 | 889 | $ cat <<EOF | rt -i test-cases.t 2>&1 |
|
890 | 890 | > y |
|
891 | 891 | > y |
|
892 | 892 | > EOF |
|
893 | 893 | running 2 tests using 1 parallel processes |
|
894 | 894 | |
|
895 | 895 | --- $TESTTMP/test-cases.t |
|
896 | 896 | +++ $TESTTMP/test-cases.t#a.err |
|
897 | 897 | @@ -1,6 +1,7 @@ |
|
898 | 898 | #testcases a b |
|
899 | 899 | #if a |
|
900 | 900 | $ echo 1 |
|
901 | 901 | + 1 |
|
902 | 902 | #endif |
|
903 | 903 | #if b |
|
904 | 904 | $ echo 2 |
|
905 | 905 | Accept this change? [y/N] . |
|
906 | 906 | --- $TESTTMP/test-cases.t |
|
907 | 907 | +++ $TESTTMP/test-cases.t#b.err |
|
908 | 908 | @@ -5,4 +5,5 @@ |
|
909 | 909 | #endif |
|
910 | 910 | #if b |
|
911 | 911 | $ echo 2 |
|
912 | 912 | + 2 |
|
913 | 913 | #endif |
|
914 | 914 | Accept this change? [y/N] . |
|
915 | 915 | # Ran 2 tests, 0 skipped, 0 failed. |
|
916 | 916 | |
|
917 | 917 | $ cat test-cases.t |
|
918 | 918 | #testcases a b |
|
919 | 919 | #if a |
|
920 | 920 | $ echo 1 |
|
921 | 921 | 1 |
|
922 | 922 | #endif |
|
923 | 923 | #if b |
|
924 | 924 | $ echo 2 |
|
925 | 925 | 2 |
|
926 | 926 | #endif |
|
927 | 927 | |
|
928 | 928 | $ cat >> test-cases.t <<'EOF' |
|
929 | 929 | > #if a |
|
930 | 930 | > $ NAME=A |
|
931 | 931 | > #else |
|
932 | 932 | > $ NAME=B |
|
933 | 933 | > #endif |
|
934 | 934 | > $ echo $NAME |
|
935 | 935 | > A (a !) |
|
936 | 936 | > B (b !) |
|
937 | 937 | > EOF |
|
938 | 938 | $ rt test-cases.t |
|
939 | 939 | running 2 tests using 1 parallel processes |
|
940 | 940 | .. |
|
941 | 941 | # Ran 2 tests, 0 skipped, 0 failed. |
|
942 | 942 | |
|
943 | 943 | When using multiple dimensions of "#testcases" in .t files |
|
944 | 944 | |
|
945 | 945 | $ cat > test-cases.t <<'EOF' |
|
946 | 946 | > #testcases a b |
|
947 | 947 | > #testcases c d |
|
948 | 948 | > #if a d |
|
949 | 949 | > $ echo $TESTCASE |
|
950 | 950 | > a#d |
|
951 | 951 | > #endif |
|
952 | 952 | > #if b c |
|
953 | 953 | > $ echo yes |
|
954 | 954 | > no |
|
955 | 955 | > #endif |
|
956 | 956 | > EOF |
|
957 | 957 | $ rt test-cases.t |
|
958 | 958 | running 4 tests using 1 parallel processes |
|
959 | 959 | .. |
|
960 | 960 | --- $TESTTMP/test-cases.t |
|
961 | 961 | +++ $TESTTMP/test-cases.t#b#c.err |
|
962 | 962 | @@ -6,5 +6,5 @@ |
|
963 | 963 | #endif |
|
964 | 964 | #if b c |
|
965 | 965 | $ echo yes |
|
966 | 966 | - no |
|
967 | 967 | + yes |
|
968 | 968 | #endif |
|
969 | 969 | |
|
970 | 970 | ERROR: test-cases.t#b#c output changed |
|
971 | 971 | !. |
|
972 | 972 | Failed test-cases.t#b#c: output changed |
|
973 | 973 | # Ran 4 tests, 0 skipped, 1 failed. |
|
974 | 974 | python hash seed: * (glob) |
|
975 | 975 | [1] |
|
976 | 976 | |
|
977 | 977 | $ rt --retest |
|
978 | 978 | running 1 tests using 1 parallel processes |
|
979 | 979 | |
|
980 | 980 | --- $TESTTMP/test-cases.t |
|
981 | 981 | +++ $TESTTMP/test-cases.t#b#c.err |
|
982 | 982 | @@ -6,5 +6,5 @@ |
|
983 | 983 | #endif |
|
984 | 984 | #if b c |
|
985 | 985 | $ echo yes |
|
986 | 986 | - no |
|
987 | 987 | + yes |
|
988 | 988 | #endif |
|
989 | 989 | |
|
990 | 990 | ERROR: test-cases.t#b#c output changed |
|
991 | 991 | ! |
|
992 | 992 | Failed test-cases.t#b#c: output changed |
|
993 | 993 | # Ran 1 tests, 0 skipped, 1 failed. |
|
994 | 994 | python hash seed: * (glob) |
|
995 | 995 | [1] |
|
996 | 996 | $ rm test-cases.t#b#c.err |
|
997 | 997 | $ rm test-cases.t |
|
998 | 998 | |
|
999 | 999 | (reinstall) |
|
1000 | 1000 | $ mv backup test-failure.t |
|
1001 | 1001 | |
|
1002 | 1002 | No Diff |
|
1003 | 1003 | =============== |
|
1004 | 1004 | |
|
1005 | 1005 | $ rt --nodiff |
|
1006 | 1006 | running 2 tests using 1 parallel processes |
|
1007 | 1007 | !. |
|
1008 | 1008 | Failed test-failure.t: output changed |
|
1009 | 1009 | # Ran 2 tests, 0 skipped, 1 failed. |
|
1010 | 1010 | python hash seed: * (glob) |
|
1011 | 1011 | [1] |
|
1012 | 1012 | |
|
1013 | 1013 | test --tmpdir support |
|
1014 | 1014 | $ rt --tmpdir=$TESTTMP/keep test-success.t |
|
1015 | 1015 | running 1 tests using 1 parallel processes |
|
1016 | 1016 | |
|
1017 | 1017 | Keeping testtmp dir: $TESTTMP/keep/child1/test-success.t |
|
1018 | 1018 | Keeping threadtmp dir: $TESTTMP/keep/child1 |
|
1019 | 1019 | . |
|
1020 | 1020 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1021 | 1021 | |
|
1022 | 1022 | timeouts |
|
1023 | 1023 | ======== |
|
1024 | 1024 | $ cat > test-timeout.t <<EOF |
|
1025 | 1025 | > $ sleep 2 |
|
1026 | 1026 | > $ echo pass |
|
1027 | 1027 | > pass |
|
1028 | 1028 | > EOF |
|
1029 | 1029 | > echo '#require slow' > test-slow-timeout.t |
|
1030 | 1030 | > cat test-timeout.t >> test-slow-timeout.t |
|
1031 | 1031 | $ rt --timeout=1 --slowtimeout=3 test-timeout.t test-slow-timeout.t |
|
1032 | 1032 | running 2 tests using 1 parallel processes |
|
1033 | 1033 | st |
|
1034 | 1034 | Skipped test-slow-timeout.t: missing feature: allow slow tests (use --allow-slow-tests) |
|
1035 | 1035 | Failed test-timeout.t: timed out |
|
1036 | 1036 | # Ran 1 tests, 1 skipped, 1 failed. |
|
1037 | 1037 | python hash seed: * (glob) |
|
1038 | 1038 | [1] |
|
1039 | 1039 | $ rt --timeout=1 --slowtimeout=3 \ |
|
1040 | 1040 | > test-timeout.t test-slow-timeout.t --allow-slow-tests |
|
1041 | 1041 | running 2 tests using 1 parallel processes |
|
1042 | 1042 | .t |
|
1043 | 1043 | Failed test-timeout.t: timed out |
|
1044 | 1044 | # Ran 2 tests, 0 skipped, 1 failed. |
|
1045 | 1045 | python hash seed: * (glob) |
|
1046 | 1046 | [1] |
|
1047 | 1047 | $ rm test-timeout.t test-slow-timeout.t |
|
1048 | 1048 | |
|
1049 | 1049 | test for --time |
|
1050 | 1050 | ================== |
|
1051 | 1051 | |
|
1052 | 1052 | $ rt test-success.t --time |
|
1053 | 1053 | running 1 tests using 1 parallel processes |
|
1054 | 1054 | . |
|
1055 | 1055 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1056 | 1056 | # Producing time report |
|
1057 | 1057 | start end cuser csys real Test |
|
1058 | 1058 | \s*[\d\.]{5,8} \s*[\d\.]{5,8} \s*[\d\.]{5,8} \s*[\d\.]{5,8} \s*[\d\.]{5,8} test-success.t (re) |
|
1059 | 1059 | |
|
1060 | 1060 | test for --time with --job enabled |
|
1061 | 1061 | ==================================== |
|
1062 | 1062 | |
|
1063 | 1063 | $ rt test-success.t --time --jobs 2 |
|
1064 | 1064 | running 1 tests using 1 parallel processes |
|
1065 | 1065 | . |
|
1066 | 1066 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1067 | 1067 | # Producing time report |
|
1068 | 1068 | start end cuser csys real Test |
|
1069 | 1069 | \s*[\d\.]{5,8} \s*[\d\.]{5,8} \s*[\d\.]{5,8} \s*[\d\.]{5,8} \s*[\d\.]{5,8} test-success.t (re) |
|
1070 | 1070 | |
|
1071 | 1071 | Skips |
|
1072 | 1072 | ================ |
|
1073 | 1073 | $ cat > test-skip.t <<EOF |
|
1074 | 1074 | > $ echo xyzzy |
|
1075 | 1075 | > #if true |
|
1076 | 1076 | > #require false |
|
1077 | 1077 | > #end |
|
1078 | 1078 | > EOF |
|
1079 | 1079 | $ cat > test-noskip.t <<EOF |
|
1080 | 1080 | > #if false |
|
1081 | 1081 | > #require false |
|
1082 | 1082 | > #endif |
|
1083 | 1083 | > EOF |
|
1084 | 1084 | $ rt --nodiff |
|
1085 | 1085 | running 4 tests using 1 parallel processes |
|
1086 | 1086 | !.s. |
|
1087 | 1087 | Skipped test-skip.t: missing feature: nail clipper |
|
1088 | 1088 | Failed test-failure.t: output changed |
|
1089 | 1089 | # Ran 3 tests, 1 skipped, 1 failed. |
|
1090 | 1090 | python hash seed: * (glob) |
|
1091 | 1091 | [1] |
|
1092 | 1092 | |
|
1093 | 1093 | $ rm test-noskip.t |
|
1094 | 1094 | $ rt --keyword xyzzy |
|
1095 | 1095 | running 3 tests using 1 parallel processes |
|
1096 | 1096 | .s |
|
1097 | 1097 | Skipped test-skip.t: missing feature: nail clipper |
|
1098 | 1098 | # Ran 2 tests, 2 skipped, 0 failed. |
|
1099 | 1099 | |
|
1100 | 1100 | Skips with xml |
|
1101 | 1101 | $ rt --keyword xyzzy \ |
|
1102 | 1102 | > --xunit=xunit.xml |
|
1103 | 1103 | running 3 tests using 1 parallel processes |
|
1104 | 1104 | .s |
|
1105 | 1105 | Skipped test-skip.t: missing feature: nail clipper |
|
1106 | 1106 | # Ran 2 tests, 2 skipped, 0 failed. |
|
1107 | 1107 | $ cat xunit.xml |
|
1108 | 1108 | <?xml version="1.0" encoding="utf-8"?> |
|
1109 | 1109 | <testsuite errors="0" failures="0" name="run-tests" skipped="2" tests="2"> |
|
1110 | 1110 | <testcase name="test-success.t" time="*"/> (glob) |
|
1111 | 1111 | <testcase name="test-skip.t"> |
|
1112 | 1112 | <skipped><![CDATA[missing feature: nail clipper]]></skipped> (py38 !) |
|
1113 | 1113 | <skipped> (no-py38 !) |
|
1114 | 1114 | <![CDATA[missing feature: nail clipper]]> </skipped> (no-py38 !) |
|
1115 | 1115 | </testcase> |
|
1116 | 1116 | </testsuite> |
|
1117 | 1117 | |
|
1118 | 1118 | Missing skips or blacklisted skips don't count as executed: |
|
1119 | 1119 | $ mkdir tests |
|
1120 | 1120 | $ echo tests/test-failure.t > blacklist |
|
1121 | 1121 | $ cp test-failure.t tests |
|
1122 | 1122 | $ rt --blacklist=blacklist --json\ |
|
1123 | 1123 | > tests/test-failure.t tests/test-bogus.t |
|
1124 | 1124 | running 2 tests using 1 parallel processes |
|
1125 | 1125 | ss |
|
1126 | 1126 | Skipped test-bogus.t: Doesn't exist |
|
1127 | 1127 | Skipped test-failure.t: blacklisted |
|
1128 | 1128 | # Ran 0 tests, 2 skipped, 0 failed. |
|
1129 | 1129 | $ cat tests/report.json |
|
1130 | 1130 | testreport ={ |
|
1131 | 1131 | "test-bogus.t": { |
|
1132 | 1132 | "result": "skip" |
|
1133 | 1133 | }, |
|
1134 | 1134 | "test-failure.t": { |
|
1135 | 1135 | "result": "skip" |
|
1136 | 1136 | } |
|
1137 | 1137 | } (no-eol) |
|
1138 | 1138 | $ rm -r tests |
|
1139 | 1139 | $ echo test-failure.t > blacklist |
|
1140 | 1140 | |
|
1141 | 1141 | Whitelist trumps blacklist |
|
1142 | 1142 | $ echo test-failure.t > whitelist |
|
1143 | 1143 | $ rt --blacklist=blacklist --whitelist=whitelist --json\ |
|
1144 | 1144 | > test-failure.t test-bogus.t |
|
1145 | 1145 | running 2 tests using 1 parallel processes |
|
1146 | 1146 | s |
|
1147 | 1147 | --- $TESTTMP/test-failure.t |
|
1148 | 1148 | +++ $TESTTMP/test-failure.t.err |
|
1149 | 1149 | @@ -1,5 +1,5 @@ |
|
1150 | 1150 | $ echo babar |
|
1151 | 1151 | - rataxes |
|
1152 | 1152 | + babar |
|
1153 | 1153 | This is a noop statement so that |
|
1154 | 1154 | this test is still more bytes than success. |
|
1155 | 1155 | pad pad pad pad............................................................ |
|
1156 | 1156 | |
|
1157 | 1157 | ERROR: test-failure.t output changed |
|
1158 | 1158 | ! |
|
1159 | 1159 | Skipped test-bogus.t: Doesn't exist |
|
1160 | 1160 | Failed test-failure.t: output changed |
|
1161 | 1161 | # Ran 1 tests, 1 skipped, 1 failed. |
|
1162 | 1162 | python hash seed: * (glob) |
|
1163 | 1163 | [1] |
|
1164 | 1164 | |
|
1165 | 1165 | Ensure that --test-list causes only the tests listed in that file to |
|
1166 | 1166 | be executed. |
|
1167 | 1167 | $ echo test-success.t >> onlytest |
|
1168 | 1168 | $ rt --test-list=onlytest |
|
1169 | 1169 | running 1 tests using 1 parallel processes |
|
1170 | 1170 | . |
|
1171 | 1171 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1172 | 1172 | $ echo test-bogus.t >> anothertest |
|
1173 | 1173 | $ rt --test-list=onlytest --test-list=anothertest |
|
1174 | 1174 | running 2 tests using 1 parallel processes |
|
1175 | 1175 | s. |
|
1176 | 1176 | Skipped test-bogus.t: Doesn't exist |
|
1177 | 1177 | # Ran 1 tests, 1 skipped, 0 failed. |
|
1178 | 1178 | $ rm onlytest anothertest |
|
1179 | 1179 | |
|
1180 | 1180 | test for --json |
|
1181 | 1181 | ================== |
|
1182 | 1182 | |
|
1183 | 1183 | $ rt --json |
|
1184 | 1184 | running 3 tests using 1 parallel processes |
|
1185 | 1185 | |
|
1186 | 1186 | --- $TESTTMP/test-failure.t |
|
1187 | 1187 | +++ $TESTTMP/test-failure.t.err |
|
1188 | 1188 | @@ -1,5 +1,5 @@ |
|
1189 | 1189 | $ echo babar |
|
1190 | 1190 | - rataxes |
|
1191 | 1191 | + babar |
|
1192 | 1192 | This is a noop statement so that |
|
1193 | 1193 | this test is still more bytes than success. |
|
1194 | 1194 | pad pad pad pad............................................................ |
|
1195 | 1195 | |
|
1196 | 1196 | ERROR: test-failure.t output changed |
|
1197 | 1197 | !.s |
|
1198 | 1198 | Skipped test-skip.t: missing feature: nail clipper |
|
1199 | 1199 | Failed test-failure.t: output changed |
|
1200 | 1200 | # Ran 2 tests, 1 skipped, 1 failed. |
|
1201 | 1201 | python hash seed: * (glob) |
|
1202 | 1202 | [1] |
|
1203 | 1203 | |
|
1204 | 1204 | $ cat report.json |
|
1205 | 1205 | testreport ={ |
|
1206 | 1206 | "test-failure.t": [\{] (re) |
|
1207 | 1207 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1208 | 1208 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1209 | 1209 | "diff": "---.+\+\+\+.+", ? (re) |
|
1210 | 1210 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1211 | 1211 | "result": "failure", ? (re) |
|
1212 | 1212 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1213 | 1213 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1214 | 1214 | }, ? (re) |
|
1215 | 1215 | "test-skip.t": { |
|
1216 | 1216 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1217 | 1217 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1218 | 1218 | "diff": "", ? (re) |
|
1219 | 1219 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1220 | 1220 | "result": "skip", ? (re) |
|
1221 | 1221 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1222 | 1222 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1223 | 1223 | }, ? (re) |
|
1224 | 1224 | "test-success.t": [\{] (re) |
|
1225 | 1225 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1226 | 1226 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1227 | 1227 | "diff": "", ? (re) |
|
1228 | 1228 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1229 | 1229 | "result": "success", ? (re) |
|
1230 | 1230 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1231 | 1231 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1232 | 1232 | } |
|
1233 | 1233 | } (no-eol) |
|
1234 | 1234 | --json with --outputdir |
|
1235 | 1235 | |
|
1236 | 1236 | $ rm report.json |
|
1237 | 1237 | $ rm -r output |
|
1238 | 1238 | $ mkdir output |
|
1239 | 1239 | $ rt --json --outputdir output |
|
1240 | 1240 | running 3 tests using 1 parallel processes |
|
1241 | 1241 | |
|
1242 | 1242 | --- $TESTTMP/test-failure.t |
|
1243 | 1243 | +++ $TESTTMP/output/test-failure.t.err |
|
1244 | 1244 | @@ -1,5 +1,5 @@ |
|
1245 | 1245 | $ echo babar |
|
1246 | 1246 | - rataxes |
|
1247 | 1247 | + babar |
|
1248 | 1248 | This is a noop statement so that |
|
1249 | 1249 | this test is still more bytes than success. |
|
1250 | 1250 | pad pad pad pad............................................................ |
|
1251 | 1251 | |
|
1252 | 1252 | ERROR: test-failure.t output changed |
|
1253 | 1253 | !.s |
|
1254 | 1254 | Skipped test-skip.t: missing feature: nail clipper |
|
1255 | 1255 | Failed test-failure.t: output changed |
|
1256 | 1256 | # Ran 2 tests, 1 skipped, 1 failed. |
|
1257 | 1257 | python hash seed: * (glob) |
|
1258 | 1258 | [1] |
|
1259 | 1259 | $ f report.json |
|
1260 | 1260 | report.json: file not found |
|
1261 | 1261 | $ cat output/report.json |
|
1262 | 1262 | testreport ={ |
|
1263 | 1263 | "test-failure.t": [\{] (re) |
|
1264 | 1264 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1265 | 1265 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1266 | 1266 | "diff": "---.+\+\+\+.+", ? (re) |
|
1267 | 1267 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1268 | 1268 | "result": "failure", ? (re) |
|
1269 | 1269 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1270 | 1270 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1271 | 1271 | }, ? (re) |
|
1272 | 1272 | "test-skip.t": { |
|
1273 | 1273 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1274 | 1274 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1275 | 1275 | "diff": "", ? (re) |
|
1276 | 1276 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1277 | 1277 | "result": "skip", ? (re) |
|
1278 | 1278 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1279 | 1279 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1280 | 1280 | }, ? (re) |
|
1281 | 1281 | "test-success.t": [\{] (re) |
|
1282 | 1282 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1283 | 1283 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1284 | 1284 | "diff": "", ? (re) |
|
1285 | 1285 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1286 | 1286 | "result": "success", ? (re) |
|
1287 | 1287 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1288 | 1288 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1289 | 1289 | } |
|
1290 | 1290 | } (no-eol) |
|
1291 | 1291 | $ ls -a output |
|
1292 | 1292 | . |
|
1293 | 1293 | .. |
|
1294 | 1294 | .testtimes |
|
1295 | 1295 | report.json |
|
1296 | 1296 | test-failure.t.err |
|
1297 | 1297 | |
|
1298 | 1298 | Test that failed test accepted through interactive are properly reported: |
|
1299 | 1299 | |
|
1300 | 1300 | $ cp test-failure.t backup |
|
1301 | 1301 | $ echo y | rt --json -i |
|
1302 | 1302 | running 3 tests using 1 parallel processes |
|
1303 | 1303 | |
|
1304 | 1304 | --- $TESTTMP/test-failure.t |
|
1305 | 1305 | +++ $TESTTMP/test-failure.t.err |
|
1306 | 1306 | @@ -1,5 +1,5 @@ |
|
1307 | 1307 | $ echo babar |
|
1308 | 1308 | - rataxes |
|
1309 | 1309 | + babar |
|
1310 | 1310 | This is a noop statement so that |
|
1311 | 1311 | this test is still more bytes than success. |
|
1312 | 1312 | pad pad pad pad............................................................ |
|
1313 | 1313 | Accept this change? [y/N] ..s |
|
1314 | 1314 | Skipped test-skip.t: missing feature: nail clipper |
|
1315 | 1315 | # Ran 2 tests, 1 skipped, 0 failed. |
|
1316 | 1316 | |
|
1317 | 1317 | $ cat report.json |
|
1318 | 1318 | testreport ={ |
|
1319 | 1319 | "test-failure.t": [\{] (re) |
|
1320 | 1320 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1321 | 1321 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1322 | 1322 | "diff": "", ? (re) |
|
1323 | 1323 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1324 | 1324 | "result": "success", ? (re) |
|
1325 | 1325 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1326 | 1326 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1327 | 1327 | }, ? (re) |
|
1328 | 1328 | "test-skip.t": { |
|
1329 | 1329 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1330 | 1330 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1331 | 1331 | "diff": "", ? (re) |
|
1332 | 1332 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1333 | 1333 | "result": "skip", ? (re) |
|
1334 | 1334 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1335 | 1335 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1336 | 1336 | }, ? (re) |
|
1337 | 1337 | "test-success.t": [\{] (re) |
|
1338 | 1338 | "csys": "\s*\d+\.\d{3,4}", ? (re) |
|
1339 | 1339 | "cuser": "\s*\d+\.\d{3,4}", ? (re) |
|
1340 | 1340 | "diff": "", ? (re) |
|
1341 | 1341 | "end": "\s*\d+\.\d{3,4}", ? (re) |
|
1342 | 1342 | "result": "success", ? (re) |
|
1343 | 1343 | "start": "\s*\d+\.\d{3,4}", ? (re) |
|
1344 | 1344 | "time": "\s*\d+\.\d{3,4}" (re) |
|
1345 | 1345 | } |
|
1346 | 1346 | } (no-eol) |
|
1347 | 1347 | $ mv backup test-failure.t |
|
1348 | 1348 | |
|
1349 | 1349 | backslash on end of line with glob matching is handled properly |
|
1350 | 1350 | |
|
1351 | 1351 | $ cat > test-glob-backslash.t << EOF |
|
1352 | 1352 | > $ echo 'foo bar \\' |
|
1353 | 1353 | > foo * \ (glob) |
|
1354 | 1354 | > EOF |
|
1355 | 1355 | |
|
1356 | 1356 | $ rt test-glob-backslash.t |
|
1357 | 1357 | running 1 tests using 1 parallel processes |
|
1358 | 1358 | . |
|
1359 | 1359 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1360 | 1360 | |
|
1361 | 1361 | $ rm -f test-glob-backslash.t |
|
1362 | 1362 | |
|
1363 | 1363 | Test globbing of local IP addresses |
|
1364 | 1364 | $ echo 172.16.18.1 |
|
1365 | 1365 | $LOCALIP (glob) |
|
1366 | 1366 | $ echo dead:beef::1 |
|
1367 | 1367 | $LOCALIP (glob) |
|
1368 | 1368 | |
|
1369 | 1369 | Add support for external test formatter |
|
1370 | 1370 | ======================================= |
|
1371 | 1371 | |
|
1372 |
$ CUSTOM_TEST_RESULT=basic_test_result "$PYTHON" $TESTDIR/run-tests.py --with-hg= |
|
|
1372 | $ CUSTOM_TEST_RESULT=basic_test_result "$PYTHON" $TESTDIR/run-tests.py --with-hg=$HGTEST_REAL_HG -j1 "$@" test-success.t test-failure.t | |
|
1373 | 1373 | running 2 tests using 1 parallel processes |
|
1374 | 1374 | |
|
1375 | 1375 | # Ran 2 tests, 0 skipped, 0 failed. |
|
1376 | 1376 | ON_START! <__main__.TestSuite tests=[<__main__.TTest testMethod=test-failure.t>, <__main__.TTest testMethod=test-success.t>]> |
|
1377 | 1377 | FAILURE! test-failure.t output changed |
|
1378 | 1378 | SUCCESS! test-success.t |
|
1379 | 1379 | ON_END! |
|
1380 | 1380 | |
|
1381 | 1381 | Test reusability for third party tools |
|
1382 | 1382 | ====================================== |
|
1383 | 1383 | |
|
1384 | 1384 | $ THISTESTDIR="$TESTDIR" |
|
1385 | 1385 | $ export THISTESTDIR |
|
1386 | 1386 | $ THISTESTTMP="$TESTTMP" |
|
1387 | 1387 | $ export THISTESTTMP |
|
1388 | 1388 | |
|
1389 | 1389 | #if windows |
|
1390 | 1390 | |
|
1391 | 1391 | $ NEWTESTDIR="$THISTESTTMP"\\anothertests |
|
1392 | 1392 | |
|
1393 | 1393 | #else |
|
1394 | 1394 | |
|
1395 | 1395 | $ NEWTESTDIR="$THISTESTTMP"/anothertests |
|
1396 | 1396 | |
|
1397 | 1397 | #endif |
|
1398 | 1398 | |
|
1399 | 1399 | $ export NEWTESTDIR |
|
1400 | 1400 | |
|
1401 | 1401 | $ echo creating some new test in: $NEWTESTDIR |
|
1402 | 1402 | creating some new test in: $TESTTMP\anothertests (windows !) |
|
1403 | 1403 | creating some new test in: $TESTTMP/anothertests (no-windows !) |
|
1404 | 1404 | $ mkdir "$NEWTESTDIR" |
|
1405 | 1405 | $ cd "$NEWTESTDIR" |
|
1406 | 1406 | |
|
1407 | 1407 | test that `run-tests.py` can execute hghave, even if it runs not in |
|
1408 | 1408 | Mercurial source tree. |
|
1409 | 1409 | |
|
1410 | 1410 | $ cat > test-hghave.t <<EOF |
|
1411 | 1411 | > #require true |
|
1412 | 1412 | > $ echo foo |
|
1413 | 1413 | > foo |
|
1414 | 1414 | > EOF |
|
1415 | 1415 | $ rt test-hghave.t |
|
1416 | 1416 | running 1 tests using 1 parallel processes |
|
1417 | 1417 | . |
|
1418 | 1418 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1419 | 1419 | |
|
1420 | 1420 | test that RUNTESTDIR refers the directory, in which `run-tests.py` now |
|
1421 | 1421 | running is placed. |
|
1422 | 1422 | |
|
1423 | 1423 | |
|
1424 | 1424 | $ cat > test-runtestdir.t <<EOF |
|
1425 | 1425 | > # \$THISTESTDIR, in which test-run-tests.t (this test file) is placed |
|
1426 | 1426 | > # \$THISTESTTMP, in which test-run-tests.t (this test file) is placed |
|
1427 | 1427 | > # \$TESTDIR, in which test-runtestdir.t is placed (expanded at runtime) |
|
1428 | 1428 | > # \$RUNTESTDIR, in which run-tests.py is placed (expanded at runtime) |
|
1429 | 1429 | > |
|
1430 | 1430 | > $ test "\$TESTDIR" = "\$NEWTESTDIR" |
|
1431 | 1431 | > If this prints a path, that means RUNTESTDIR didn't equal |
|
1432 | 1432 | > THISTESTDIR as it should have. |
|
1433 | 1433 | > $ test "\$RUNTESTDIR" = "\$THISTESTDIR" || echo "\$RUNTESTDIR" |
|
1434 | 1434 | > This should print the start of check-code. If this passes but the |
|
1435 | 1435 | > previous check failed, that means we found a copy of check-code at whatever |
|
1436 | 1436 | > RUNTESTSDIR ended up containing, even though it doesn't match THISTESTDIR. |
|
1437 | 1437 | > $ head -n 3 "\$RUNTESTDIR"/../contrib/check-code.py | sed 's@.!.*python3@#!USRBINENVPY@' |
|
1438 | 1438 | > #!USRBINENVPY |
|
1439 | 1439 | > # |
|
1440 | 1440 | > # check-code - a style and portability checker for Mercurial |
|
1441 | 1441 | > EOF |
|
1442 | 1442 | $ rt test-runtestdir.t |
|
1443 | 1443 | running 1 tests using 1 parallel processes |
|
1444 | 1444 | . |
|
1445 | 1445 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1446 | 1446 | |
|
1447 | 1447 | #if execbit |
|
1448 | 1448 | |
|
1449 | 1449 | test that TESTDIR is referred in PATH |
|
1450 | 1450 | |
|
1451 | 1451 | $ cat > custom-command.sh <<EOF |
|
1452 | 1452 | > #!/bin/sh |
|
1453 | 1453 | > echo "hello world" |
|
1454 | 1454 | > EOF |
|
1455 | 1455 | $ chmod +x custom-command.sh |
|
1456 | 1456 | $ cat > test-testdir-path.t <<EOF |
|
1457 | 1457 | > $ custom-command.sh |
|
1458 | 1458 | > hello world |
|
1459 | 1459 | > EOF |
|
1460 | 1460 | $ rt test-testdir-path.t |
|
1461 | 1461 | running 1 tests using 1 parallel processes |
|
1462 | 1462 | . |
|
1463 | 1463 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1464 | 1464 | |
|
1465 | 1465 | #endif |
|
1466 | 1466 | |
|
1467 | 1467 | test support for --allow-slow-tests |
|
1468 | 1468 | $ cat > test-very-slow-test.t <<EOF |
|
1469 | 1469 | > #require slow |
|
1470 | 1470 | > $ echo pass |
|
1471 | 1471 | > pass |
|
1472 | 1472 | > EOF |
|
1473 | 1473 | $ rt test-very-slow-test.t |
|
1474 | 1474 | running 1 tests using 1 parallel processes |
|
1475 | 1475 | s |
|
1476 | 1476 | Skipped test-very-slow-test.t: missing feature: allow slow tests (use --allow-slow-tests) |
|
1477 | 1477 | # Ran 0 tests, 1 skipped, 0 failed. |
|
1478 | 1478 | $ rt $HGTEST_RUN_TESTS_PURE --allow-slow-tests test-very-slow-test.t |
|
1479 | 1479 | running 1 tests using 1 parallel processes |
|
1480 | 1480 | . |
|
1481 | 1481 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1482 | 1482 | |
|
1483 | 1483 | support for running a test outside the current directory |
|
1484 | 1484 | $ mkdir nonlocal |
|
1485 | 1485 | $ cat > nonlocal/test-is-not-here.t << EOF |
|
1486 | 1486 | > $ echo pass |
|
1487 | 1487 | > pass |
|
1488 | 1488 | > EOF |
|
1489 | 1489 | $ rt nonlocal/test-is-not-here.t |
|
1490 | 1490 | running 1 tests using 1 parallel processes |
|
1491 | 1491 | . |
|
1492 | 1492 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1493 | 1493 | |
|
1494 | 1494 | support for automatically discovering test if arg is a folder |
|
1495 | 1495 | $ mkdir tmp && cd tmp |
|
1496 | 1496 | |
|
1497 | 1497 | $ cat > test-uno.t << EOF |
|
1498 | 1498 | > $ echo line |
|
1499 | 1499 | > line |
|
1500 | 1500 | > EOF |
|
1501 | 1501 | |
|
1502 | 1502 | $ cp test-uno.t test-dos.t |
|
1503 | 1503 | $ cd .. |
|
1504 | 1504 | $ cp -R tmp tmpp |
|
1505 | 1505 | $ cp tmp/test-uno.t test-solo.t |
|
1506 | 1506 | |
|
1507 | 1507 | $ rt tmp/ test-solo.t tmpp |
|
1508 | 1508 | running 5 tests using 1 parallel processes |
|
1509 | 1509 | ..... |
|
1510 | 1510 | # Ran 5 tests, 0 skipped, 0 failed. |
|
1511 | 1511 | $ rm -rf tmp tmpp |
|
1512 | 1512 | |
|
1513 | 1513 | support for running run-tests.py from another directory |
|
1514 | 1514 | $ mkdir tmp && cd tmp |
|
1515 | 1515 | |
|
1516 | 1516 | $ cat > useful-file.sh << EOF |
|
1517 | 1517 | > important command |
|
1518 | 1518 | > EOF |
|
1519 | 1519 | |
|
1520 | 1520 | $ cat > test-folder.t << EOF |
|
1521 | 1521 | > $ cat \$TESTDIR/useful-file.sh |
|
1522 | 1522 | > important command |
|
1523 | 1523 | > EOF |
|
1524 | 1524 | |
|
1525 | 1525 | $ cat > test-folder-fail.t << EOF |
|
1526 | 1526 | > $ cat \$TESTDIR/useful-file.sh |
|
1527 | 1527 | > important commando |
|
1528 | 1528 | > EOF |
|
1529 | 1529 | |
|
1530 | 1530 | $ cd .. |
|
1531 | 1531 | $ rt tmp/test-*.t |
|
1532 | 1532 | running 2 tests using 1 parallel processes |
|
1533 | 1533 | |
|
1534 | 1534 | --- $TESTTMP/anothertests/tmp/test-folder-fail.t |
|
1535 | 1535 | +++ $TESTTMP/anothertests/tmp/test-folder-fail.t.err |
|
1536 | 1536 | @@ -1,2 +1,2 @@ |
|
1537 | 1537 | $ cat $TESTDIR/useful-file.sh |
|
1538 | 1538 | - important commando |
|
1539 | 1539 | + important command |
|
1540 | 1540 | |
|
1541 | 1541 | ERROR: test-folder-fail.t output changed |
|
1542 | 1542 | !. |
|
1543 | 1543 | Failed test-folder-fail.t: output changed |
|
1544 | 1544 | # Ran 2 tests, 0 skipped, 1 failed. |
|
1545 | 1545 | python hash seed: * (glob) |
|
1546 | 1546 | [1] |
|
1547 | 1547 | |
|
1548 | 1548 | support for bisecting failed tests automatically |
|
1549 | 1549 | $ hg init bisect |
|
1550 | 1550 | $ cd bisect |
|
1551 | 1551 | $ cat >> test-bisect.t <<EOF |
|
1552 | 1552 | > $ echo pass |
|
1553 | 1553 | > pass |
|
1554 | 1554 | > EOF |
|
1555 | 1555 | $ hg add test-bisect.t |
|
1556 | 1556 | $ hg ci -m 'good' |
|
1557 | 1557 | $ cat >> test-bisect.t <<EOF |
|
1558 | 1558 | > $ echo pass |
|
1559 | 1559 | > fail |
|
1560 | 1560 | > EOF |
|
1561 | 1561 | $ hg ci -m 'bad' |
|
1562 | 1562 | $ rt --known-good-rev=0 test-bisect.t |
|
1563 | 1563 | running 1 tests using 1 parallel processes |
|
1564 | 1564 | |
|
1565 | 1565 | --- $TESTTMP/anothertests/bisect/test-bisect.t |
|
1566 | 1566 | +++ $TESTTMP/anothertests/bisect/test-bisect.t.err |
|
1567 | 1567 | @@ -1,4 +1,4 @@ |
|
1568 | 1568 | $ echo pass |
|
1569 | 1569 | pass |
|
1570 | 1570 | $ echo pass |
|
1571 | 1571 | - fail |
|
1572 | 1572 | + pass |
|
1573 | 1573 | |
|
1574 | 1574 | ERROR: test-bisect.t output changed |
|
1575 | 1575 | ! |
|
1576 | 1576 | Failed test-bisect.t: output changed |
|
1577 | 1577 | test-bisect.t broken by 72cbf122d116 (bad) |
|
1578 | 1578 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1579 | 1579 | python hash seed: * (glob) |
|
1580 | 1580 | [1] |
|
1581 | 1581 | |
|
1582 | 1582 | $ cd .. |
|
1583 | 1583 | |
|
1584 | 1584 | support bisecting a separate repo |
|
1585 | 1585 | |
|
1586 | 1586 | $ hg init bisect-dependent |
|
1587 | 1587 | $ cd bisect-dependent |
|
1588 | 1588 | $ cat > test-bisect-dependent.t <<EOF |
|
1589 | 1589 | > $ tail -1 \$TESTDIR/../bisect/test-bisect.t |
|
1590 | 1590 | > pass |
|
1591 | 1591 | > EOF |
|
1592 | 1592 | $ hg commit -Am dependent test-bisect-dependent.t |
|
1593 | 1593 | |
|
1594 | 1594 | $ rt --known-good-rev=0 test-bisect-dependent.t |
|
1595 | 1595 | running 1 tests using 1 parallel processes |
|
1596 | 1596 | |
|
1597 | 1597 | --- $TESTTMP/anothertests/bisect-dependent/test-bisect-dependent.t |
|
1598 | 1598 | +++ $TESTTMP/anothertests/bisect-dependent/test-bisect-dependent.t.err |
|
1599 | 1599 | @@ -1,2 +1,2 @@ |
|
1600 | 1600 | $ tail -1 $TESTDIR/../bisect/test-bisect.t |
|
1601 | 1601 | - pass |
|
1602 | 1602 | + fail |
|
1603 | 1603 | |
|
1604 | 1604 | ERROR: test-bisect-dependent.t output changed |
|
1605 | 1605 | ! |
|
1606 | 1606 | Failed test-bisect-dependent.t: output changed |
|
1607 | 1607 | Failed to identify failure point for test-bisect-dependent.t |
|
1608 | 1608 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1609 | 1609 | python hash seed: * (glob) |
|
1610 | 1610 | [1] |
|
1611 | 1611 | |
|
1612 | 1612 | $ rt --bisect-repo=../test-bisect test-bisect-dependent.t |
|
1613 | 1613 | usage: run-tests.py [options] [tests] |
|
1614 | 1614 | run-tests.py: error: --bisect-repo cannot be used without --known-good-rev |
|
1615 | 1615 | [2] |
|
1616 | 1616 | |
|
1617 | 1617 | $ rt --known-good-rev=0 --bisect-repo=../bisect test-bisect-dependent.t |
|
1618 | 1618 | running 1 tests using 1 parallel processes |
|
1619 | 1619 | |
|
1620 | 1620 | --- $TESTTMP/anothertests/bisect-dependent/test-bisect-dependent.t |
|
1621 | 1621 | +++ $TESTTMP/anothertests/bisect-dependent/test-bisect-dependent.t.err |
|
1622 | 1622 | @@ -1,2 +1,2 @@ |
|
1623 | 1623 | $ tail -1 $TESTDIR/../bisect/test-bisect.t |
|
1624 | 1624 | - pass |
|
1625 | 1625 | + fail |
|
1626 | 1626 | |
|
1627 | 1627 | ERROR: test-bisect-dependent.t output changed |
|
1628 | 1628 | ! |
|
1629 | 1629 | Failed test-bisect-dependent.t: output changed |
|
1630 | 1630 | test-bisect-dependent.t broken by 72cbf122d116 (bad) |
|
1631 | 1631 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1632 | 1632 | python hash seed: * (glob) |
|
1633 | 1633 | [1] |
|
1634 | 1634 | |
|
1635 | 1635 | $ cd .. |
|
1636 | 1636 | |
|
1637 | 1637 | Test a broken #if statement doesn't break run-tests threading. |
|
1638 | 1638 | ============================================================== |
|
1639 | 1639 | $ mkdir broken |
|
1640 | 1640 | $ cd broken |
|
1641 | 1641 | $ cat > test-broken.t <<EOF |
|
1642 | 1642 | > true |
|
1643 | 1643 | > #if notarealhghavefeature |
|
1644 | 1644 | > $ false |
|
1645 | 1645 | > #endif |
|
1646 | 1646 | > EOF |
|
1647 | 1647 | $ for f in 1 2 3 4 ; do |
|
1648 | 1648 | > cat > test-works-$f.t <<EOF |
|
1649 | 1649 | > This is test case $f |
|
1650 | 1650 | > $ sleep 1 |
|
1651 | 1651 | > EOF |
|
1652 | 1652 | > done |
|
1653 | 1653 | $ rt -j 2 |
|
1654 | 1654 | running 5 tests using 2 parallel processes |
|
1655 | 1655 | .... |
|
1656 | 1656 | # Ran 5 tests, 0 skipped, 0 failed. |
|
1657 | 1657 | skipped: unknown feature: notarealhghavefeature |
|
1658 | 1658 | |
|
1659 | 1659 | $ cd .. |
|
1660 | 1660 | $ rm -rf broken |
|
1661 | 1661 | |
|
1662 | 1662 | Test cases in .t files |
|
1663 | 1663 | ====================== |
|
1664 | 1664 | $ mkdir cases |
|
1665 | 1665 | $ cd cases |
|
1666 | 1666 | $ cat > test-cases-abc.t <<'EOF' |
|
1667 | 1667 | > #testcases A B C |
|
1668 | 1668 | > $ V=B |
|
1669 | 1669 | > #if A |
|
1670 | 1670 | > $ V=A |
|
1671 | 1671 | > #endif |
|
1672 | 1672 | > #if C |
|
1673 | 1673 | > $ V=C |
|
1674 | 1674 | > #endif |
|
1675 | 1675 | > $ echo $V | sed 's/A/C/' |
|
1676 | 1676 | > C |
|
1677 | 1677 | > #if C |
|
1678 | 1678 | > $ [ $V = C ] |
|
1679 | 1679 | > #endif |
|
1680 | 1680 | > #if A |
|
1681 | 1681 | > $ [ $V = C ] |
|
1682 | 1682 | > [1] |
|
1683 | 1683 | > #endif |
|
1684 | 1684 | > #if no-C |
|
1685 | 1685 | > $ [ $V = C ] |
|
1686 | 1686 | > [1] |
|
1687 | 1687 | > #endif |
|
1688 | 1688 | > $ [ $V = D ] |
|
1689 | 1689 | > [1] |
|
1690 | 1690 | > EOF |
|
1691 | 1691 | $ rt |
|
1692 | 1692 | running 3 tests using 1 parallel processes |
|
1693 | 1693 | . |
|
1694 | 1694 | --- $TESTTMP/anothertests/cases/test-cases-abc.t |
|
1695 | 1695 | +++ $TESTTMP/anothertests/cases/test-cases-abc.t#B.err |
|
1696 | 1696 | @@ -7,7 +7,7 @@ |
|
1697 | 1697 | $ V=C |
|
1698 | 1698 | #endif |
|
1699 | 1699 | $ echo $V | sed 's/A/C/' |
|
1700 | 1700 | - C |
|
1701 | 1701 | + B |
|
1702 | 1702 | #if C |
|
1703 | 1703 | $ [ $V = C ] |
|
1704 | 1704 | #endif |
|
1705 | 1705 | |
|
1706 | 1706 | ERROR: test-cases-abc.t#B output changed |
|
1707 | 1707 | !. |
|
1708 | 1708 | Failed test-cases-abc.t#B: output changed |
|
1709 | 1709 | # Ran 3 tests, 0 skipped, 1 failed. |
|
1710 | 1710 | python hash seed: * (glob) |
|
1711 | 1711 | [1] |
|
1712 | 1712 | |
|
1713 | 1713 | --restart works |
|
1714 | 1714 | |
|
1715 | 1715 | $ rt --restart |
|
1716 | 1716 | running 2 tests using 1 parallel processes |
|
1717 | 1717 | |
|
1718 | 1718 | --- $TESTTMP/anothertests/cases/test-cases-abc.t |
|
1719 | 1719 | +++ $TESTTMP/anothertests/cases/test-cases-abc.t#B.err |
|
1720 | 1720 | @@ -7,7 +7,7 @@ |
|
1721 | 1721 | $ V=C |
|
1722 | 1722 | #endif |
|
1723 | 1723 | $ echo $V | sed 's/A/C/' |
|
1724 | 1724 | - C |
|
1725 | 1725 | + B |
|
1726 | 1726 | #if C |
|
1727 | 1727 | $ [ $V = C ] |
|
1728 | 1728 | #endif |
|
1729 | 1729 | |
|
1730 | 1730 | ERROR: test-cases-abc.t#B output changed |
|
1731 | 1731 | !. |
|
1732 | 1732 | Failed test-cases-abc.t#B: output changed |
|
1733 | 1733 | # Ran 2 tests, 0 skipped, 1 failed. |
|
1734 | 1734 | python hash seed: * (glob) |
|
1735 | 1735 | [1] |
|
1736 | 1736 | |
|
1737 | 1737 | --restart works with outputdir |
|
1738 | 1738 | |
|
1739 | 1739 | $ mkdir output |
|
1740 | 1740 | $ mv test-cases-abc.t#B.err output |
|
1741 | 1741 | $ rt --restart --outputdir output |
|
1742 | 1742 | running 2 tests using 1 parallel processes |
|
1743 | 1743 | |
|
1744 | 1744 | --- $TESTTMP/anothertests/cases/test-cases-abc.t |
|
1745 | 1745 | +++ $TESTTMP/anothertests/cases/output/test-cases-abc.t#B.err |
|
1746 | 1746 | @@ -7,7 +7,7 @@ |
|
1747 | 1747 | $ V=C |
|
1748 | 1748 | #endif |
|
1749 | 1749 | $ echo $V | sed 's/A/C/' |
|
1750 | 1750 | - C |
|
1751 | 1751 | + B |
|
1752 | 1752 | #if C |
|
1753 | 1753 | $ [ $V = C ] |
|
1754 | 1754 | #endif |
|
1755 | 1755 | |
|
1756 | 1756 | ERROR: test-cases-abc.t#B output changed |
|
1757 | 1757 | !. |
|
1758 | 1758 | Failed test-cases-abc.t#B: output changed |
|
1759 | 1759 | # Ran 2 tests, 0 skipped, 1 failed. |
|
1760 | 1760 | python hash seed: * (glob) |
|
1761 | 1761 | [1] |
|
1762 | 1762 | |
|
1763 | 1763 | Test TESTCASE variable |
|
1764 | 1764 | |
|
1765 | 1765 | $ cat > test-cases-ab.t <<'EOF' |
|
1766 | 1766 | > $ dostuff() { |
|
1767 | 1767 | > > echo "In case $TESTCASE" |
|
1768 | 1768 | > > } |
|
1769 | 1769 | > #testcases A B |
|
1770 | 1770 | > #if A |
|
1771 | 1771 | > $ dostuff |
|
1772 | 1772 | > In case A |
|
1773 | 1773 | > #endif |
|
1774 | 1774 | > #if B |
|
1775 | 1775 | > $ dostuff |
|
1776 | 1776 | > In case B |
|
1777 | 1777 | > #endif |
|
1778 | 1778 | > EOF |
|
1779 | 1779 | $ rt test-cases-ab.t |
|
1780 | 1780 | running 2 tests using 1 parallel processes |
|
1781 | 1781 | .. |
|
1782 | 1782 | # Ran 2 tests, 0 skipped, 0 failed. |
|
1783 | 1783 | |
|
1784 | 1784 | Support running a specific test case |
|
1785 | 1785 | |
|
1786 | 1786 | $ rt "test-cases-abc.t#B" |
|
1787 | 1787 | running 1 tests using 1 parallel processes |
|
1788 | 1788 | |
|
1789 | 1789 | --- $TESTTMP/anothertests/cases/test-cases-abc.t |
|
1790 | 1790 | +++ $TESTTMP/anothertests/cases/test-cases-abc.t#B.err |
|
1791 | 1791 | @@ -7,7 +7,7 @@ |
|
1792 | 1792 | $ V=C |
|
1793 | 1793 | #endif |
|
1794 | 1794 | $ echo $V | sed 's/A/C/' |
|
1795 | 1795 | - C |
|
1796 | 1796 | + B |
|
1797 | 1797 | #if C |
|
1798 | 1798 | $ [ $V = C ] |
|
1799 | 1799 | #endif |
|
1800 | 1800 | |
|
1801 | 1801 | ERROR: test-cases-abc.t#B output changed |
|
1802 | 1802 | ! |
|
1803 | 1803 | Failed test-cases-abc.t#B: output changed |
|
1804 | 1804 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1805 | 1805 | python hash seed: * (glob) |
|
1806 | 1806 | [1] |
|
1807 | 1807 | |
|
1808 | 1808 | Support running multiple test cases in the same file |
|
1809 | 1809 | |
|
1810 | 1810 | $ rt test-cases-abc.t#B test-cases-abc.t#C |
|
1811 | 1811 | running 2 tests using 1 parallel processes |
|
1812 | 1812 | |
|
1813 | 1813 | --- $TESTTMP/anothertests/cases/test-cases-abc.t |
|
1814 | 1814 | +++ $TESTTMP/anothertests/cases/test-cases-abc.t#B.err |
|
1815 | 1815 | @@ -7,7 +7,7 @@ |
|
1816 | 1816 | $ V=C |
|
1817 | 1817 | #endif |
|
1818 | 1818 | $ echo $V | sed 's/A/C/' |
|
1819 | 1819 | - C |
|
1820 | 1820 | + B |
|
1821 | 1821 | #if C |
|
1822 | 1822 | $ [ $V = C ] |
|
1823 | 1823 | #endif |
|
1824 | 1824 | |
|
1825 | 1825 | ERROR: test-cases-abc.t#B output changed |
|
1826 | 1826 | !. |
|
1827 | 1827 | Failed test-cases-abc.t#B: output changed |
|
1828 | 1828 | # Ran 2 tests, 0 skipped, 1 failed. |
|
1829 | 1829 | python hash seed: * (glob) |
|
1830 | 1830 | [1] |
|
1831 | 1831 | |
|
1832 | 1832 | Support ignoring invalid test cases |
|
1833 | 1833 | |
|
1834 | 1834 | $ rt test-cases-abc.t#B test-cases-abc.t#D |
|
1835 | 1835 | running 1 tests using 1 parallel processes |
|
1836 | 1836 | |
|
1837 | 1837 | --- $TESTTMP/anothertests/cases/test-cases-abc.t |
|
1838 | 1838 | +++ $TESTTMP/anothertests/cases/test-cases-abc.t#B.err |
|
1839 | 1839 | @@ -7,7 +7,7 @@ |
|
1840 | 1840 | $ V=C |
|
1841 | 1841 | #endif |
|
1842 | 1842 | $ echo $V | sed 's/A/C/' |
|
1843 | 1843 | - C |
|
1844 | 1844 | + B |
|
1845 | 1845 | #if C |
|
1846 | 1846 | $ [ $V = C ] |
|
1847 | 1847 | #endif |
|
1848 | 1848 | |
|
1849 | 1849 | ERROR: test-cases-abc.t#B output changed |
|
1850 | 1850 | ! |
|
1851 | 1851 | Failed test-cases-abc.t#B: output changed |
|
1852 | 1852 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1853 | 1853 | python hash seed: * (glob) |
|
1854 | 1854 | [1] |
|
1855 | 1855 | |
|
1856 | 1856 | Support running complex test cases names |
|
1857 | 1857 | |
|
1858 | 1858 | $ cat > test-cases-advanced-cases.t <<'EOF' |
|
1859 | 1859 | > #testcases simple case-with-dashes casewith_-.chars |
|
1860 | 1860 | > $ echo $TESTCASE |
|
1861 | 1861 | > simple |
|
1862 | 1862 | > EOF |
|
1863 | 1863 | |
|
1864 | 1864 | $ cat test-cases-advanced-cases.t |
|
1865 | 1865 | #testcases simple case-with-dashes casewith_-.chars |
|
1866 | 1866 | $ echo $TESTCASE |
|
1867 | 1867 | simple |
|
1868 | 1868 | |
|
1869 | 1869 | $ rt test-cases-advanced-cases.t |
|
1870 | 1870 | running 3 tests using 1 parallel processes |
|
1871 | 1871 | |
|
1872 | 1872 | --- $TESTTMP/anothertests/cases/test-cases-advanced-cases.t |
|
1873 | 1873 | +++ $TESTTMP/anothertests/cases/test-cases-advanced-cases.t#case-with-dashes.err |
|
1874 | 1874 | @@ -1,3 +1,3 @@ |
|
1875 | 1875 | #testcases simple case-with-dashes casewith_-.chars |
|
1876 | 1876 | $ echo $TESTCASE |
|
1877 | 1877 | - simple |
|
1878 | 1878 | + case-with-dashes |
|
1879 | 1879 | |
|
1880 | 1880 | ERROR: test-cases-advanced-cases.t#case-with-dashes output changed |
|
1881 | 1881 | ! |
|
1882 | 1882 | --- $TESTTMP/anothertests/cases/test-cases-advanced-cases.t |
|
1883 | 1883 | +++ $TESTTMP/anothertests/cases/test-cases-advanced-cases.t#casewith_-.chars.err |
|
1884 | 1884 | @@ -1,3 +1,3 @@ |
|
1885 | 1885 | #testcases simple case-with-dashes casewith_-.chars |
|
1886 | 1886 | $ echo $TESTCASE |
|
1887 | 1887 | - simple |
|
1888 | 1888 | + casewith_-.chars |
|
1889 | 1889 | |
|
1890 | 1890 | ERROR: test-cases-advanced-cases.t#casewith_-.chars output changed |
|
1891 | 1891 | !. |
|
1892 | 1892 | Failed test-cases-advanced-cases.t#case-with-dashes: output changed |
|
1893 | 1893 | Failed test-cases-advanced-cases.t#casewith_-.chars: output changed |
|
1894 | 1894 | # Ran 3 tests, 0 skipped, 2 failed. |
|
1895 | 1895 | python hash seed: * (glob) |
|
1896 | 1896 | [1] |
|
1897 | 1897 | |
|
1898 | 1898 | $ rt "test-cases-advanced-cases.t#case-with-dashes" |
|
1899 | 1899 | running 1 tests using 1 parallel processes |
|
1900 | 1900 | |
|
1901 | 1901 | --- $TESTTMP/anothertests/cases/test-cases-advanced-cases.t |
|
1902 | 1902 | +++ $TESTTMP/anothertests/cases/test-cases-advanced-cases.t#case-with-dashes.err |
|
1903 | 1903 | @@ -1,3 +1,3 @@ |
|
1904 | 1904 | #testcases simple case-with-dashes casewith_-.chars |
|
1905 | 1905 | $ echo $TESTCASE |
|
1906 | 1906 | - simple |
|
1907 | 1907 | + case-with-dashes |
|
1908 | 1908 | |
|
1909 | 1909 | ERROR: test-cases-advanced-cases.t#case-with-dashes output changed |
|
1910 | 1910 | ! |
|
1911 | 1911 | Failed test-cases-advanced-cases.t#case-with-dashes: output changed |
|
1912 | 1912 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1913 | 1913 | python hash seed: * (glob) |
|
1914 | 1914 | [1] |
|
1915 | 1915 | |
|
1916 | 1916 | $ rt "test-cases-advanced-cases.t#casewith_-.chars" |
|
1917 | 1917 | running 1 tests using 1 parallel processes |
|
1918 | 1918 | |
|
1919 | 1919 | --- $TESTTMP/anothertests/cases/test-cases-advanced-cases.t |
|
1920 | 1920 | +++ $TESTTMP/anothertests/cases/test-cases-advanced-cases.t#casewith_-.chars.err |
|
1921 | 1921 | @@ -1,3 +1,3 @@ |
|
1922 | 1922 | #testcases simple case-with-dashes casewith_-.chars |
|
1923 | 1923 | $ echo $TESTCASE |
|
1924 | 1924 | - simple |
|
1925 | 1925 | + casewith_-.chars |
|
1926 | 1926 | |
|
1927 | 1927 | ERROR: test-cases-advanced-cases.t#casewith_-.chars output changed |
|
1928 | 1928 | ! |
|
1929 | 1929 | Failed test-cases-advanced-cases.t#casewith_-.chars: output changed |
|
1930 | 1930 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1931 | 1931 | python hash seed: * (glob) |
|
1932 | 1932 | [1] |
|
1933 | 1933 | |
|
1934 | 1934 | Test automatic pattern replacement |
|
1935 | 1935 | ================================== |
|
1936 | 1936 | |
|
1937 | 1937 | $ cat << EOF >> common-pattern.py |
|
1938 | 1938 | > substitutions = [ |
|
1939 | 1939 | > (br'foo-(.*)\\b', |
|
1940 | 1940 | > br'\$XXX=\\1\$'), |
|
1941 | 1941 | > (br'bar\\n', |
|
1942 | 1942 | > br'\$YYY$\\n'), |
|
1943 | 1943 | > ] |
|
1944 | 1944 | > EOF |
|
1945 | 1945 | |
|
1946 | 1946 | $ cat << EOF >> test-substitution.t |
|
1947 | 1947 | > $ echo foo-12 |
|
1948 | 1948 | > \$XXX=12$ |
|
1949 | 1949 | > $ echo foo-42 |
|
1950 | 1950 | > \$XXX=42$ |
|
1951 | 1951 | > $ echo bar prior |
|
1952 | 1952 | > bar prior |
|
1953 | 1953 | > $ echo lastbar |
|
1954 | 1954 | > last\$YYY$ |
|
1955 | 1955 | > $ echo foo-bar foo-baz |
|
1956 | 1956 | > EOF |
|
1957 | 1957 | |
|
1958 | 1958 | $ rt test-substitution.t |
|
1959 | 1959 | running 1 tests using 1 parallel processes |
|
1960 | 1960 | |
|
1961 | 1961 | --- $TESTTMP/anothertests/cases/test-substitution.t |
|
1962 | 1962 | +++ $TESTTMP/anothertests/cases/test-substitution.t.err |
|
1963 | 1963 | @@ -7,3 +7,4 @@ |
|
1964 | 1964 | $ echo lastbar |
|
1965 | 1965 | last$YYY$ |
|
1966 | 1966 | $ echo foo-bar foo-baz |
|
1967 | 1967 | + $XXX=bar foo-baz$ |
|
1968 | 1968 | |
|
1969 | 1969 | ERROR: test-substitution.t output changed |
|
1970 | 1970 | ! |
|
1971 | 1971 | Failed test-substitution.t: output changed |
|
1972 | 1972 | # Ran 1 tests, 0 skipped, 1 failed. |
|
1973 | 1973 | python hash seed: * (glob) |
|
1974 | 1974 | [1] |
|
1975 | 1975 | |
|
1976 | 1976 | --extra-config-opt works |
|
1977 | 1977 | |
|
1978 | 1978 | $ cat << EOF >> test-config-opt.t |
|
1979 | 1979 | > $ hg init test-config-opt |
|
1980 | 1980 | > $ hg -R test-config-opt purge |
|
1981 | 1981 | > $ echo "HGTESTEXTRAEXTENSIONS: \$HGTESTEXTRAEXTENSIONS" |
|
1982 | 1982 | > HGTESTEXTRAEXTENSIONS: purge |
|
1983 | 1983 | > EOF |
|
1984 | 1984 | |
|
1985 | 1985 | $ rt --extra-config-opt extensions.purge= \ |
|
1986 | 1986 | > --extra-config-opt not.an.extension=True test-config-opt.t |
|
1987 | 1987 | running 1 tests using 1 parallel processes |
|
1988 | 1988 | . |
|
1989 | 1989 | # Ran 1 tests, 0 skipped, 0 failed. |
|
1990 | 1990 | |
|
1991 | 1991 | Test conditional output matching |
|
1992 | 1992 | ================================ |
|
1993 | 1993 | |
|
1994 | 1994 | $ cat << EOF >> test-conditional-matching.t |
|
1995 | 1995 | > #testcases foo bar |
|
1996 | 1996 | > $ echo richtig |
|
1997 | 1997 | > richtig (true !) |
|
1998 | 1998 | > $ echo falsch |
|
1999 | 1999 | > falsch (false !) |
|
2000 | 2000 | > #if foo |
|
2001 | 2001 | > $ echo arthur |
|
2002 | 2002 | > arthur (bar !) |
|
2003 | 2003 | > #endif |
|
2004 | 2004 | > $ echo celeste |
|
2005 | 2005 | > celeste (foo !) |
|
2006 | 2006 | > $ echo zephir |
|
2007 | 2007 | > zephir (bar !) |
|
2008 | 2008 | > EOF |
|
2009 | 2009 | |
|
2010 | 2010 | $ rt test-conditional-matching.t |
|
2011 | 2011 | running 2 tests using 1 parallel processes |
|
2012 | 2012 | |
|
2013 | 2013 | --- $TESTTMP/anothertests/cases/test-conditional-matching.t |
|
2014 | 2014 | +++ $TESTTMP/anothertests/cases/test-conditional-matching.t#bar.err |
|
2015 | 2015 | @@ -3,11 +3,13 @@ |
|
2016 | 2016 | richtig (true !) |
|
2017 | 2017 | $ echo falsch |
|
2018 | 2018 | falsch (false !) |
|
2019 | 2019 | + falsch |
|
2020 | 2020 | #if foo |
|
2021 | 2021 | $ echo arthur |
|
2022 | 2022 | arthur \(bar !\) (re) |
|
2023 | 2023 | #endif |
|
2024 | 2024 | $ echo celeste |
|
2025 | 2025 | celeste \(foo !\) (re) |
|
2026 | 2026 | + celeste |
|
2027 | 2027 | $ echo zephir |
|
2028 | 2028 | zephir \(bar !\) (re) |
|
2029 | 2029 | |
|
2030 | 2030 | ERROR: test-conditional-matching.t#bar output changed |
|
2031 | 2031 | ! |
|
2032 | 2032 | --- $TESTTMP/anothertests/cases/test-conditional-matching.t |
|
2033 | 2033 | +++ $TESTTMP/anothertests/cases/test-conditional-matching.t#foo.err |
|
2034 | 2034 | @@ -3,11 +3,14 @@ |
|
2035 | 2035 | richtig (true !) |
|
2036 | 2036 | $ echo falsch |
|
2037 | 2037 | falsch (false !) |
|
2038 | 2038 | + falsch |
|
2039 | 2039 | #if foo |
|
2040 | 2040 | $ echo arthur |
|
2041 | 2041 | arthur \(bar !\) (re) |
|
2042 | 2042 | + arthur |
|
2043 | 2043 | #endif |
|
2044 | 2044 | $ echo celeste |
|
2045 | 2045 | celeste \(foo !\) (re) |
|
2046 | 2046 | $ echo zephir |
|
2047 | 2047 | zephir \(bar !\) (re) |
|
2048 | 2048 | + zephir |
|
2049 | 2049 | |
|
2050 | 2050 | ERROR: test-conditional-matching.t#foo output changed |
|
2051 | 2051 | ! |
|
2052 | 2052 | Failed test-conditional-matching.t#bar: output changed |
|
2053 | 2053 | Failed test-conditional-matching.t#foo: output changed |
|
2054 | 2054 | # Ran 2 tests, 0 skipped, 2 failed. |
|
2055 | 2055 | python hash seed: * (glob) |
|
2056 | 2056 | [1] |
|
2057 | 2057 | |
|
2058 | 2058 | Test that a proper "python" has been set up |
|
2059 | 2059 | =========================================== |
|
2060 | 2060 | |
|
2061 | 2061 | (with a small check-code work around) |
|
2062 | 2062 | $ printf "#!/usr/bi" > test-py3.tmp |
|
2063 | 2063 | $ printf "n/en" >> test-py3.tmp |
|
2064 | 2064 | $ cat << EOF >> test-py3.tmp |
|
2065 | 2065 | > v python3 |
|
2066 | 2066 | > import sys |
|
2067 | 2067 | > print('.'.join(str(x) for x in sys.version_info)) |
|
2068 | 2068 | > EOF |
|
2069 | 2069 | $ mv test-py3.tmp test-py3.py |
|
2070 | 2070 | $ chmod +x test-py3.py |
|
2071 | 2071 | |
|
2072 | 2072 | (with a small check-code work around) |
|
2073 | 2073 | $ printf "#!/usr/bi" > test-py.tmp |
|
2074 | 2074 | $ printf "n/en" >> test-py.tmp |
|
2075 | 2075 | $ cat << EOF >> test-py.tmp |
|
2076 | 2076 | > v python |
|
2077 | 2077 | > import sys |
|
2078 | 2078 | > print('.'.join(str(x) for x in sys.version_info)) |
|
2079 | 2079 | > EOF |
|
2080 | 2080 | $ mv test-py.tmp test-py.py |
|
2081 | 2081 | $ chmod +x test-py.py |
|
2082 | 2082 | |
|
2083 | 2083 | $ ./test-py3.py |
|
2084 | 2084 | 3.* (glob) |
|
2085 | 2085 | $ ./test-py.py |
|
2086 | 2086 | 2.* (glob) (no-py3 !) |
|
2087 | 2087 | 3.* (glob) (py3 !) |
General Comments 0
You need to be logged in to leave comments.
Login now