summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2013-08-14 22:21:01 +0000
committerDaniel Dunbar <daniel@zuster.org>2013-08-14 22:21:01 +0000
commit80a06baec266e901f58797c39ac78c9552036b9d (patch)
tree99b81dd28aec2a2bcc198a6c29450f134c2d84c9
parent1b6e10f53bec0cd261924734bd5eb58c75c8f550 (diff)
downloadllvm-80a06baec266e901f58797c39ac78c9552036b9d.tar.gz
llvm-80a06baec266e901f58797c39ac78c9552036b9d.tar.bz2
llvm-80a06baec266e901f58797c39ac78c9552036b9d.tar.xz
[lit] Ensure test output is converted to strings where possible.
- This cleans up the text output of failing tests when run under PY3. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188416 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--utils/lit/lit/TestRunner.py10
-rw-r--r--utils/lit/lit/util.py10
-rw-r--r--utils/lit/tests/Inputs/shtest-format/external_shell/fail.txt2
-rw-r--r--utils/lit/tests/Inputs/shtest-format/external_shell/fail_with_bad_encoding.txt5
-rwxr-xr-xutils/lit/tests/Inputs/shtest-format/external_shell/write-bad-encoding.sh3
-rw-r--r--utils/lit/tests/Inputs/shtest-format/fail.txt1
-rw-r--r--utils/lit/tests/shtest-format.py36
7 files changed, 63 insertions, 4 deletions
diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py
index 3c658eafcd..6e03eb9659 100644
--- a/utils/lit/lit/TestRunner.py
+++ b/utils/lit/lit/TestRunner.py
@@ -198,6 +198,16 @@ def executeShCmd(cmd, cfg, cwd, results):
if res == -signal.SIGINT:
raise KeyboardInterrupt
+ # Ensure the resulting output is always of string type.
+ try:
+ out = str(out.decode('ascii'))
+ except:
+ out = str(out)
+ try:
+ err = str(err.decode('ascii'))
+ except:
+ err = str(err)
+
results.append((cmd.commands[i], out, err, res))
if cmd.pipe_err:
# Python treats the exit code as a signed char.
diff --git a/utils/lit/lit/util.py b/utils/lit/lit/util.py
index ce26f06d6d..2b1010c187 100644
--- a/utils/lit/lit/util.py
+++ b/utils/lit/lit/util.py
@@ -156,4 +156,14 @@ def executeCommand(command, cwd=None, env=None):
if exitCode == -signal.SIGINT:
raise KeyboardInterrupt
+ # Ensure the resulting output is always of string type.
+ try:
+ out = str(out.decode('ascii'))
+ except:
+ out = str(out)
+ try:
+ err = str(err.decode('ascii'))
+ except:
+ err = str(err)
+
return out, err, exitCode
diff --git a/utils/lit/tests/Inputs/shtest-format/external_shell/fail.txt b/utils/lit/tests/Inputs/shtest-format/external_shell/fail.txt
index 1e74be5dbd..069e37619e 100644
--- a/utils/lit/tests/Inputs/shtest-format/external_shell/fail.txt
+++ b/utils/lit/tests/Inputs/shtest-format/external_shell/fail.txt
@@ -1,3 +1,5 @@
# Run a command that fails with error on stdout.
#
+# RUN: echo "line 1: failed test output on stdout"
+# RUN: echo "line 2: failed test output on stdout"
# RUN: cat "does-not-exist"
diff --git a/utils/lit/tests/Inputs/shtest-format/external_shell/fail_with_bad_encoding.txt b/utils/lit/tests/Inputs/shtest-format/external_shell/fail_with_bad_encoding.txt
new file mode 100644
index 0000000000..f6157e66c9
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-format/external_shell/fail_with_bad_encoding.txt
@@ -0,0 +1,5 @@
+# Run a command that fails with error on stdout.
+#
+# RUN: %S/write-bad-encoding.sh
+# RUN: false
+
diff --git a/utils/lit/tests/Inputs/shtest-format/external_shell/write-bad-encoding.sh b/utils/lit/tests/Inputs/shtest-format/external_shell/write-bad-encoding.sh
new file mode 100755
index 0000000000..6b622cb232
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-format/external_shell/write-bad-encoding.sh
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+echo "a line with bad encoding: Â."
diff --git a/utils/lit/tests/Inputs/shtest-format/fail.txt b/utils/lit/tests/Inputs/shtest-format/fail.txt
index 49932c3006..8c305eb416 100644
--- a/utils/lit/tests/Inputs/shtest-format/fail.txt
+++ b/utils/lit/tests/Inputs/shtest-format/fail.txt
@@ -1 +1,2 @@
+# RUN: printf "line 1: failed test output on stdout\nline 2: failed test output on stdout"
# RUN: false
diff --git a/utils/lit/tests/shtest-format.py b/utils/lit/tests/shtest-format.py
index 4b36873a3d..a5ce2ff949 100644
--- a/utils/lit/tests/shtest-format.py
+++ b/utils/lit/tests/shtest-format.py
@@ -8,14 +8,41 @@
# CHECK: -- Testing:
# CHECK: FAIL: shtest-format :: external_shell/fail.txt
-# CHECK: *** TEST 'shtest-format :: external_shell/fail.txt' FAILED ***
+# CHECK-NEXT: *** TEST 'shtest-format :: external_shell/fail.txt' FAILED ***
+# CHECK: Command Output (stdout):
+# CHECK-NEXT: --
+# CHECK-NEXT: line 1: failed test output on stdout
+# CHECK-NEXT: line 2: failed test output on stdout
# CHECK: Command Output (stderr):
-# CHECK: cat: does-not-exist: No such file or directory
+# CHECK-NEXT: --
+# CHECK-NEXT: cat: does-not-exist: No such file or directory
+# CHECK: --
+
+# CHECK: FAIL: shtest-format :: external_shell/fail_with_bad_encoding.txt
+# CHECK-NEXT: *** TEST 'shtest-format :: external_shell/fail_with_bad_encoding.txt' FAILED ***
+# CHECK: Command Output (stdout):
+# CHECK-NEXT: --
+# CHECK-NEXT: a line with bad encoding:
# CHECK: --
# CHECK: PASS: shtest-format :: external_shell/pass.txt
# CHECK: FAIL: shtest-format :: fail.txt
+# CHECK-NEXT: *** TEST 'shtest-format :: fail.txt' FAILED ***
+# CHECK-NEXT: Script:
+# CHECK-NEXT: --
+# CHECK-NEXT: printf "line 1
+# CHECK-NEXT: false
+# CHECK-NEXT: --
+# CHECK-NEXT: Exit Code: 1
+#
+# CHECK: Command Output (stdout):
+# CHECK-NEXT: --
+# CHECK-NEXT: Command 0: "printf"
+# CHECK-NEXT: Command 0 Result: 0
+# CHECK-NEXT: Command 0 Output:
+# CHECK-NEXT: line 1: failed test output on stdout
+# CHECK-NEXT: line 2: failed test output on stdout
# CHECK: UNRESOLVED: shtest-format :: no-test-line.txt
# CHECK: PASS: shtest-format :: pass.txt
@@ -31,8 +58,9 @@
# CHECK: Unexpected Passing Tests (1)
# CHECK: shtest-format :: xpass.txt
-# CHECK: Failing Tests (2)
+# CHECK: Failing Tests (3)
# CHECK: shtest-format :: external_shell/fail.txt
+# CHECK: shtest-format :: external_shell/fail_with_bad_encoding.txt
# CHECK: shtest-format :: fail.txt
# CHECK: Expected Passes : 3
@@ -40,4 +68,4 @@
# CHECK: Unsupported Tests : 2
# CHECK: Unresolved Tests : 1
# CHECK: Unexpected Passes : 1
-# CHECK: Unexpected Failures: 2
+# CHECK: Unexpected Failures: 3