summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testsuite/driver/testlib.py30
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())