-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusage_test.go
More file actions
49 lines (41 loc) · 1.01 KB
/
usage_test.go
File metadata and controls
49 lines (41 loc) · 1.01 KB
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
package main
import (
"bytes"
"flag"
"strings"
"testing"
)
func TestPrintUsage(t *testing.T) {
var stdout, stderr bytes.Buffer
fs := flag.NewFlagSet(Name, flag.ContinueOnError)
cfg := newConfig(fs, nil)
printUsage(&stdout, &stderr, false, fs, cfg)
out := stdout.String()
err := stderr.String()
if !strings.Contains(out, "recursively") {
t.Error("Expected usage in stdout", out)
}
if len(err) > 0 {
t.Error("Did not expect usage in stderr", len(err))
}
stdout.Reset()
stderr.Reset()
printUsage(&stdout, &stderr, true, fs, cfg)
out = stdout.String()
err = stderr.String()
if !strings.Contains(err, "recursively") {
t.Error("Expected usage in stderr", out)
}
if len(out) > 0 {
t.Error("Did not expect usage in stdout", len(err))
}
cfg.configPathHelp = "Test"
stdout.Reset()
stderr.Reset()
printUsage(&stdout, &stderr, true, fs, cfg)
out = stdout.String()
err = stderr.String()
if !strings.Contains(err, "Test") {
t.Error("Usage did not detect configPathHelpError out:", out, "err:", err)
}
}