Skip to content

Commit

Permalink
fix: make TreeMatcher right for case-sensitive worlds
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Apr 10, 2021
1 parent 1b34415 commit dc48d27
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions coverage/files.py
Expand Up @@ -216,17 +216,19 @@ class TreeMatcher(object):
"""
def __init__(self, paths):
self.paths = list(paths)
self.original_paths = list(paths)
self.paths = list(map(os.path.normcase, paths))

def __repr__(self):
return "<TreeMatcher %r>" % self.paths

def info(self):
"""A list of strings for displaying when dumping state."""
return self.paths
return self.original_paths

def match(self, fpath):
"""Does `fpath` indicate a file in one of our trees?"""
fpath = os.path.normcase(fpath)
for p in self.paths:
if fpath.startswith(p):
if fpath == p:
Expand Down
5 changes: 5 additions & 0 deletions tests/test_files.py
Expand Up @@ -151,16 +151,21 @@ def assertMatches(self, matcher, filepath, matches):
assert matches == matcher.match(canonical), msg

def test_tree_matcher(self):
case_folding = env.WINDOWS
matches_to_try = [
(self.make_file("sub/file1.py"), True),
(self.make_file("sub/file2.c"), True),
(self.make_file("sub2/file3.h"), False),
(self.make_file("sub3/file4.py"), True),
(self.make_file("sub3/file5.c"), False),
(self.make_file("sub4/File5.py"), case_folding),
(self.make_file("sub5/file6.py"), case_folding),
]
trees = [
files.canonical_filename("sub"),
files.canonical_filename("sub3/file4.py"),
files.canonical_filename("sub4/file5.py"),
files.canonical_filename("SUB5/file6.py"),
]
tm = TreeMatcher(trees)
assert tm.info() == trees
Expand Down

0 comments on commit dc48d27

Please sign in to comment.