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()) } }