forked from kardianos/govendor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.go
121 lines (110 loc) · 2.33 KB
/
run_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"os"
"strings"
"testing"
"github.com/kardianos/govendor/internal/gt"
)
func Vendor(g *gt.GopathTest, name, argLine, expectedOutput string) {
os.Setenv("GO15VENDOREXPERIMENT", "1")
output := &bytes.Buffer{}
args := append([]string{"testing"}, strings.Split(argLine, " ")...)
msg, err := run(output, args)
if err != nil {
g.Fatalf("(%s) Error: %v", name, err)
}
if msg != MsgNone {
g.Fatalf("(%s) Printed help", name)
}
if strings.TrimSpace(output.String()) != strings.TrimSpace(expectedOutput) {
g.Fatalf("(%s) Got\n%s", name, output.String())
}
}
func TestSimple(t *testing.T) {
g := gt.New(t)
defer g.Clean()
g.Setup("co1/pk1",
gt.File("a.go", "co2/pk1", "co2/pk2"),
gt.File("b.go", "co2/pk1", "bytes"),
)
g.Setup("co2/pk1",
gt.File("a.go", "strings"),
)
g.Setup("co2/pk2",
gt.File("a.go", "strings"),
)
g.In("co1")
Vendor(g, "co1 init", "init", "")
Vendor(g, "", "list", `
e co2/pk1
e co2/pk2
l co1/pk1
`)
Vendor(g, "co1 add ext", "add +ext", "")
Vendor(g, "co1 list", "list", `
v co2/pk1
v co2/pk2
l co1/pk1
`)
}
func TestDuplicatePackage(t *testing.T) {
g := gt.New(t)
defer g.Clean()
g.Setup("co1/pk1",
gt.File("a.go", "co2/pk1", "co3/pk1"),
)
g.Setup("co2/pk1",
gt.File("a.go", "co3/pk1"),
)
g.Setup("co3/pk1",
gt.File("a.go", "strings"),
)
g.In("co2")
Vendor(g, "co2 init", "init", "")
Vendor(g, "co2 add", "add +ext", "")
g.In("co1")
Vendor(g, "co1 init", "init", "")
Vendor(g, "co1 pre list", "list", `
e co2/pk1
e co3/pk1
e co3/pk1
l co1/pk1
`)
Vendor(g, "co1 add", "add -long +ext", "")
Vendor(g, "co1 list", "list", `
v co2/pk1
v co3/pk1
l co1/pk1
`)
}
func TestEllipsis(t *testing.T) {
g := gt.New(t)
defer g.Clean()
g.Setup("co1/pk1",
gt.File("a.go", "co2/pk1", "co2/pk1/pk2"),
gt.File("b.go", "co2/pk1", "bytes"),
)
g.Setup("co2/pk1",
gt.File("a.go", "strings"),
)
g.Setup("co2/pk1/pk2",
gt.File("a.go", "strings"),
)
g.In("co1")
Vendor(g, "co1 init", "init", "")
Vendor(g, "", "list", `
e co2/pk1
e co2/pk1/pk2
l co1/pk1
`)
Vendor(g, "co1 add ext", "add co2/pk1/...", "")
Vendor(g, "co1 list", "list", `
v co2/pk1
v co2/pk1/pk2
l co1/pk1
`)
}