Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qualify names when generating code for external _test package #73

Open
sagikazarmark opened this issue Sep 22, 2020 · 2 comments
Open

Comments

@sagikazarmark
Copy link

Code generated by the following (semi-pseudo) example does not compile:

code := jen.NewFilePathName("path/to/pkg", "pkg_test")

code.ImportName("path/to/pkg", "pkg")

code.Qual("path/to/pkg", "MyStruct")

The problem is that the generated code in pkg_test will not properly be qualified with the package import (path/to/pkg), because the package path is actually the same. In my use case adding a _test suffix to the file package path solved the issue, but it doesn't feel right. (What if I actually have a pkg_test package?)

Not sure what the best solution would be here. Maybe handle _test suffixes? (The problem is that technically you can have other package suffixes in a single package, if you manually pass those files to go tool compile, but I think a special case for _test suffixes would suffice for the time being.)

(Sorry for the dummy example, but I think it demonstrates the issue)

@dave
Copy link
Owner

dave commented Sep 22, 2020

I understand, and yes this feels like a bug... I'll have a think about the best solution.

@sagikazarmark
Copy link
Author

Awesome, thanks!

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

No branches or pull requests

2 participants