Commit aa4d8b07 authored by Andreas Klebinger's avatar Andreas Klebinger Committed by Marge Bot

Use os.devnull instead of '/dev/null' in the testsuite driver.

The later caused issues on windows by being translated into
"\\dev\\null" and python then trying to open this non-existant file.

So we now use os.devnull inside python and convert it to "/dev/null"
when calling out to the shell, which is bound to run in a unix like
environment.

This fixes an issue a test producing unexpected stderr output failed
with a framework failure instead of showing a diff of the output.
parent a38104b4
Pipeline #9420 failed with stages
in 777 minutes and 35 seconds
......@@ -1817,7 +1817,8 @@ def compare_outputs(way: WayName,
expected_normalised_path = in_testdir(expected_normalised_file)
else:
expected_str = ''
expected_normalised_path = Path('/dev/null')
# See Note [Null device handling]
expected_normalised_path = Path(os.devnull)
actual_raw = read_no_crs(actual_path)
actual_str = normaliser(actual_raw)
......@@ -1829,7 +1830,8 @@ def compare_outputs(way: WayName,
if config.verbose >= 1 and _expect_pass(way):
print('Actual ' + kind + ' output differs from expected:')
if expected_normalised_path != '/dev/null':
# See Note [Null device handling]
if expected_normalised_path != Path(os.devnull):
write_file(expected_normalised_path, expected_str)
actual_normalised_path = add_suffix(actual_path, 'normalised')
......@@ -1837,7 +1839,7 @@ def compare_outputs(way: WayName,
if config.verbose >= 1 and _expect_pass(way):
# See Note [Output comparison].
r = runCmd('diff -uw "{0}" "{1}"'.format(expected_normalised_path,
r = runCmd('diff -uw "{0}" "{1}"'.format(null2unix_null(expected_normalised_path),
actual_normalised_path),
stdout=diff_file,
print_output=True)
......@@ -1845,7 +1847,7 @@ def compare_outputs(way: WayName,
# If for some reason there were no non-whitespace differences,
# then do a full diff
if r == 0:
r = runCmd('diff -u "{0}" "{1}"'.format(expected_normalised_path,
r = runCmd('diff -u "{0}" "{1}"'.format(null2unix_null(expected_normalised_path),
actual_normalised_path),
stdout=diff_file,
print_output=True)
......@@ -1930,6 +1932,26 @@ def grep_output(normaliser: OutputNormalizer, pattern_file, actual_file, is_subs
# on the `diff` program to ignore whitespace changes as much as
# possible (#10152).
# Note [Null device handling]
#
# On windows the null device is 'nul' instead of '/dev/null'.
# This can in principle be easily solved by using os.devnull.
# Not doing so causes issues when python tries to read/write/open
# the null device.
#
# However this still leads to a problem when executing shell
# commands in the msys environment. Which again expect '/dev/null'.
#
# So what we do is use os.devnull and convert it to the string
# '/dev/null' for shell commands which are bound to run in a
# unix-like environment.
def null2unix_null(f: Path) -> str:
if f == Path(os.devnull):
return ('/dev/null')
else:
return f.as_posix()
def normalise_whitespace(s: str) -> str:
# Merge contiguous whitespace characters into a single space.
return ' '.join(s.split())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment