diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-08 05:30:29 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2022-11-08 07:21:40 -0500 |
commit | 66657c17d33ccdffa8ca95c8efa9bd4d64bddf5e (patch) | |
tree | 3161b067982fac584530d3a48bc8fd9a429f2ba0 | |
parent | bb27eb6c844204b979fe76f0f47c7869ef1c2362 (diff) | |
download | python-coveragepy-git-66657c17d33ccdffa8ca95c8efa9bd4d64bddf5e.tar.gz |
fix: path-mapped results shouldn't start with ./
Unless the actual result in the config starts with ./
-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 = [] |