[PATCH] D69207: [lit] Don't fail when printing test output with special chars

Joel E. Denny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 15:34:08 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rG27fdf8a29d1e: [lit] Don't fail when printing test output with special chars (authored by jdenny).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69207/new/

https://reviews.llvm.org/D69207

Files:
  llvm/utils/lit/lit/display.py
  llvm/utils/lit/tests/Inputs/shtest-shell/stdout-encoding.txt
  llvm/utils/lit/tests/max-failures.py
  llvm/utils/lit/tests/shtest-shell.py


Index: llvm/utils/lit/tests/shtest-shell.py
===================================================================
--- llvm/utils/lit/tests/shtest-shell.py
+++ llvm/utils/lit/tests/shtest-shell.py
@@ -413,5 +413,17 @@
 # CHECK: PASS: shtest-shell :: rm-unicode-0.txt
 # CHECK: PASS: shtest-shell :: sequencing-0.txt
 # CHECK: XFAIL: shtest-shell :: sequencing-1.txt
+
+# CHECK: FAIL: shtest-shell :: stdout-encoding.txt
+# CHECK: *** TEST 'shtest-shell :: stdout-encoding.txt' FAILED ***
+# CHECK: $ "cat" "diff-in.bin"
+# CHECK: # command output:
+# CHECK-NEXT: {{^.f.o.o.$}}
+# CHECK-NEXT: {{^.b.a.r..}}
+# CHECK-NEXT: {{^.b.a.z.$}}
+# CHECK-NOT: error
+# CHECK: $ "false"
+# CHECK: ***
+
 # CHECK: PASS: shtest-shell :: valid-shell.txt
-# CHECK: Failing Tests (32)
+# CHECK: Failing Tests (33)
Index: llvm/utils/lit/tests/max-failures.py
===================================================================
--- llvm/utils/lit/tests/max-failures.py
+++ llvm/utils/lit/tests/max-failures.py
@@ -8,7 +8,7 @@
 #
 # END.
 
-# CHECK: Failing Tests (32)
+# CHECK: Failing Tests (33)
 # CHECK: Failing Tests (1)
 # CHECK: Failing Tests (2)
 # CHECK: error: argument --max-failures: requires positive integer, but found '0'
Index: llvm/utils/lit/tests/Inputs/shtest-shell/stdout-encoding.txt
===================================================================
--- /dev/null
+++ llvm/utils/lit/tests/Inputs/shtest-shell/stdout-encoding.txt
@@ -0,0 +1,7 @@
+# Check that lit doesn't fail when printing special characters in its test
+# results.
+
+# RUN: cat diff-in.bin
+
+# Fail so lit will print output.
+# RUN: false
Index: llvm/utils/lit/lit/display.py
===================================================================
--- llvm/utils/lit/lit/display.py
+++ llvm/utils/lit/lit/display.py
@@ -70,7 +70,20 @@
             if test.result.code.isFailure:
                 print("%s TEST '%s' FAILED %s" % ('*'*20, test.getFullName(),
                                                   '*'*20))
-            print(test.result.output)
+            out = test.result.output
+            # Encode/decode so that, when using Python 3.6.5 in Windows 10,
+            # print(out) doesn't raise UnicodeEncodeError if out contains
+            # special characters.  However, Python 2 might try to decode
+            # as part of the encode call if out is already encoded, so skip
+            # encoding if it raises UnicodeDecodeError.
+            if sys.stdout.encoding:
+                try:
+                    out = out.encode(encoding=sys.stdout.encoding,
+                                     errors="replace")
+                except UnicodeDecodeError:
+                    pass
+                out = out.decode(encoding=sys.stdout.encoding)
+            print(out)
             print("*" * 20)
 
         # Report test metrics, if present.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69207.226510.patch
Type: text/x-patch
Size: 2837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191025/d62f6a86/attachment.bin>


More information about the llvm-commits mailing list