[go: up one dir, main page]

Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

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

Open
poy opened this issue Dec 12, 2018 · 4 comments
Open

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

poy opened this issue Dec 12, 2018 · 4 comments
Assignees

Comments

@poy
Copy link
Collaborator
poy commented Dec 12, 2018

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
Copy link
gertcuykens commented Dec 15, 2018

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
Copy link
Collaborator Author
poy commented Dec 15, 2018

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

@gertcuykens
Copy link

Yes correct

@codyoss
Copy link
Member
codyoss commented Jan 14, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants