aboutsummaryrefslogtreecommitdiff
path: root/internal/engine/match_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/engine/match_test.go')
-rw-r--r--internal/engine/match_test.go55
1 files changed, 52 insertions, 3 deletions
diff --git a/internal/engine/match_test.go b/internal/engine/match_test.go
index f2a01bc..93311df 100644
--- a/internal/engine/match_test.go
+++ b/internal/engine/match_test.go
@@ -232,12 +232,10 @@ func TestMatchWarningsSorted(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- aaDir := filepath.Join(h, "aa-missing")
- zzDir := filepath.Join(h, "zz-missing")
if len(r.Warnings) != 2 {
t.Fatalf("got %d warnings, want 2 (the shared aa-missing dir should fold into one):\n%s", len(r.Warnings), strings.Join(r.Warnings, "\n"))
}
- wantPrefix := []string{"duplicate: " + aaDir + ":", "duplicate: " + zzDir + ":"}
+ wantPrefix := []string{"duplicate: ~/aa-missing:", "duplicate: ~/zz-missing:"}
for i, want := range wantPrefix {
if !strings.HasPrefix(r.Warnings[i], want) {
t.Errorf("Warnings[%d] = %q, want prefix %q", i, r.Warnings[i], want)
@@ -367,3 +365,54 @@ func TestMatchDrainsDupCandidateErrors(t *testing.T) {
t.Errorf("got %d warnings with prefix %q, want 1; warnings: %v", found, want, r.Warnings)
}
}
+
+// TestDuplicateWarningsShareOneFormat: a missing extra directory and a
+// candidate that cannot be hashed are both reported as "duplicate: PATH:
+// cause", the path abbreviated and not repeated raw inside the cause
+// (triage 6).
+func TestDuplicateWarningsShareOneFormat(t *testing.T) {
+ if os.Getuid() == 0 {
+ t.Skip("root reads a chmod 000 file")
+ }
+ h := sandbox(t)
+ dl := filepath.Join(h, "dl")
+ extra := filepath.Join(h, "extra")
+ os.MkdirAll(dl, 0o755)
+ os.MkdirAll(extra, 0o755)
+ old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
+ for _, p := range []string{filepath.Join(dl, "a.txt"), filepath.Join(extra, "c.txt")} {
+ os.WriteFile(p, []byte("same size"), 0o644)
+ os.Chtimes(p, old, old)
+ }
+ os.Chmod(filepath.Join(extra, "c.txt"), 0)
+ t.Cleanup(func() { os.Chmod(filepath.Join(extra, "c.txt"), 0o644) })
+ main := writeConfig(t, h, `(include "dl")`, map[string]string{"dl": `
+(path "~/dl")
+(rule "d" (when (duplicate "~/extra" "~/nonexistent")) (move "Dupes"))
+`})
+ 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)
+ }
+ want := map[string]bool{
+ "duplicate: ~/extra/c.txt: open: permission denied": false,
+ "duplicate: ~/nonexistent: lstat: no such file or directory": false,
+ }
+ for _, w := range r.Warnings {
+ if strings.Contains(w, h) {
+ t.Errorf("warning repeats the raw path: %q", w)
+ }
+ if _, ok := want[w]; ok {
+ want[w] = true
+ }
+ }
+ for w, seen := range want {
+ if !seen {
+ t.Errorf("missing warning %q in %q", w, r.Warnings)
+ }
+ }
+}