qur / withmock

Automatic Go package mock generation tool
Other
71 stars 9 forks source link

ERROR when testing dir outside GOPATH #24

Closed ezk84 closed 10 years ago

ezk84 commented 10 years ago

I have followed the instructions to the letter on a Ubuntu 12.04 install. I can withmock go test scenarios in the withmock source code.

What I can't seem to do is test when the source directory isn't within the $GOPATH\src directory. This is unfortunately the usual case with Google App Engine go apps (which would benefit immensely from the ability to mock external services).

Here's an example to reproduce:

example.go

package example
import "fmt"

func PrintIt(a int) {
    fmt.Println("Got a", a)
}

example_test.go

package example
import (
    "testing"
    "code.google.com/p/gomock/gomock"
    mockfmt "fmt" // mock
)

func TestPrintIt(t *testing.T) {
    ctrl := gomock.NewController(t)
    defer ctrl.Finish()
    mockfmt.MOCK().SetController(ctrl)

    mockfmt.EXPECT().Println("Got a", 10)

    PrintIt(10)
}

Put this in $GOPATH/src/example and withmock go test should work. Take the example dir outside, and it errors out with

ERROR: Unable to find package: _/path/to/example
qur commented 10 years ago

I've had no occasion to try testing packages outside of GOPATH, it simply didn't occur to me. Should work now hopefully ...

qur commented 10 years ago

Assuming this is now fixed ...