Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix trailing single asterisk matching subdirs #1650

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion coverage/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def sep(s: str) -> str:
(r"\*\*+[^/]+", None), # Can't have **x
(r"\*\*/\*\*", None), # Can't have **/**
(r"^\*+/", r"(.*[/\\\\])?"), # ^*/ matches any prefix-slash, or nothing.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nedbat I wonder if this has the same problem with the prefix..

(r"/\*+$", r"[/\\\\].*"), # /*$ matches any slash-suffix.
(r"/\*\*+$", r"[/\\\\].*"), # /**$ matches any slash-suffix.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nedbat at first I thought I'd just send a test case demonstrating the problem, but then, I thought it should be easy to fix, so I've added this change as well. I don't know if there was a motivation for things to work as they do, but hopefully this can improve the behavior and match it with what's documented…

(r"\*\*/", r"(.*[/\\\\])?"), # **/ matches any subdirs, including none
(r"/", r"[/\\\\]"), # / matches either slash or backslash
(r"\*", r"[^/\\\\]*"), # * matches any number of non slash-likes
Expand Down
7 changes: 5 additions & 2 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,14 @@ def test_glob_matcher(self) -> None:
(self.make_file("sub/file1.py"), True),
(self.make_file("sub/file2.c"), False),
(self.make_file("sub2/file3.h"), True),
(self.make_file("sub2/sub/file3.h"), False),
(self.make_file("sub3/file4.py"), True),
(self.make_file("sub3/file5.c"), False),
(self.make_file("sub4/file3.h"), True),
(self.make_file("sub4/sub/file3.h"), True),
]
fnm = GlobMatcher(["*.py", "*/sub2/*"])
assert fnm.info() == ["*.py", "*/sub2/*"]
fnm = GlobMatcher(["*.py", "*/sub2/*", "*/sub4/**"])
assert fnm.info() == ["*.py", "*/sub2/*", "*/sub4/**"]
for filepath, matches in matches_to_try:
self.assertMatches(fnm, filepath, matches)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_report_omitting(self) -> None:
self.make_mycode()
cov = coverage.Coverage()
self.start_import_stop(cov, "mycode")
report = self.get_report(cov, omit=[f"{TESTS_DIR}/*", "*/site-packages/*"])
report = self.get_report(cov, omit=[f"{TESTS_DIR}/**", "*/site-packages/**"])

# Name Stmts Miss Cover
# -------------------------------
Expand Down