diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-11 14:47:10 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-11 15:01:57 +0200 |
| commit | 42b02c47be9b285099203e44a2570636d4ca6f03 (patch) | |
| tree | 82bcb9e19bd886f36e1ca7b2d94a204c988f1fd1 /cmd/krino/main_test.go | |
| download | krino-42b02c47be9b285099203e44a2570636d4ca6f03.tar.gz krino-42b02c47be9b285099203e44a2570636d4ca6f03.zip | |
krino: foundation — sexp reader, config language, init/new/check
Diffstat (limited to 'cmd/krino/main_test.go')
| -rw-r--r-- | cmd/krino/main_test.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/cmd/krino/main_test.go b/cmd/krino/main_test.go new file mode 100644 index 0000000..1caab6b --- /dev/null +++ b/cmd/krino/main_test.go @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import ( + "bytes" + "strings" + "testing" + + "krino/internal/config" +) + +// runCLI drives run() and returns its exit code and output. +func runCLI(t *testing.T, args ...string) (int, string, string) { + t.Helper() + var out, errb bytes.Buffer + code := run(args, &out, &errb) + return code, out.String(), errb.String() +} + +func TestVersion(t *testing.T) { + code, out, _ := runCLI(t, "--version") + if code != 0 || out != "krino dev\n" { + t.Fatalf("got %d %q, want 0 %q", code, out, "krino dev\n") + } +} + +func TestHelp(t *testing.T) { + for _, arg := range []string{"-h", "--help"} { + code, out, _ := runCLI(t, arg) + if code != 0 || !strings.HasPrefix(out, "usage: krino") { + t.Errorf("%s: got %d %q", arg, code, out) + } + } +} + +func TestBadFlag(t *testing.T) { + code, _, errOut := runCLI(t, "--bogus") + if code != 2 || !strings.Contains(errOut, "flag provided but not defined: -bogus") { + t.Fatalf("got %d %q", code, errOut) + } +} + +// TestCommandsAreReserved is item E: every subcommand name must also be a +// reserved directory name, so a directory can never shadow a command. +func TestCommandsAreReserved(t *testing.T) { + for name := range commands { + if !config.Reserved[name] { + t.Errorf("command %q is not in config.Reserved", name) + } + } +} + +func TestSortNotYet(t *testing.T) { + code, _, errOut := runCLI(t) + if code != 2 || !strings.Contains(errOut, "not implemented yet") { + t.Fatalf("got %d %q", code, errOut) + } +} |
