-
Notifications
You must be signed in to change notification settings - Fork 10
/
clop_version_about_test.go
74 lines (58 loc) · 1.98 KB
/
clop_version_about_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package clop
import (
"bytes"
"fmt"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
// 测试显示信息, 普通命令
func Test_Version_Show(t *testing.T) {
type show struct {
Max int `clop:"short;long" usage:"max threads"`
}
var buf bytes.Buffer
cmd := New([]string{"-h"}).SetProcName("Test_Version_Show").SetVersion("v0.0.2").SetExit(false).SetOutput(&buf)
cmd.MustBind(&show{})
assert.NotEqual(t, strings.Index(buf.String(), "print version information"), -1)
assert.NotEqual(t, strings.Index(buf.String(), "print the help information"), -1)
}
// 测试about信息
func Test_About_Show(t *testing.T) {
var buf bytes.Buffer
cmd := New([]string{"-h"}).SetProcName("Test_Version_Show").SetAbout("about信息").SetExit(false).SetOutput(&buf)
cmd.MustBind(&git{})
assert.NotEqual(t, strings.Index(buf.String(), "about信息"), -1)
}
// 测试-V
func Test_Version_Option_Short(t *testing.T) {
var buf bytes.Buffer
procName := "Test_Version_Option_Short"
version := "v0.2.0"
cmd := New([]string{"-V"}).SetProcName(procName).SetVersion(version).SetExit(false).SetOutput(&buf)
cmd.MustBind(&git{})
assert.NotEqual(t, strings.Index(buf.String(), version), -1)
}
// 测试 --version
func Test_Version_Option_Long(t *testing.T) {
var buf bytes.Buffer
procName := "Test_Version_Option_Short"
version := "v0.2.0"
cmd := New([]string{"--version"}).SetProcName(procName).SetVersion(version).SetExit(false).SetOutput(&buf)
cmd.MustBind(&git{})
assert.NotEqual(t, strings.Index(buf.String(), version), -1)
}
// 测试-V
func Test_Version_Option_Short_Replace(t *testing.T) {
type dup struct {
Version string `clop:"-V" usage:"usage"`
}
d := &dup{}
var buf bytes.Buffer
procName := "Test_Version_Option_Short"
version := "v0.2.0"
cmd := New([]string{"-V", "1"}).SetProcName(procName).SetVersion(version).SetExit(false).SetOutput(&buf)
cmd.MustBind(d)
assert.Equal(t, d.Version, "1")
assert.Equal(t, strings.Index(buf.String(), fmt.Sprintf("%s %s\n", procName, version)), -1)
}