Skip to content

Commit

Permalink
Test .gitignore with */* is applied correctly
Browse files Browse the repository at this point in the history
The test contains two cases: when the .gitignore with the special rule
to ignore every subfolder and its contents (*/*) is in the root, and
when the file is inside a subfolder relative to root (nested). In both
cases, we compare the files that are visible by Black with a known
list of paths containing the expected values.

Before the fix introduced in the previous commit, this test failed when
the .gitignore file was nested (second case). Now, the test is passed
for both cases.

Signed-off-by: Antonio Ossa Guerra <aaossa@uc.cl>
  • Loading branch information
aaossa committed Oct 17, 2022
1 parent 814ee81 commit 6485024
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/*
Empty file.
Empty file.
18 changes: 18 additions & 0 deletions tests/test_black.py
Original file line number Diff line number Diff line change
Expand Up @@ -2056,6 +2056,24 @@ def test_invalid_nested_gitignore(self) -> None:
gitignore = path / "a" / ".gitignore"
assert f"Could not parse {gitignore}" in result.stderr_bytes.decode()

def test_gitignore_that_ignores_subfolders(self) -> None:
# If gitignore with */* is in root
root = Path(DATA_DIR / "ignore_subfolders_gitignore_tests" / "subdir")
expected = [root / "b.py"]
ctx = FakeContext()
ctx.obj["root"] = root
assert_collected_sources([root], expected, ctx=ctx)

# If .gitignore with */* is nested
root = Path(DATA_DIR / "ignore_subfolders_gitignore_tests")
expected = [
root / "a.py",
root / "subdir" / "b.py",
]
ctx = FakeContext()
ctx.obj["root"] = root
assert_collected_sources([root], expected, ctx=ctx)

def test_empty_include(self) -> None:
path = DATA_DIR / "include_exclude_tests"
src = [path]
Expand Down

0 comments on commit 6485024

Please sign in to comment.