jennifer
jennifer copied to clipboard
Qualify names when generating code for external _test package
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)
I understand, and yes this feels like a bug... I'll have a think about the best solution.
Awesome, thanks!