1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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())
}
}
|