Skip to content

Commit

Permalink
fix: combine aliases on windows base dirs (ie: X:\) (fixes: #577)
Browse files Browse the repository at this point in the history
Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
  • Loading branch information
vaab committed Dec 26, 2020
1 parent 37285cb commit 1a648e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions coverage/files.py
Expand Up @@ -359,17 +359,19 @@ def add(self, pattern, result):
match an entire tree, and not just its root.
"""
pattern_sep = sep(pattern)

if len(pattern) > 1:
pattern = pattern.rstrip(r"\/")

# The pattern can't end with a wildcard component.
if pattern.endswith("*"):
raise CoverageException("Pattern must not end with wildcards.")
pattern_sep = sep(pattern)

# The pattern is meant to match a filepath. Let's make it absolute
# unless it already is, or is meant to match any prefix.
if not pattern.startswith('*') and not isabs_anywhere(pattern):
if not pattern.startswith('*') and not isabs_anywhere(pattern +
pattern_sep):
pattern = abs_file(pattern)
if not pattern.endswith(pattern_sep):
pattern += pattern_sep
Expand Down
14 changes: 14 additions & 0 deletions tests/test_files.py
Expand Up @@ -349,6 +349,20 @@ def test_multiple_wildcard(self):
'./django/foo/bar.py'
)

def test_windows_root_paths(self):
aliases = PathAliases()
aliases.add('X:\\', '/tmp/src')
self.assert_mapped(
aliases,
"X:\\a\\file.py",
"/tmp/src/a/file.py"
)
self.assert_mapped(
aliases,
"X:\\file.py",
"/tmp/src/file.py"
)

def test_leading_wildcard(self):
aliases = PathAliases()
aliases.add('*/d1', './mysrc1')
Expand Down

0 comments on commit 1a648e0

Please sign in to comment.