-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathrunner_test.go
95 lines (83 loc) · 2.59 KB
/
runner_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
package command_test
import (
"log"
"os"
"path/filepath"
"testing"
"github.com/maxbrunsfeld/counterfeiter/v6/command"
. "github.com/onsi/gomega"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
)
func TestRunner(t *testing.T) {
spec.Run(t, "Runner", testRunner, spec.Report(report.Terminal{}))
}
func testRunner(t *testing.T, when spec.G, it spec.S) {
reset := func() {
os.Unsetenv("DOLLAR")
os.Unsetenv("GOFILE")
os.Unsetenv("GOLINE")
os.Unsetenv("GOPACKAGE")
}
it.Before(func() {
RegisterTestingT(t)
reset()
log.SetFlags(log.Llongfile)
})
it.After(func() {
reset()
})
when("counterfeiter has been invoked directly", func() {
it.Before(func() {
})
it("creates an invocation", func() {
i, err := command.Detect(filepath.Join(".", "..", "fixtures"), []string{"counterfeiter", ".", "AliasedInterface"}, false)
Expect(err).NotTo(HaveOccurred())
Expect(i).NotTo(BeNil())
Expect(i).To(HaveLen(1))
Expect(i[0].Args).To(HaveLen(3))
Expect(i[0].Args[1]).To(Equal("."))
Expect(i[0].Args[2]).To(Equal("AliasedInterface"))
})
})
when("counterfeiter is invoked in generate mode", func() {
it.Before(func() {
os.Unsetenv("DOLLAR")
os.Unsetenv("GOFILE")
os.Unsetenv("GOLINE")
os.Unsetenv("GOPACKAGE")
})
it("creates invocations", func() {
i, err := command.Detect(filepath.Join(".", "..", "fixtures"), []string{"counterfeiter", ".", "AliasedInterface"}, true)
Expect(err).NotTo(HaveOccurred())
Expect(i).NotTo(BeNil())
Expect(len(i)).To(Equal(19))
Expect(i[0].File).To(Equal("aliased_interfaces.go"))
Expect(i[0].Line).To(Equal(6))
Expect(i[0].Args).To(HaveLen(3))
Expect(i[0].Args[0]).To(Equal("counterfeiter"))
Expect(i[0].Args[1]).To(Equal("."))
Expect(i[0].Args[2]).To(Equal("AliasedInterface"))
})
})
when("counterfeiter has been invoked by go generate", func() {
it.Before(func() {
os.Setenv("DOLLAR", "$")
os.Setenv("GOFILE", "aliased_interfaces.go")
os.Setenv("GOLINE", "5")
os.Setenv("GOPACKAGE", "fixtures")
})
it("creates invocations but does not include generate mode as an invocation", func() {
i, err := command.Detect(filepath.Join(".", "..", "fixtures"), []string{"counterfeiter", ".", "AliasedInterface"}, false)
Expect(err).NotTo(HaveOccurred())
Expect(i).NotTo(BeNil())
Expect(len(i)).To(Equal(1))
Expect(i[0].File).To(Equal("aliased_interfaces.go"))
Expect(i[0].Line).To(Equal(5))
Expect(i[0].Args).To(HaveLen(3))
Expect(i[0].Args[0]).To(Equal("counterfeiter"))
Expect(i[0].Args[1]).To(Equal("."))
Expect(i[0].Args[2]).To(Equal("AliasedInterface"))
})
})
}