Skip to content

Commit b9ed3cd

Browse files
committed
deprecate CompileTest*
1 parent 2a5bf77 commit b9ed3cd

File tree

2 files changed

+21
-161
lines changed

2 files changed

+21
-161
lines changed

gexec/build.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ A path pointing to this binary is returned.
7474
7575
CompileTest uses the $GOPATH set in your environment. If $GOPATH is not set and you are using Go 1.8+,
7676
it will use the default GOPATH instead. It passes the variadic args on to `go test`.
77+
78+
Deprecated: CompileTest makes GOPATH assumptions that don't translate well to the go modules world.
7779
*/
7880
func CompileTest(packagePath string, args ...string) (compiledPath string, err error) {
7981
return doCompileTest(build.Default.GOPATH, packagePath, nil, args...)
8082
}
8183

8284
/*
8385
GetAndCompileTest is identical to CompileTest but `go get` the package before compiling tests.
86+
87+
Deprecated: GetAndCompileTest makes GOPATH assumptions that don't translate well to the go modules world.
8488
*/
8589
func GetAndCompileTest(packagePath string, args ...string) (compiledPath string, err error) {
8690
if err := getForTest(build.Default.GOPATH, packagePath, []string{"GO111MODULE=off"}); err != nil {
@@ -92,13 +96,17 @@ func GetAndCompileTest(packagePath string, args ...string) (compiledPath string,
9296

9397
/*
9498
CompileTestWithEnvironment is identical to CompileTest but allows you to specify env vars to be set at build time.
99+
100+
Deprecated: CompileTestWithEnvironment makes GOPATH assumptions that don't translate well to the go modules world.
95101
*/
96102
func CompileTestWithEnvironment(packagePath string, env []string, args ...string) (compiledPath string, err error) {
97103
return doCompileTest(build.Default.GOPATH, packagePath, env, args...)
98104
}
99105

100106
/*
101107
GetAndCompileTestWithEnvironment is identical to GetAndCompileTest but allows you to specify env vars to be set at build time.
108+
109+
Deprecated: GetAndCompileTestWithEnvironment makes GOPATH assumptions that don't translate well to the go modules world.
102110
*/
103111
func GetAndCompileTestWithEnvironment(packagePath string, env []string, args ...string) (compiledPath string, err error) {
104112
if err := getForTest(build.Default.GOPATH, packagePath, append(env, "GO111MODULE=off")); err != nil {
@@ -110,6 +118,8 @@ func GetAndCompileTestWithEnvironment(packagePath string, env []string, args ...
110118

111119
/*
112120
CompileTestIn is identical to CompileTest but allows you to specify a custom $GOPATH (the first argument).
121+
122+
Deprecated: CompileTestIn makes GOPATH assumptions that don't translate well to the go modules world.
113123
*/
114124
func CompileTestIn(gopath string, packagePath string, args ...string) (compiledPath string, err error) {
115125
return doCompileTest(gopath, packagePath, nil, args...)

gexec/build_test.go

Lines changed: 11 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,22 @@ import (
1414
var packagePath = "./_fixture/firefly"
1515

1616
var _ = Describe(".Build", func() {
17-
When("there have been previous calls to CompileTest", func() {
17+
It("compiles the specified package", func() {
18+
compiledPath, err := gexec.Build(packagePath)
19+
Expect(err).ShouldNot(HaveOccurred())
20+
Expect(compiledPath).Should(BeAnExistingFile())
21+
Expect(filepath.Base(compiledPath)).Should(MatchRegexp(`firefly(|.exe)$`))
22+
})
23+
24+
Context("and CleanupBuildArtifacts has been called", func() {
1825
BeforeEach(func() {
19-
_, err := gexec.CompileTest(packagePath)
20-
Expect(err).ShouldNot(HaveOccurred())
26+
gexec.CleanupBuildArtifacts()
2127
})
2228

2329
It("compiles the specified package", func() {
24-
compiledPath, err := gexec.Build(packagePath)
30+
fireflyPath, err := gexec.Build(packagePath)
2531
Expect(err).ShouldNot(HaveOccurred())
26-
Expect(compiledPath).Should(BeAnExistingFile())
27-
Expect(filepath.Base(compiledPath)).Should(MatchRegexp(`firefly(|.exe)$`))
28-
})
29-
30-
Context("and CleanupBuildArtifacts has been called", func() {
31-
BeforeEach(func() {
32-
gexec.CleanupBuildArtifacts()
33-
})
34-
35-
It("compiles the specified package", func() {
36-
fireflyPath, err := gexec.Build(packagePath)
37-
Expect(err).ShouldNot(HaveOccurred())
38-
Expect(fireflyPath).Should(BeAnExistingFile())
39-
})
32+
Expect(fireflyPath).Should(BeAnExistingFile())
4033
})
4134
})
4235

@@ -130,149 +123,6 @@ var _ = Describe(".BuildIn", func() {
130123
})
131124
})
132125

133-
var _ = Describe(".CompileTest", func() {
134-
Context("a remote package", Label("network"), func() {
135-
const remotePackage = "github.com/onsi/ginkgo/types"
136-
137-
It("compiles the specified test package", func() {
138-
compiledPath, err := gexec.GetAndCompileTest(remotePackage)
139-
Expect(err).ShouldNot(HaveOccurred())
140-
Expect(compiledPath).Should(BeAnExistingFile())
141-
})
142-
})
143-
144-
When("there have been previous calls to CompileTest", func() {
145-
BeforeEach(func() {
146-
_, err := gexec.CompileTest(packagePath)
147-
Expect(err).ShouldNot(HaveOccurred())
148-
})
149-
150-
It("compiles the specified test package", func() {
151-
compiledPath, err := gexec.CompileTest(packagePath)
152-
Expect(err).ShouldNot(HaveOccurred())
153-
Expect(compiledPath).Should(BeAnExistingFile())
154-
})
155-
156-
Context("and CleanupBuildArtifacts has been called", func() {
157-
BeforeEach(func() {
158-
gexec.CleanupBuildArtifacts()
159-
})
160-
161-
It("compiles the specified test package", func() {
162-
fireflyTestPath, err := gexec.CompileTest(packagePath)
163-
Expect(err).ShouldNot(HaveOccurred())
164-
Expect(fireflyTestPath).Should(BeAnExistingFile())
165-
})
166-
})
167-
})
168-
169-
When("there have been previous calls to Build", func() {
170-
BeforeEach(func() {
171-
_, err := gexec.Build(packagePath)
172-
Expect(err).ShouldNot(HaveOccurred())
173-
})
174-
175-
It("compiles the specified test package", func() {
176-
compiledPath, err := gexec.CompileTest(packagePath)
177-
Expect(err).ShouldNot(HaveOccurred())
178-
Expect(compiledPath).Should(BeAnExistingFile())
179-
})
180-
181-
Context("and CleanupBuildArtifacts has been called", func() {
182-
BeforeEach(func() {
183-
gexec.CleanupBuildArtifacts()
184-
})
185-
186-
It("compiles the specified test package", func() {
187-
fireflyTestPath, err := gexec.CompileTest(packagePath)
188-
Expect(err).ShouldNot(HaveOccurred())
189-
Expect(fireflyTestPath).Should(BeAnExistingFile())
190-
})
191-
})
192-
})
193-
})
194-
195-
var _ = Describe(".CompileTestWithEnvironment", func() {
196-
var err error
197-
env := []string{
198-
"GOOS=linux",
199-
"GOARCH=amd64",
200-
}
201-
202-
Context("a remote package", Label("network"), func() {
203-
const remotePackage = "github.com/onsi/ginkgo/types"
204-
205-
It("compiles the specified test package with the specified env vars", func() {
206-
compiledPath, err := gexec.GetAndCompileTestWithEnvironment(remotePackage, env)
207-
Expect(err).ShouldNot(HaveOccurred())
208-
Expect(compiledPath).Should(BeAnExistingFile())
209-
})
210-
})
211-
212-
It("compiles the specified test package with the specified env vars", func() {
213-
compiledPath, err := gexec.CompileTestWithEnvironment(packagePath, env)
214-
Expect(err).ShouldNot(HaveOccurred())
215-
Expect(compiledPath).Should(BeAnExistingFile())
216-
})
217-
218-
It("returns the environment to a good state", func() {
219-
_, err = gexec.CompileTestWithEnvironment(packagePath, env)
220-
Expect(err).ShouldNot(HaveOccurred())
221-
Expect(os.Environ()).ShouldNot(ContainElement("GOOS=linux"))
222-
})
223-
})
224-
225-
var _ = Describe(".CompiledTestIn", func() {
226-
const target = "github.com/onsi/gomega/gexec/_fixture/firefly"
227-
228-
var (
229-
original string
230-
gopath string
231-
)
232-
233-
BeforeEach(func() {
234-
var err error
235-
original = os.Getenv("GOPATH")
236-
gopath, err = gutil.MkdirTemp("", "")
237-
Expect(err).NotTo(HaveOccurred())
238-
Expect(os.Setenv("GOPATH", filepath.Join(os.TempDir(), "emptyFakeGopath"))).To(Succeed())
239-
Expect(os.Environ()).To(ContainElement(fmt.Sprintf("GOPATH=%s", filepath.Join(os.TempDir(), "emptyFakeGopath"))))
240-
})
241-
242-
AfterEach(func() {
243-
if original == "" {
244-
Expect(os.Unsetenv("GOPATH")).To(Succeed())
245-
} else {
246-
Expect(os.Setenv("GOPATH", original)).To(Succeed())
247-
}
248-
if gopath != "" {
249-
os.RemoveAll(gopath)
250-
}
251-
})
252-
253-
Context("a remote package", Label("network"), func() {
254-
const remotePackage = "github.com/onsi/ginkgo/types"
255-
256-
It("compiles the specified test package", func() {
257-
compiledPath, err := gexec.GetAndCompileTestIn(gopath, remotePackage)
258-
Expect(err).ShouldNot(HaveOccurred())
259-
Expect(compiledPath).Should(BeAnExistingFile())
260-
})
261-
})
262-
263-
It("appends the gopath env var", func() {
264-
compiledPath, err := gexec.CompileTestIn(gopath, target)
265-
Expect(err).NotTo(HaveOccurred())
266-
Expect(compiledPath).Should(BeAnExistingFile())
267-
})
268-
269-
It("resets GOPATH to its original value", func() {
270-
_, err := gexec.CompileTestIn(gopath, target)
271-
Expect(err).NotTo(HaveOccurred())
272-
Expect(os.Getenv("GOPATH")).To(Equal(filepath.Join(os.TempDir(), "emptyFakeGopath")))
273-
})
274-
})
275-
276126
func copyFile(source, directory, basename string) {
277127
Expect(os.MkdirAll(directory, 0755)).To(Succeed())
278128
content, err := gutil.ReadFile(source)

0 commit comments

Comments
 (0)