Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Fix tests returning UNRESOLVED on non-English VS and non-UTF-8 Windows #2145

Merged
merged 1 commit into from
Aug 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions tests/utils/stl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ def __init__(self, msg, out, err, exitCode):
kUseCloseFDs = not (platform.system() == 'Windows')


def decodeOutput(bytes):
# MSVC's output is encoded in the active code page
# EDG's (`cl /BE`) output is encoded in UTF-8
try:
return bytes.decode()
except UnicodeError:
import locale
return bytes.decode(locale.getpreferredencoding(do_setlocale=False))


def executeCommand(command, cwd=None, env=None, input=None, timeout=0):
"""
Execute command ``command`` (list of arguments or string)
Expand Down Expand Up @@ -118,8 +128,8 @@ def killProcess():
timerObject.cancel()

# Ensure the resulting output is always of string type.
out = out.decode()
err = err.decode()
out = decodeOutput(out)
err = decodeOutput(err)

if hitTimeOut:
raise ExecuteCommandTimeoutException(
Expand Down