diff options
Diffstat (limited to 'internal/cli/cli_test.go')
| -rw-r--r-- | internal/cli/cli_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go new file mode 100644 index 0000000..85097ed --- /dev/null +++ b/internal/cli/cli_test.go @@ -0,0 +1,51 @@ +package cli + +import ( + "bytes" + "strings" + "testing" +) + +func TestHelp(t *testing.T) { + var out, errb bytes.Buffer + code := Run([]string{"help"}, nil, &out, &errb) + if code != 0 || !strings.Contains(out.String(), "lectio") { + t.Errorf("help code=%d out=%q", code, out.String()) + } +} + +func TestUnknownCommand(t *testing.T) { + var out, errb bytes.Buffer + if code := Run([]string{"bogus"}, nil, &out, &errb); code != 2 { + t.Errorf("unknown cmd code=%d want 2", code) + } +} + +func TestVersion(t *testing.T) { + var out, errb bytes.Buffer + if code := Run([]string{"--version"}, nil, &out, &errb); code != 0 { + t.Errorf("version code=%d", code) + } +} + +// TestBadDate exercises the "date" subcommand's usage-error path (bad +// YYYY-MM-DD format) without touching the network: format validation +// happens before any fetch is attempted. +func TestBadDate(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) + var out, errb bytes.Buffer + if code := Run([]string{"date", "13-13-13"}, nil, &out, &errb); code != 2 { + t.Errorf("bad date code=%d want 2 (stderr=%q)", code, errb.String()) + } +} + +// TestUnknownVersion exercises "show"'s version-validation usage-error path +// without touching the network: the version code is checked against the +// five known codes before any fetch is attempted. +func TestUnknownVersion(t *testing.T) { + t.Setenv("XDG_CONFIG_HOME", t.TempDir()) + var out, errb bytes.Buffer + if code := Run([]string{"show", "zzz"}, nil, &out, &errb); code != 2 { + t.Errorf("unknown version code=%d want 2 (stderr=%q)", code, errb.String()) + } +} |
