Mercurial > hg
changeset 45013:bd0f122f3f51 stable
run-tests: fix escapes with conditions
Before this fix, escapes with conditions in tests failed like this on Python 3:
$ $PYTHON -c 'from mercurial.utils.procutil import stdout; stdout.write(b"\xff")'
- \xff (no-eol) (esc) (true !)
+ \xff (no-eol) (esc)
The unicode_escape encoding decodes br'\xff' to u'\xff'. To convert the first
256 code points to bytes with the same ordinal, the latin-1 encoding must be
used.
Escapes without conditions already worked before on Python 3, but not through
`el == l` a few lines below the changed line in run-tests.py. I didn’t
investigate further.
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Mon, 29 Jun 2020 02:05:12 +0200 |
parents | 5c0d5b48e58c |
children | 4a503c1b664a 697212a830fb |
files | tests/run-tests.py tests/test-unified-test.t |
diffstat | 2 files changed, 11 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/run-tests.py Sun Jun 28 18:02:45 2020 +0200 +++ b/tests/run-tests.py Mon Jun 29 02:05:12 2020 +0200 @@ -2069,7 +2069,7 @@ if el.endswith(b" (esc)\n"): if PYTHON3: el = el[:-7].decode('unicode_escape') + '\n' - el = el.encode('utf-8') + el = el.encode('latin-1') else: el = el[:-7].decode('string-escape') + '\n' if el == l or os.name == 'nt' and el[:-1] + b'\r\n' == l:
--- a/tests/test-unified-test.t Sun Jun 28 18:02:45 2020 +0200 +++ b/tests/test-unified-test.t Mon Jun 29 02:05:12 2020 +0200 @@ -75,6 +75,16 @@ crlf\r (esc) #endif +Escapes: + + $ $PYTHON -c 'from mercurial.utils.procutil import stdout; stdout.write(b"\xff")' + \xff (no-eol) (esc) + +Escapes with conditions: + + $ $PYTHON -c 'from mercurial.utils.procutil import stdout; stdout.write(b"\xff")' + \xff (no-eol) (esc) (true !) + Combining esc with other markups - and handling lines ending with \r instead of \n: $ printf 'foo/bar\r'