diff options
Diffstat (limited to 'cmd/krino/sort_test.go')
| -rw-r--r-- | cmd/krino/sort_test.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/cmd/krino/sort_test.go b/cmd/krino/sort_test.go index 071a64d..4f3e29f 100644 --- a/cmd/krino/sort_test.go +++ b/cmd/krino/sort_test.go @@ -366,3 +366,32 @@ func TestLaterDirectoryNeverOverwritesAnEarlierOnesResult(t *testing.T) { t.Errorf("the Trash holds %d entries; nothing should have been displaced", len(entries)) } } + +// TestOnlyWhereFilesEndedUpStaysClaimed: a path an earlier directory's file +// passed through and left - renamed, then moved on - is free for a later +// directory; only where files ended up stays claimed (plan 11 re-check). +func TestOnlyWhereFilesEndedUpStaysClaimed(t *testing.T) { + h := home(t) + old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + if code, _, errOut := runCLI(t, "init"); code != 0 { + t.Fatal(errOut) + } + for _, n := range []string{"a", "b"} { + p := filepath.Join(h, n, "x.pdf") + os.MkdirAll(filepath.Dir(p), 0o755) + os.WriteFile(p, []byte("from "+n), 0o644) + os.Chtimes(p, old, old) + if code, _, errOut := runCLI(t, "new", n, filepath.Join(h, n)); code != 0 { + t.Fatal(errOut) + } + } + dirs := filepath.Join(h, ".config", "krino", "dirs") + os.WriteFile(filepath.Join(dirs, "a.conf"), []byte("(path \"~/a\")\n(rule \"r\" (rename \"x-r.pdf\") (move \"~/Out\"))\n"), 0o644) + os.WriteFile(filepath.Join(dirs, "b.conf"), []byte("(path \"~/b\")\n(rule \"r\" (rename \"x-r.pdf\") (move \"~/a\"))\n"), 0o644) + if code, out, errOut := runCLI(t, "-y", "a", "b"); code != 0 { + t.Fatalf("exit %d\n%s\n%s", code, out, errOut) + } + if b, err := os.ReadFile(filepath.Join(h, "a", "x-r.pdf")); err != nil || string(b) != "from b" { + t.Errorf("a/x-r.pdf: %q, %v; want b's file under its planned name", b, err) + } +} |
