diff options
| -rw-r--r-- | coverage/files.py | 3 | ||||
| -rw-r--r-- | tests/test_files.py | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/coverage/files.py b/coverage/files.py index 82f4df31..bfd808ff 100644 --- a/coverage/files.py +++ b/coverage/files.py @@ -435,6 +435,9 @@ class PathAliases: new = new.replace(sep(path), sep(result)) if not self.relative: new = canonical_filename(new) + dot_start = result.startswith(("./", ".\\")) and len(result) > 2 + if new.startswith(("./", ".\\")) and not dot_start: + new = new[2:] self.debugfn( f"Matched path {path!r} to rule {original_pattern!r} -> {result!r}, " + f"producing {new!r}" diff --git a/tests/test_files.py b/tests/test_files.py index 9a4cea7f..561b961d 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -380,6 +380,13 @@ class PathAliasesTest(CoverageTest): aliases.add('/home/*/src', './mysrc') self.assert_unchanged(aliases, '/home/foo/srcetc') + def test_no_dotslash(self, rel_yn): + # The result shouldn't start with "./" if the map result didn't. + aliases = PathAliases(relative=rel_yn) + aliases.add('*/project', '.') + # Because the map result has no slash, the actual result is os-dependent. + self.assert_mapped(aliases, '/ned/home/project/src/a.py', f'src{os.sep}a.py') + def test_multiple_patterns(self, rel_yn): # also test the debugfn... msgs = [] |
