From 59015f1f91d640502fdfc34019cf0154b5206bb8 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 15 Sep 2026 00:27:43 +0200 Subject: explain walks the directory for a duplicate test in an exclude too --- internal/engine/exclude_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'internal/engine/exclude_test.go') diff --git a/internal/engine/exclude_test.go b/internal/engine/exclude_test.go index 5a758bb..9aafd7f 100644 --- a/internal/engine/exclude_test.go +++ b/internal/engine/exclude_test.go @@ -483,3 +483,32 @@ func TestPartlyReadableDocumentIsNotCached(t *testing.T) { } } } + +// TestExplainAgreesWithMatchOnADuplicateExclude: a (duplicate) test inside +// an exclude needs the directory's other files, as one inside a rule does, +// so explain sets aside exactly the files Match does (plan 11 review M3). +func TestExplainAgreesWithMatchOnADuplicateExclude(t *testing.T) { + h, dl := excludeTree(t, map[string]string{"a.txt": "same", "b.txt": "same", "c.txt": "other"}) + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": ` +(path "~/dl") +(exclude (not (duplicate))) +(rule "all" (move "Out")) +`}) + e, errs := Load(main) + if len(errs) > 0 { + t.Fatal(errs) + } + r, err := e.Match(context.Background(), e.Dirs[0]) + if err != nil { + t.Fatal(err) + } + for _, fm := range append(append([]FileMatch{}, r.Matched...), r.Unmatched...) { + x, err := e.Explain(context.Background(), filepath.Join(dl, fm.File.Rel)) + if err != nil { + t.Fatal(err) + } + if x.Excluded != fm.Excluded { + t.Errorf("%s: explain sets it aside as %q, Match as %q", fm.File.Rel, x.Excluded, fm.Excluded) + } + } +} -- cgit v1.3