diff options
Diffstat (limited to 'internal/engine/match_test.go')
| -rw-r--r-- | internal/engine/match_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/engine/match_test.go b/internal/engine/match_test.go index 93311df..63bb54a 100644 --- a/internal/engine/match_test.go +++ b/internal/engine/match_test.go @@ -416,3 +416,47 @@ func TestDuplicateWarningsShareOneFormat(t *testing.T) { } } } + +// TestRuleDuplicateWarningShortensThePath: a duplicate check that fails on +// the file itself is reported on the rule with the path shortened and not +// repeated raw inside the cause, like the directory-level warnings (plan 11 +// review L7). +func TestRuleDuplicateWarningShortensThePath(t *testing.T) { + if os.Getuid() == 0 { + t.Skip("root reads a chmod 000 file") + } + h := sandbox(t) + dl := filepath.Join(h, "dl") + os.MkdirAll(dl, 0o755) + old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + for _, n := range []string{"a.txt", "b.txt"} { + p := filepath.Join(dl, n) + os.WriteFile(p, []byte("same size"), 0o644) + os.Chtimes(p, old, old) + } + os.Chmod(filepath.Join(dl, "a.txt"), 0) + t.Cleanup(func() { os.Chmod(filepath.Join(dl, "a.txt"), 0o644) }) + main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": "(path \"~/dl\")\n(rule \"dups\" (when (duplicate)) (move \"Dupes\"))\n"}) + 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) + } + found := false + for _, fm := range append(append([]FileMatch{}, r.Matched...), r.Unmatched...) { + for _, w := range fm.Warnings { + if strings.Contains(w, h) { + t.Errorf("%s: warning repeats the raw path: %q", fm.File.Rel, w) + } + if w == "dups: duplicate check failed: ~/dl/a.txt: open: permission denied" { + found = true + } + } + } + if !found { + t.Errorf("no shortened rule warning for a.txt: %+v %+v", r.Matched, r.Unmatched) + } +} |
