Skip to content

Commit

Permalink
Merge pull request #158 from mull-project/develop
Browse files Browse the repository at this point in the history
Treat inputs as UTF-8 (both stdin and check file)
  • Loading branch information
stanislaw authored Sep 25, 2021
2 parents 3b51964 + 374e792 commit a94f3c5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
9 changes: 7 additions & 2 deletions filecheck/FileCheck.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import argparse
import io
import os
import re
import sys
Expand Down Expand Up @@ -275,7 +276,7 @@ def exit_handler(code):
exit_handler(2)

checks = []
with open(check_file) as f:
with open(check_file, encoding="utf-8") as f:
for line_idx, line in enumerate(f):
line = line.rstrip()

Expand Down Expand Up @@ -411,7 +412,11 @@ def exit_handler(code):
# TODO: Performance implications?
# "Getting exit code 141 when reading from stdin with a Python script with “set -o pipefail” set"
# 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
input_lines = sys.stdin.readlines()
# Also: Forcing the stdin to be UTF-8
# Python 3: How to specify stdin encoding
# https://stackoverflow.com/a/16549381/598057
input_stream = io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8')
input_lines = input_stream.readlines()
stdin_input_iter = enumerate(input_lines)

try:
Expand Down
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Python port of LLVM's FileCheck, flexible pattern matching file v
authors = ["Stanislav Pankevich <s.pankevich@gmail.com>"]

[tool.poetry.dependencies]
python = "^3.5"
python = "^3.6"

[tool.poetry.dev-dependencies]
lit = "^0.9"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CHECK: # © A line with UTF-8 produces
CHECK: # UnicodeDecodeError: 'ascii' codec can't decode byte
CHECK: # if not properly handled
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# © A line with UTF-8 produces
# UnicodeDecodeError: 'ascii' codec can't decode byte
# if not properly handled

def hello_world():
print("hello world")
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RUN: %cat "%S/filecheck.input" | %expect_exit 0 --expect-no-content %FILECHECK_EXEC "%S/filecheck.check"

0 comments on commit a94f3c5

Please sign in to comment.