Skip to content

Commit 374e792

Browse files
committed
Treat inputs as UTF-8 (both stdin and check file)
Also: Poetry: remove Python 3.5
1 parent 3b51964 commit 374e792

File tree

6 files changed

+20
-5
lines changed

6 files changed

+20
-5
lines changed

filecheck/FileCheck.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
import io
45
import os
56
import re
67
import sys
@@ -275,7 +276,7 @@ def exit_handler(code):
275276
exit_handler(2)
276277

277278
checks = []
278-
with open(check_file) as f:
279+
with open(check_file, encoding="utf-8") as f:
279280
for line_idx, line in enumerate(f):
280281
line = line.rstrip()
281282

@@ -411,7 +412,11 @@ def exit_handler(code):
411412
# TODO: Performance implications?
412413
# "Getting exit code 141 when reading from stdin with a Python script with “set -o pipefail” set"
413414
# https://stackoverflow.com/questions/59436858/getting-exit-code-141-when-reading-from-stdin-with-a-python-script-with-set-o/59436997?noredirect=1#comment105058533_59436997
414-
input_lines = sys.stdin.readlines()
415+
# Also: Forcing the stdin to be UTF-8
416+
# Python 3: How to specify stdin encoding
417+
# https://stackoverflow.com/a/16549381/598057
418+
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
419+
input_lines = input_stream.readlines()
415420
stdin_input_iter = enumerate(input_lines)
416421

417422
try:

poetry.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description = "Python port of LLVM's FileCheck, flexible pattern matching file v
55
authors = ["Stanislav Pankevich <[email protected]>"]
66

77
[tool.poetry.dependencies]
8-
python = "^3.5"
8+
python = "^3.6"
99

1010
[tool.poetry.dev-dependencies]
1111
lit = "^0.9"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CHECK: # © A line with UTF-8 produces
2+
CHECK: # UnicodeDecodeError: 'ascii' codec can't decode byte
3+
CHECK: # if not properly handled
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# © A line with UTF-8 produces
2+
# UnicodeDecodeError: 'ascii' codec can't decode byte
3+
# if not properly handled
4+
5+
def hello_world():
6+
print("hello world")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"

0 commit comments

Comments
 (0)