summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2018-01-22 20:36:11 -0500
committerNed Batchelder <ned@nedbatchelder.com>2018-01-22 20:36:11 -0500
commit8718508cf15d9a2eb1f697d14aec0c8d558d44b3 (patch)
tree51e24898ca271647eca8818d14b54f7c3f1d1148
parente7a7b13fde81be114a8b6bba9483ba0fbdea729d (diff)
downloadpython-coveragepy-8718508cf15d9a2eb1f697d14aec0c8d558d44b3.tar.gz
Ensure mapped paths use the separator of the result. #618
-rw-r--r--CHANGES.rst6
-rw-r--r--coverage/files.py3
-rw-r--r--tests/test_files.py32
3 files changed, 39 insertions, 2 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index 08b62e3..a9b5c1b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -29,12 +29,18 @@ Unreleased
is raised if we thought there were files to combine, but in fact none of them
could be used. Fixes `issue 629`_.
+- The ``coverage combine`` command could get confused about path separators
+ when combining data collected on Windows with data collected on Linux, as
+ described in `issue 618`_. This is now fixed: the result path always uses
+ the path separator specified in the ``[paths]`` result.
+
- On Windows, the HTML report could fail when source trees are deeply nested,
due to attempting to create HTML filenames longer than the 250-character
maximum. Now filenames will never get much larger than 200 characters,
fixing `issue 627`_. Thanks to Alex Sandro for helping with the fix.
.. _issue 563: https://bitbucket.org/ned/coveragepy/issues/563/platform-specific-configuration
+.. _issue 618: https://bitbucket.org/ned/coveragepy/issues/618/problem-when-combining-windows-generated
.. _issue 621: https://bitbucket.org/ned/coveragepy/issues/621/include-ignored-warning-when-using
.. _issue 622: https://bitbucket.org/ned/coveragepy/issues/622/report-omit-overwrites-run-omit
.. _issue 627: https://bitbucket.org/ned/coveragepy/issues/627/failure-generating-html-reports-when-the
diff --git a/coverage/files.py b/coverage/files.py
index 12b89e8..e746c3b 100644
--- a/coverage/files.py
+++ b/coverage/files.py
@@ -381,8 +381,7 @@ class PathAliases(object):
m = regex.match(path)
if m:
new = path.replace(m.group(0), result)
- if pattern_sep != result_sep:
- new = new.replace(pattern_sep, result_sep)
+ new = new.replace(sep(path), result_sep)
new = canonical_filename(new)
return new
return path
diff --git a/tests/test_files.py b/tests/test_files.py
index 84d84a4..dd88b6e 100644
--- a/tests/test_files.py
+++ b/tests/test_files.py
@@ -246,6 +246,38 @@ class PathAliasesTest(CoverageTest):
aliases.add(r'c:\ned\src', r'.\mysrc')
self.assert_mapped(aliases, r'/home/ned/foo/src/sub/a.py', r'.\mysrc\sub\a.py')
+ def test_windows_on_linux(self):
+ # https://bitbucket.org/ned/coveragepy/issues/618/problem-when-combining-windows-generated
+ lin = "*/project/module/"
+ win = "*\\project\\module\\"
+
+ # Try the paths in both orders.
+ for paths in [[lin, win], [win, lin]]:
+ aliases = PathAliases()
+ for path in paths:
+ aliases.add(path, "project/module")
+ self.assert_mapped(
+ aliases,
+ "C:\\a\\path\\somewhere\\coveragepy_test\\project\\module\\tests\\file.py",
+ "project/module/tests/file.py"
+ )
+
+ def test_linux_on_windows(self):
+ # https://bitbucket.org/ned/coveragepy/issues/618/problem-when-combining-windows-generated
+ lin = "*/project/module/"
+ win = "*\\project\\module\\"
+
+ # Try the paths in both orders.
+ for paths in [[lin, win], [win, lin]]:
+ aliases = PathAliases()
+ for path in paths:
+ aliases.add(path, "project\\module")
+ self.assert_mapped(
+ aliases,
+ "C:/a/path/somewhere/coveragepy_test/project/module/tests/file.py",
+ "project\\module\\tests\\file.py"
+ )
+
def test_multiple_wildcard(self):
aliases = PathAliases()
aliases.add('/home/jenkins/*/a/*/b/*/django', './django')