Skip to content

Qualify names when generating code for external _test package #73

Open
@sagikazarmark

Description

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions