Fix runtest.py output
authorBruce Forstall <brucefo@microsoft.com>
Mon, 4 Feb 2019 23:20:09 +0000 (15:20 -0800)
committerBruce Forstall <brucefo@microsoft.com>
Tue, 5 Feb 2019 02:01:21 +0000 (18:01 -0800)
1. Fix extra newline output
2. Remove extra output of failed logs
3. Catch errors with Unicode conversion

Commit migrated from https://github.com/dotnet/coreclr/commit/718e651e7ede620ef1ecbfc8ebe838db8f3dfa2f

src/coreclr/tests/runtest.py

index db58915..a595ab4 100755 (executable)
@@ -2224,18 +2224,25 @@ def print_summary(tests):
             # XUnit results are captured as escaped characters.
             test_output = test_output.replace("\\r", "\r")
             test_output = test_output.replace("\\n", "\n")
-
-            print(test_output)
             test_output = test_output.replace("/r", "\r")
             test_output = test_output.replace("/n", "\n")
+
+            # Replace CR/LF by just LF; Python "print", below, will map as necessary on the platform.
+            # If we don't do this, then Python on Windows will convert \r\n to \r\r\n on output.
+            test_output = test_output.replace("\r\n", "\n")
+
             unicode_output = None
             if sys.version_info < (3,0):
                 # Handle unicode characters in output in python2.*
-                unicode_output = unicode(test_output, "utf-8")
+                try:
+                    unicode_output = unicode(test_output, "utf-8")
+                except:
+                    print("Error: failed to convert Unicode output")
             else:
                 unicode_output = test_output
 
-            print(unicode_output)
+            if unicode_output is not None:
+                print(unicode_output)
             print("")
 
         print("")