aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/history_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/krino/history_test.go')
-rw-r--r--cmd/krino/history_test.go56
1 files changed, 53 insertions, 3 deletions
diff --git a/cmd/krino/history_test.go b/cmd/krino/history_test.go
index 1a9ea2b..fce38ad 100644
--- a/cmd/krino/history_test.go
+++ b/cmd/krino/history_test.go
@@ -143,7 +143,7 @@ func TestFinalizeUndoPlanMarksUnapprovedAsDeclined(t *testing.T) {
{File: "b"}, // index 1: not approved -> declined
{File: "c", Refused: "gone"}, // index 2: refused, never declined
}}
- out := finalizeUndoPlan(up, map[int]bool{0: true})
+ out, _ := finalizeUndoPlan(up, map[int]bool{0: true}, 'c')
if len(out.Files) != 3 {
t.Fatalf("files = %+v, want all three carried through", out.Files)
}
@@ -203,8 +203,8 @@ func TestReviewUndoWriteStopsAsking(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if action != 'c' || !approved[0] || approved[1] || approved[2] {
- t.Errorf("approved = %v action = %q; want only index 0", approved, action)
+ if action != 'w' || !approved[0] || len(approved) != 1 {
+ t.Errorf("approved = %v action = %q; want 'w' with only index 0 decided", approved, action)
}
if !strings.Contains(out.String(), "'t' is not y, n, a, w or q") || strings.Contains(out.String(), "[t]") {
t.Errorf("undo review should reject t and not offer it:\n%s", out)
@@ -466,3 +466,53 @@ func TestUndoWithoutRunContinuesTheLastUndo(t *testing.T) {
t.Fatalf("undo -n after a failed undo: exit %d\n%s\n%s", code, out, errOut)
}
}
+
+// TestReviewUndoMatchesReview: undo's per-file review behaves as review's
+// does (review cli F2): n is recorded, each choice is echoed in red, and w
+// leaves the files it never reached out of the plan, counted as not
+// reviewed rather than logged as declined.
+func TestReviewUndoMatchesReview(t *testing.T) {
+ out := new(strings.Builder)
+ files := undoFiles("a", "b", "c")
+ approved, action, err := reviewUndoFiles(strings.NewReader("cynw"), out, files, palette{on: true})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if action != 'w' || !approved[0] || approved[1] {
+ t.Fatalf("approved = %v action = %q", approved, action)
+ }
+ if v, ok := approved[1]; !ok || v {
+ t.Errorf("b should be decided as no: %v", approved)
+ }
+ for _, want := range []string{"\x1b[31m→ yes\x1b[0m", "\x1b[31m→ no\x1b[0m"} {
+ if !strings.Contains(out.String(), want) {
+ t.Errorf("no %q echo in:\n%q", want, out)
+ }
+ }
+ up := &engine.UndoPlan{Run: "r", Files: files}
+ plan, notReviewed := finalizeUndoPlan(up, approved, action)
+ if notReviewed != 1 || len(plan.Files) != 2 || plan.Files[0].Declined || !plan.Files[1].Declined {
+ t.Errorf("finalize: notReviewed %d, files %+v; want a, declined b, c left out", notReviewed, plan.Files)
+ }
+}
+
+// TestMinAgeRejectedOutsideSortAndExplain: --min-age only changes sorting
+// and explain; any other command refuses it rather than silently ignoring
+// a mistyped value, and an empty value is an error (review cli F4).
+func TestMinAgeRejectedOutsideSortAndExplain(t *testing.T) {
+ matchingFixture(t)
+ for _, args := range [][]string{
+ {"undo", "-n", "--min-age", "1d"},
+ {"--min-age", "garbage", "undo", "-n"},
+ {"check", "--min-age", "1d"},
+ {"log", "--min-age", "1d"},
+ {"-n", "--min-age="},
+ } {
+ if code, _, errOut := runCLI(t, args...); code != 2 || !strings.Contains(errOut, "--min-age") {
+ t.Errorf("krino %q: exit %d, stderr %q; want 2 naming --min-age", args, code, errOut)
+ }
+ }
+ if code, _, errOut := runCLI(t, "-n", "--min-age", "0"); code != 0 {
+ t.Errorf("-n --min-age 0: exit %d %s", code, errOut)
+ }
+}