gitignore_parser icon indicating copy to clipboard operation
gitignore_parser copied to clipboard

unit tests fail on windows runners

Open Javagedes opened this issue 2 years ago • 2 comments

Hello, unit tests fail on windows runners, specifically for the trailing whitespace tests. This occured for the recent changes made to fix issues with resolving symlinks. The Path call in _normalize_path retains whitespaces on Linux, but removes them on Windows.

A simple (but not elegant) fix I found was to re-apply the trailing whitespace on windows systems.

# At bottom of file
def _count_trailing_whitespace(text: str):
    count = 0
    for char in reversed(str(text)):
        if char.isspace():
            count += 1
        else:
            break
    return count
# In IgnoreRule
def match(self, abs_path):
    """Returns True or False if the path matches the rule."""
    matched = False
    if self.base_path:
        rel_path = str(_normalize_path(abs_path).relative_to(self.base_path))
    else:
        rel_path = str(_normalize_path(abs_path))
    
    # Path() strips trailing spaces on windows
    if sys.platform.startswith('win'):        
        rel_path += " " * _count_trailing_whitespace(abs_path)
    
    # Path() strips the trailing slash, so we need to preserve it
    # in case of directory-only negation
    if self.negation and isinstance(abs_path, str) and abs_path[-1] == '/':
        rel_path += '/'
    if rel_path.startswith('./'):
        rel_path = rel_path[2:]
    if re.search(self.regex, rel_path):
        matched = True
    return matched

Javagedes avatar Oct 24 '23 23:10 Javagedes

Hello, as usual I'll be happy to accept a PR that fixes this problem.

mherrmann avatar Oct 25 '23 05:10 mherrmann

Hello, as usual I'll be happy to accept a PR that fixes this problem.

Added #61

Javagedes avatar Oct 25 '23 16:10 Javagedes