mtest: use backslash replace when printing error logs

If there's an UnicodeEncodeError while printing the error logs,
TestHarness tries an encode/decode pair to get rid of anything that
is not a 7-bit ASCII character; this however results in "?" characters
that are not very clear.  To make it easier to understand what is
going on, use backslashreplace instead.

While at it, fix the decode to use a matching encoding.  This will
only matter in the rare case of sys.stdout.encoding not being an
ASCII superset, but that should not matter.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
pull/8001/head
Paolo Bonzini 4 years ago
parent 2201e2bca6
commit 414aee6328
  1. 2
      mesonbuild/mtest.py

@ -1050,7 +1050,7 @@ class TestHarness:
try: try:
print(line) print(line)
except UnicodeEncodeError: except UnicodeEncodeError:
line = line.encode('ascii', errors='replace').decode() line = line.encode('ascii', errors='backslashreplace').decode('ascii')
print(line) print(line)
def total_failure_count(self) -> int: def total_failure_count(self) -> int:

Loading…
Cancel
Save