-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalias_test.go
45 lines (40 loc) · 1.03 KB
/
alias_test.go
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
package options
import (
"bytes"
"io"
"testing"
"github.com/pborman/getopt/v2"
)
func TestSetVar(t *testing.T) {
dw, hc, cl := getopt.DisplayWidth, getopt.HelpColumn, getopt.CommandLine
defer func() {
getopt.DisplayWidth, getopt.HelpColumn, getopt.CommandLine = dw, hc, cl
}()
SetDisplayWidth(42)
SetHelpColumn(17)
if getopt.DisplayWidth != 42 {
t.Errorf("Setting DisplayWidth got %d, want 42", getopt.DisplayWidth)
}
if getopt.HelpColumn != 17 {
t.Errorf("Setting HelpColumn got %d, want 17", getopt.HelpColumn)
}
}
func TestUsage(t *testing.T) {
// We screw up the usage function here so we can't test it further.
var w io.Writer
var buf bytes.Buffer
SetUsage(func() { w = &buf })
Usage()
if w != &buf {
t.Errorf("Usage did not call the function set by SetUsage")
}
cl := getopt.CommandLine
defer func() { getopt.CommandLine = cl }()
SetParameters("PARAMS")
SetProgram("TEST")
PrintUsage(&buf)
got, want := buf.String(), "Usage: TEST PARAMS\n"
if got != want {
t.Errorf("Got usage %q, want %q", got, want)
}
}