diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 22:32:00 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-14 22:32:00 +0200 |
| commit | 8227de6a887c8600746b06d1287cb2b00de77e28 (patch) | |
| tree | d3370476344ee22c699270457d05c846453ad0d7 /cmd/krino/history_test.go | |
| parent | a91b713dcec4d17f76155f0cd6b26903c59b9c19 (diff) | |
| download | krino-8227de6a887c8600746b06d1287cb2b00de77e28.tar.gz krino-8227de6a887c8600746b06d1287cb2b00de77e28.zip | |
plan 10: commands refuse global flags they do not use
Diffstat (limited to 'cmd/krino/history_test.go')
| -rw-r--r-- | cmd/krino/history_test.go | 36 |
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) + } +} |
