# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 2020-03-29 20:51:26
# Node ID d359f0d1a3d37cea2dc64c62606df4393dd9afe4
# Parent  02fa5392bab6cb89ab28ea0d0beb8619ddcd96d9

tests: force \n newlines when writing to sys.stdout

Without this, Python 3 on Windows inserts some \r that aren't
present in the input, causing test-http-bad-server.t to fail.
After this change, the test passes on Python 3 on Windows!

Differential Revision: https://phab.mercurial-scm.org/D8341

diff --git a/tests/filtertraceback.py b/tests/filtertraceback.py
--- a/tests/filtertraceback.py
+++ b/tests/filtertraceback.py
@@ -4,8 +4,19 @@
 
 from __future__ import absolute_import, print_function
 
+import io
 import sys
 
+if sys.version_info[0] >= 3:
+    # Prevent \r from being inserted on Windows.
+    sys.stdout = io.TextIOWrapper(
+        sys.stdout.buffer,
+        sys.stdout.encoding,
+        sys.stdout.errors,
+        newline="\n",
+        line_buffering=sys.stdout.line_buffering,
+    )
+
 state = 'none'
 
 for line in sys.stdin: