diff options
-rw-r--r-- | coverage/files.py | 7 | ||||
-rw-r--r-- | tests/test_files.py | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/coverage/files.py b/coverage/files.py index 72c0bf92..40c126e9 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -177,7 +177,12 @@ class FnmatchMatcher(object): """A matcher for files by filename pattern.""" def __init__(self, pats): self.pats = pats[:] - self.re = re.compile(join_regex([fnmatch.translate(p) for p in pats])) + # fnmatch is platform-specific. On Windows, it does the Windows thing + # of treating / and \ as equivalent. But on other platforms, we need to + # take care of that ourselves. + fnpats = [fnmatch.translate(p) for p in pats] + fnpats = [p.replace(r"\/", r"[\\/]") for p in fnpats] + self.re = re.compile(join_regex(fnpats)) def __repr__(self): return "<FnmatchMatcher %r>" % self.pats diff --git a/tests/test_files.py b/tests/test_files.py index 070430ff..648c76a9 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -99,6 +99,14 @@ class MatcherTest(CoverageTest): self.assertMatches(fnm, "x123foo.txt", True) self.assertMatches(fnm, "x798bar.txt", False) + def test_fnmatch_windows_paths(self): + # We should be able to match Windows paths even if we are running on + # a non-Windows OS. + fnm = FnmatchMatcher(["*/foo.py"]) + self.assertMatches(fnm, r"dir\foo.py", True) + fnm = FnmatchMatcher([r"*\foo.py"]) + self.assertMatches(fnm, r"dir\foo.py", True) + class PathAliasesTest(CoverageTest): """Tests for coverage/files.py:PathAliases""" |