diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2019-08-09 12:38:40 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-08-14 16:56:20 -0400 |
commit | aa4d8b07edad74c29acdcf06cf1b4c3ff6b97ffa (patch) | |
tree | c458b79db124ea3f6d451e2a49ead16f0289ca21 /testsuite/driver | |
parent | a38104b4df092d2155f61e9785e92ceb268b7e5f (diff) | |
download | haskell-aa4d8b07edad74c29acdcf06cf1b4c3ff6b97ffa.tar.gz |
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.
Diffstat (limited to 'testsuite/driver')
-rw-r--r-- | testsuite/driver/testlib.py | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/testsuite/driver/testlib.py b/testsuite/driver/testlib.py index e03a2c54aa..36aaf38076 100644 --- a/testsuite/driver/testlib.py +++ b/testsuite/driver/testlib.py @@ -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()) |