diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-13 02:31:32 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-13 02:31:32 +0200 |
| commit | 26c94eb3db62ec6eebbf8d22c11afe691d9520c4 (patch) | |
| tree | 165e5bf69234b4f96c9b74deb4898d7143ddf120 /cmd/krino/history_test.go | |
| parent | a6e442a645902011b2081c216daaec052cdc6ce6 (diff) | |
| download | krino-26c94eb3db62ec6eebbf8d22c11afe691d9520c4.tar.gz krino-26c94eb3db62ec6eebbf8d22c11afe691d9520c4.zip | |
krino: release 0.0.1 — man pages, install, examples, cross and release, README, changelogv0.0.1
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.
Diffstat (limited to 'cmd/krino/history_test.go')
| -rw-r--r-- | cmd/krino/history_test.go | 63 |
1 files changed, 63 insertions, 0 deletions
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") + } +} |
