[PATCH stable] run-tests: fix escapes with conditions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH stable] run-tests: fix escapes with conditions

Manuel Jacob
# HG changeset patch
# User Manuel Jacob <[hidden email]>
# Date 1593389112 -7200
#      Mon Jun 29 02:05:12 2020 +0200
# Branch stable
# Node ID 929e181fd0c765e66b063313b517c440f6c143aa
# Parent  aa8deb0561ff015ffb0b6df004d8860ccec8e911
# EXP-Topic svn_encoding
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.

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -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:
diff --git a/tests/test-unified-test.t b/tests/test-unified-test.t
--- a/tests/test-unified-test.t
+++ b/tests/test-unified-test.t
@@ -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'
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH stable] run-tests: fix escapes with conditions

Yuya Nishihara
On Mon, 29 Jun 2020 06:16:41 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <[hidden email]>
> # Date 1593389112 -7200
> #      Mon Jun 29 02:05:12 2020 +0200
> # Branch stable
> # Node ID 929e181fd0c765e66b063313b517c440f6c143aa
> # Parent  aa8deb0561ff015ffb0b6df004d8860ccec8e911
> # EXP-Topic svn_encoding
> run-tests: fix escapes with conditions

Queued for stable, thanks.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel