mirror of
https://github.com/esphome/esphome.git
synced 2026-08-23 06:36:23 +00:00
[core] Fix srcFilter exclusions being silently ignored on Windows (#17648)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import glob
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -86,6 +87,48 @@ def test_collect_filtered_files_exclude(tmp_path):
|
||||
assert str(f2) not in result
|
||||
|
||||
|
||||
def test_collect_filtered_files_exclude_pattern_in_subdir(tmp_path):
|
||||
src = tmp_path / "lib" / "src"
|
||||
src.mkdir(parents=True)
|
||||
kept = src / "a.c"
|
||||
excluded = src / "hasty.c"
|
||||
kept.write_text("int a;")
|
||||
excluded.write_text("int b;")
|
||||
|
||||
result = collect_filtered_files(tmp_path, ["+<lib/src/*.c>", "-<lib/src/hasty.c>"])
|
||||
assert str(kept) in result
|
||||
assert str(excluded) not in result
|
||||
|
||||
|
||||
def test_collect_filtered_files_exclude_unnormalized_glob_output(tmp_path, monkeypatch):
|
||||
# On Windows, glob keeps the pattern's literal separators for non-wildcard
|
||||
# path components, so the "+" wildcard pattern and the "-" literal pattern
|
||||
# yield the same file spelled differently and the exclude set difference
|
||||
# misses it. Backslash is a regular filename character on POSIX (such paths
|
||||
# fail the final is_file filter), so reproduce the unnormalized-output
|
||||
# mismatch portably with dot segments, which normpath also collapses.
|
||||
src = tmp_path / "lib" / "src"
|
||||
src.mkdir(parents=True)
|
||||
kept = src / "a.c"
|
||||
excluded = src / "hasty.c"
|
||||
kept.write_text("int a;")
|
||||
excluded.write_text("int b;")
|
||||
|
||||
real_glob = glob.glob
|
||||
|
||||
def unnormalized_glob(pattern, recursive=False):
|
||||
if "*" in pattern:
|
||||
base = str(tmp_path)
|
||||
return [base + "/lib/./src/a.c", base + "/lib/./src/hasty.c"]
|
||||
return real_glob(pattern, recursive=recursive)
|
||||
|
||||
monkeypatch.setattr(glob, "glob", unnormalized_glob)
|
||||
|
||||
result = collect_filtered_files(tmp_path, ["+<lib/src/*.c>", "-<lib/src/hasty.c>"])
|
||||
assert [Path(r).name for r in result] == ["a.c"]
|
||||
assert str(kept) in result
|
||||
|
||||
|
||||
def test_split_list_by_condition():
|
||||
items = ["-Iinclude", "-Llib", "-Wall"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user