Mercurial > hg
annotate tests/filtertraceback.py @ 47584:ee1fc8f970e6
run-tests: introduce a `HGTEST_REAL_HG` variable for test
It turns out that currently, `hg` and `which hg` can point to different things
because `hg` is an alias… This is annoying because script and pieces of test
are unknowingly using the wrong `hg`.
We will fix it in another changeset. However some test actually need to use a
real `hg` binary and not some `chg` or `rhg` equivalent. So we introduce a new
variable with the right value and we put it to us in the appropriate location.
Differential Revision: https://phab.mercurial-scm.org/D11049
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Fri, 09 Jul 2021 20:03:46 +0200 |
parents | c102b704edb5 |
children | 6000f5b25c9b |
rev | line source |
---|---|
45830
c102b704edb5
global: use python3 in shebangs
Gregory Szorc <gregory.szorc@gmail.com>
parents:
44654
diff
changeset
|
1 #!/usr/bin/env python3 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 # Filters traceback lines from stdin. |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 from __future__ import absolute_import, print_function |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
7 import io |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 import sys |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
9 |
44654
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
10 if sys.version_info[0] >= 3: |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
11 # Prevent \r from being inserted on Windows. |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
12 sys.stdout = io.TextIOWrapper( |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
13 sys.stdout.buffer, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
14 sys.stdout.encoding, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
15 sys.stdout.errors, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
16 newline="\n", |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
17 line_buffering=sys.stdout.line_buffering, |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
18 ) |
d359f0d1a3d3
tests: force \n newlines when writing to sys.stdout
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41462
diff
changeset
|
19 |
41462
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 for line in sys.stdin: |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 if state == 'none': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 if line.startswith('Traceback '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 elif state == 'tb': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 if line.startswith(' File '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 state = 'file' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
30 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 elif not line.startswith(' '): |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 state = 'none' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 elif state == 'file': |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 # Ignore lines after " File " |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 state = 'tb' |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 continue |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 |
9b2b8794f801
hgweb: log error before attempting I/O
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 print(line, end='') |