Closed karim-eclipseio closed 10 years ago
What packages are you importing? Do you have a local package called "encoding"?
No, I am importing encoding/base64, encoding/json, both part of go.
This patch will make it run:
Modified lib/mock.go
diff --git a/lib/mock.go b/lib/mock.go
index 5a180fc..96f362d 100644
--- a/lib/mock.go
+++ b/lib/mock.go
@@ -900,6 +900,10 @@ func (m *mockGen) file(out io.Writer, f *ast.File, filename string) error {
if impPath == "code.google.com/p/gomock/gomock" {
continue
}
+ if impPath == "encoding" {
+ fmt.Println("Skipping encoding...")
+ continue
+ }
if s.Doc != nil {
fmt.Fprintf(out, "%s", s.Doc.Text())
}
but with error
ERROR: Failed to install 'github.com/EclipseUSA/withmock': exit status 2
output:
# github.com/EclipseUSA/withmock/lib
../../../../github.com/EclipseUSA/withmock/lib/lib_mock.go:104: type ifInfo has both field and method named EXPECT
../../../../github.com/EclipseUSA/withmock/lib/lib_mock.go:144: type mockGen has both field and method named EXPECT
I'm definitely confused. For that patch to have any effect suggests that there is a line 'import "encoding"' somewhere. Replacing 'fmt.Println("Skipping encoding...")' with 'fmt.Println(filename, ": Skipping encoding...")' should be instructive.
The error you describe suggests that you are trying to import the withmock/lib library in the code under test (or the test code itself) - which isn't supported and won't work.
Thanks for the tip, all is working now.
Turns out, I was indeed importing withmock in my test code, instead of gomock.
Also, we use gcfg (https://code.google.com/p/gcfg/) which seems to work with/detect different versions of go. This file was the culprit: https://code.google.com/p/gcfg/source/browse/go1_2.go, which if I were using go 1.2 would work as https://code.google.com/p/go/source/browse#hg%2Fsrc%2Fpkg%2Fencoding exists. I am unsure if you want to look at the // +build comments in withmock, let me know if I can help.
Hopefully this is fixed now ...
It is fixed in my env. Thanks!
$ withmock go test
ERROR: Failed to get name for 'encoding': External program 'go' failed (exit status 1), with output: can't load package: package encoding: no Go source files in /usr/local/go/src/pkg/encoding
ls -a shows all the go packages there. Is there something obvious I am doing wrong?