Mercurial > hg
annotate tests/heredoctest.py @ 46492:7289eac777ec stable
hooks: introduce a `:run-with-plain` option for hooks
This option control if HGPLAIN should be set or not for the hooks. This is the
first step to give user some control of the HGPLAIN setting for they hooks.
Some hooks (eg: consistency checking) deserve to be run with HGPLAIN, some other
(eg: user set visual helper) might need to respect the user config and setting.
So both usage are valid and we need to restore the ability to run -without-
HGPLAIN that got lost in Mercurial 5.7.
This does not offer a way to restore the pre-5.7 behavior yet (respect whatever
HGPLAIN setting from the shell), this will be dealt with in the next changeset.
The option name is a bit verbose because implementing this highlighs the need
for another option: `:run-if-plain`. That would make it possible for some hooks
to be easily disabled if HG PLAIN is set. However such option would be a new
feature, not something introduced to mitigate a behavior change introduced in
5.7, so the `:run-if-plain` option belong to the default branch and is not part
of this series.
Differential Revision: https://phab.mercurial-scm.org/D9981
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 10 Feb 2021 23:21:21 +0100 |
parents | 2372284d9457 |
children | 6000f5b25c9b |
rev | line source |
---|---|
29485
6a98f9408a50
py3: make files use absolute_import and print_function
Pulkit Goyal <7895pulkit@gmail.com>
parents:
27297
diff
changeset
|
1 from __future__ import absolute_import, print_function |
27297
4179d054b3e9
tests: use absolute_import for heredoctest.py
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25032
diff
changeset
|
2 |
15434
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
3 import sys |
15247
3cd1605e9d8e
tests: remove temp doctest file when finished running it
Idan Kamara <idankk86@gmail.com>
parents:
15235
diff
changeset
|
4 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40318
diff
changeset
|
5 |
40318
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
6 def flush(): |
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
7 sys.stdout.flush() |
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
8 sys.stderr.flush() |
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
9 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
40318
diff
changeset
|
10 |
15434
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
11 globalvars = {} |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
12 lines = sys.stdin.readlines() |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
13 while lines: |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
14 l = lines.pop(0) |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
15 if l.startswith('SALT'): |
25032
1db2127d2373
heredoctest: 2to3 -w -f numliterals -f except -f print tests/heredoctest.py
Augie Fackler <augie@google.com>
parents:
22565
diff
changeset
|
16 print(l[:-1]) |
15434
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
17 elif l.startswith('>>> '): |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
18 snippet = l[4:] |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
19 while lines and lines[0].startswith('... '): |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
20 l = lines.pop(0) |
22565
8d45a42b0c0f
heredoctest: do not append extra newline character to continuation line
Yuya Nishihara <yuya@tcha.org>
parents:
22564
diff
changeset
|
21 snippet += l[4:] |
15434
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
22 c = compile(snippet, '<heredoc>', 'single') |
5635a4017061
run-tests: replace inline python handling with more native scheme
Matt Mackall <mpm@selenic.com>
parents:
15398
diff
changeset
|
23 try: |
40318
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
24 flush() |
25032
1db2127d2373
heredoctest: 2to3 -w -f numliterals -f except -f print tests/heredoctest.py
Augie Fackler <augie@google.com>
parents:
22565
diff
changeset
|
25 exec(c, globalvars) |
40318
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
26 flush() |
25032
1db2127d2373
heredoctest: 2to3 -w -f numliterals -f except -f print tests/heredoctest.py
Augie Fackler <augie@google.com>
parents:
22565
diff
changeset
|
27 except Exception as inst: |
40318
55fd0fefbec4
py3: flush std streams before/after running user code in heredoctest.py
Yuya Nishihara <yuya@tcha.org>
parents:
29485
diff
changeset
|
28 flush() |
25032
1db2127d2373
heredoctest: 2to3 -w -f numliterals -f except -f print tests/heredoctest.py
Augie Fackler <augie@google.com>
parents:
22565
diff
changeset
|
29 print(repr(inst)) |