golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

invalid package default when destination is in the same directory #252

Open poy opened 5 years ago

poy commented 5 years ago

The default package name is mock_<CURRENT_PACKAGE>. This is fine if the destination is outside the current directory, however it is invalid if you place it in the same directory as the source. A valid package would have to be either <CURRENT_PACKAGE> or <CURRENT_PACKAGE>_test.

gertcuykens commented 5 years ago

Note that this will create a import cycle

mockgen -destination app_test.go -source=app.pb.go -package=main
package main

import (
    x "."
    context "context"
    gomock "github.com/golang/mock/gomock"
    grpc "google.golang.org/grpc"
    reflect "reflect"
)

Suggest by default to not use x "." so that one can generate mock files in the same directory without using a subdirectory

poy commented 5 years ago

@gertcuykens this looks related to #230. Are you using modules outside the go gopath when you get these results?

gertcuykens commented 5 years ago

Yes correct

codyoss commented 4 years ago

You are right the default is not great. An option here might be to default the package name to <CURRENT_PACKAGE>_test if both source and dest files are in the same location. That way we don't change peoples imports with the current behavior, but we give people code that will compile if they attempt to generate in the same directory as the source.