summaryrefslogtreecommitdiff
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.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/cmd/krino/history_test.go b/cmd/krino/history_test.go
index fce38ad..6d8c1e4 100644
--- a/cmd/krino/history_test.go
+++ b/cmd/krino/history_test.go
@@ -516,3 +516,39 @@ func TestMinAgeRejectedOutsideSortAndExplain(t *testing.T) {
t.Errorf("-n --min-age 0: exit %d %s", code, errOut)
}
}
+
+// TestIgnoredGlobalFlagsAreRefused: a global flag a command does not use is
+// refused instead of silently ignored, so "krino -n new ..." or "krino -n
+// init" - meant as a preview - cannot write config (re-review cli F4).
+func TestIgnoredGlobalFlagsAreRefused(t *testing.T) {
+ h := home(t)
+ if code, _, errOut := runCLI(t, "-n", "init"); code != 2 || !strings.Contains(errOut, "-n") {
+ t.Errorf("-n init: exit %d %q", code, errOut)
+ }
+ if _, err := os.Stat(filepath.Join(h, ".config", "krino", "krino.conf")); !os.IsNotExist(err) {
+ t.Fatalf("-n init wrote the config: %v", err)
+ }
+ if code, _, errOut := runCLI(t, "init"); code != 0 {
+ t.Fatal(errOut)
+ }
+ dl := filepath.Join(h, "dl")
+ os.MkdirAll(dl, 0o755)
+ for _, args := range [][]string{
+ {"-n", "new", "dl", dl},
+ {"-y", "check"},
+ {"--json", "log"},
+ {"-v", "log"},
+ {"--json", "undo", "-n"},
+ {"-v", "undo", "-n"},
+ } {
+ if code, _, errOut := runCLI(t, args...); code != 2 || !strings.Contains(errOut, "does not take") {
+ t.Errorf("krino %q: exit %d, stderr %q; want 2, refused", args, code, errOut)
+ }
+ }
+ if _, err := os.Stat(filepath.Join(h, ".config", "krino", "dirs", "dl.conf")); !os.IsNotExist(err) {
+ t.Errorf("-n new wrote a directory file: %v", err)
+ }
+ if code, _, errOut := runCLI(t, "log", "-n", "3"); code != 0 {
+ t.Errorf("log -n 3 (its own count flag) was refused: %d %q", code, errOut)
+ }
+}