From 26c94eb3db62ec6eebbf8d22c11afe691d9520c4 Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Sun, 13 Sep 2026 02:31:32 +0200 Subject: krino: release 0.0.1 — man pages, install, examples, cross and release, README, changelog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also: undo removes the directories its run created; a hardlink is never a duplicate of its own other name; a flag written before "undo" is honoured; --version prints no leading v. Duplicate conditions with different scopes not sharing an original is documented as a known limitation. --- cmd/krino/history_test.go | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'cmd/krino/history_test.go') diff --git a/cmd/krino/history_test.go b/cmd/krino/history_test.go index 2667b63..23b1e5f 100644 --- a/cmd/krino/history_test.go +++ b/cmd/krino/history_test.go @@ -315,3 +315,66 @@ func TestReviewUndoInvalidKeyReprompts(t *testing.T) { t.Errorf("no mention of the rejected key:\n%s", out) } } + +// TestGlobalDryRunBeforeUndo: -n written before the subcommand, the way +// krino.1 teaches flags, is a dry run of the undo. It shows the plan, +// exits 0, and moves nothing back. +func TestGlobalDryRunBeforeUndo(t *testing.T) { + h := matchingFixture(t) + if code, _, errOut := runCLI(t, "-y"); code != 0 { + t.Fatalf("apply: %d %s", code, errOut) + } + filed := filepath.Join(h, "dl", "Work", "Acme", "inv1.txt") + + code, out, errOut := runCLI(t, "-n", "undo") + if code != 0 || !strings.Contains(out, "undo-move") { + t.Errorf("-n undo: %d %q\n%s", code, errOut, out) + } + if _, err := os.Stat(filed); err != nil { + t.Errorf("-n undo moved a file: %v", err) + } + if _, out, _ = runCLI(t, "log"); strings.Contains(out, "undone") { + t.Errorf("-n undo marked the run undone:\n%s", out) + } +} + +// TestGlobalDryRunBeforeUndoConflictsWithYes: -n before the subcommand and +// -y after it is the same conflict as both after it: exit 2, nothing +// changed. +func TestGlobalDryRunBeforeUndoConflictsWithYes(t *testing.T) { + h := matchingFixture(t) + if code, _, errOut := runCLI(t, "-y"); code != 0 { + t.Fatalf("apply: %d %s", code, errOut) + } + filed := filepath.Join(h, "dl", "Work", "Acme", "inv1.txt") + + code, _, errOut := runCLI(t, "-n", "undo", "-y") + if code != 2 || !strings.Contains(errOut, "-y and -n cannot be used together") { + t.Errorf("-n undo -y: %d %q", code, errOut) + } + if _, err := os.Stat(filed); err != nil { + t.Errorf("-n undo -y moved a file: %v", err) + } + if _, out, _ := runCLI(t, "log"); strings.Contains(out, "undone") { + t.Errorf("-n undo -y marked the run undone:\n%s", out) + } +} + +// TestGlobalYesBeforeUndo: -y before the subcommand applies the undo. +func TestGlobalYesBeforeUndo(t *testing.T) { + h := matchingFixture(t) + if code, _, errOut := runCLI(t, "-y"); code != 0 { + t.Fatalf("apply: %d %s", code, errOut) + } + filed := filepath.Join(h, "dl", "Work", "Acme", "inv1.txt") + + if code, _, errOut := runCLI(t, "-y", "undo"); code != 0 { + t.Fatalf("-y undo: %d %s", code, errOut) + } + if _, err := os.Stat(filepath.Join(h, "dl", "inv1.txt")); err != nil { + t.Errorf("-y undo did not put the file back: %v", err) + } + if _, err := os.Stat(filed); !os.IsNotExist(err) { + t.Error("the filed copy survived -y undo") + } +} -- cgit v1.3