diff options
author | Michal Gorny <mgorny@gentoo.org> | 2019-06-24 09:40:33 +0000 |
---|---|---|
committer | Michal Gorny <mgorny@gentoo.org> | 2019-06-24 09:40:33 +0000 |
commit | a5bb7b6c20e2812da265a31624fc49f41dc6ff04 (patch) | |
tree | 65be2c5aed487421346a9cd07f511ce61bc7bd25 /libcxx/utils | |
parent | bb6d0b8e7b0d815710a71b8012438a586e986450 (diff) | |
download | bcm5719-llvm-a5bb7b6c20e2812da265a31624fc49f41dc6ff04.tar.gz bcm5719-llvm-a5bb7b6c20e2812da265a31624fc49f41dc6ff04.zip |
[libcxx] [test] Read files as bytestrings to fix py3 encoding issues
Use binary mode to read test files in libcxx LibcxxTestFormat class.
This ensures that tests are read correctly independently of encoding,
and therefore fixes UnicodeDecodeError when file is opened in Python 3
that defaults to pure ASCII encoding.
Technically this could be also fixed via conditionally appending
encoding argument when opening the file in Python 3. However, since
the code in question only searches for fixed ASCII substrings reading
it in binary mode is simpler and more universal.
Differential Revision: https://reviews.llvm.org/D63346
llvm-svn: 364170
Diffstat (limited to 'libcxx/utils')
-rw-r--r-- | libcxx/utils/libcxx/test/format.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libcxx/utils/libcxx/test/format.py b/libcxx/utils/libcxx/test/format.py index a8dae489875..122014272db 100644 --- a/libcxx/utils/libcxx/test/format.py +++ b/libcxx/utils/libcxx/test/format.py @@ -135,9 +135,9 @@ class LibcxxTestFormat(object): # If we see this we need to build the test against uniquely built # modules. if is_libcxx_test: - with open(test.getSourcePath(), 'r') as f: + with open(test.getSourcePath(), 'rb') as f: contents = f.read() - if '#define _LIBCPP_ASSERT' in contents: + if b'#define _LIBCPP_ASSERT' in contents: test_cxx.useModules(False) if is_objcxx_test: @@ -224,10 +224,11 @@ class LibcxxTestFormat(object): def _evaluate_fail_test(self, test, test_cxx, parsers): source_path = test.getSourcePath() # FIXME: lift this detection into LLVM/LIT. - with open(source_path, 'r') as f: + with open(source_path, 'rb') as f: contents = f.read() - verify_tags = ['expected-note', 'expected-remark', 'expected-warning', - 'expected-error', 'expected-no-diagnostics'] + verify_tags = [b'expected-note', b'expected-remark', + b'expected-warning', b'expected-error', + b'expected-no-diagnostics'] use_verify = self.use_verify_for_fail and \ any([tag in contents for tag in verify_tags]) # FIXME(EricWF): GCC 5 does not evaluate static assertions that @@ -249,7 +250,8 @@ class LibcxxTestFormat(object): # # Therefore, we check if the test was expected to fail because of # nodiscard before enabling it - test_str_list = ['ignoring return value', 'nodiscard', 'NODISCARD'] + test_str_list = [b'ignoring return value', b'nodiscard', + b'NODISCARD'] if any(test_str in contents for test_str in test_str_list): test_cxx.flags += ['-Werror=unused-result'] cmd, out, err, rc = test_cxx.compile(source_path, out=os.devnull) |