llvm.org GIT mirror llvm / a2091d4
[lit] Fix UnicodeEncodeError when test commands contain non-ASCII chars Ensure that the bash script written by lit TestRunner is open with UTF-8 encoding when using Python 3. Otherwise, attempt to write non-ASCII characters causes UnicodeEncodeError. This happened e.g. with the following LLD test: UNRESOLVED: lld :: ELF/format-binary-non-ascii.s (657 of 2119) ******************** TEST 'lld :: ELF/format-binary-non-ascii.s' FAILED ******************** Exception during script execution: Traceback (most recent call last): File "/home/mgorny/llvm-project/llvm/utils/lit/lit/worker.py", line 63, in _execute_test result = test.config.test_format.execute(test, lit_config) File "/home/mgorny/llvm-project/llvm/utils/lit/lit/formats/shtest.py", line 25, in execute self.execute_external) File "/home/mgorny/llvm-project/llvm/utils/lit/lit/TestRunner.py", line 1644, in executeShTest res = _runShTest(test, litConfig, useExternalSh, script, tmpBase) File "/home/mgorny/llvm-project/llvm/utils/lit/lit/TestRunner.py", line 1590, in _runShTest res = executeScript(test, litConfig, tmpBase, script, execdir) File "/home/mgorny/llvm-project/llvm/utils/lit/lit/TestRunner.py", line 1157, in executeScript f.write('{ ' + '; } &&\n{ '.join(commands) + '; }') UnicodeEncodeError: 'ascii' codec can't encode character '\xa3' in position 274: ordinal not in range(128) Differential Revision: https://reviews.llvm.org/D63254 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363388 91177308-0d34-0410-b5e6-96231b3b80d8 Michal Gorny a month ago
3 changed file(s) with 10 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
11321132
11331133 # Write script file
11341134 mode = 'w'
1135 open_kwargs = {}
11351136 if litConfig.isWindows and not isWin32CMDEXE:
1136 mode += 'b' # Avoid CRLFs when writing bash scripts.
1137 f = open(script, mode)
1137 mode += 'b' # Avoid CRLFs when writing bash scripts.
1138 elif sys.version_info > (3,0):
1139 open_kwargs['encoding'] = 'utf-8'
1140 f = open(script, mode, **open_kwargs)
11381141 if isWin32CMDEXE:
11391142 for i, ln in enumerate(commands):
11401143 commands[i] = re.sub(kPdbgRegex, "echo '\\1' > nul && ", ln)
0 # Run a command including UTF-8 characters.
1 #
2 # RUN: echo £
7979 # CHECK: shtest-format :: external_shell/fail_with_bad_encoding.txt
8080 # CHECK: shtest-format :: fail.txt
8181
82 # CHECK: Expected Passes : 7
82 # CHECK: Expected Passes : 8
8383 # CHECK: Expected Failures : 4
8484 # CHECK: Unsupported Tests : 5
8585 # CHECK: Unresolved Tests : 3
8989
9090 # XUNIT:
9191 # XUNIT-NEXT:
92 # XUNIT-NEXT:
92 # XUNIT-NEXT:
9393
9494 # XUNIT:
9595