Skip to content

Skip _test.go files when parsing enum constants - #26

Merged
umputun merged 2 commits into
masterfrom
skip-test-files
Oct 31, 2026
Merged

umputun merged 2 commits into
masterfrom
skip-test-files

Conversation

@umputun

@umputun umputun commented Oct 31, 2026

Copy link
Copy Markdown
Member

Parse groups every package found in the directory and keeps the name of whichever one map iteration visits last. With a black-box test file (package foo_test) next to the enum, the generated <type>_enum.go got package foo_test in most runs (7 of 8 in a repro) and go build failed with "found packages foo and foo_test". Constants declared in test files also leaked into the enum, though the generated file is not a test file and can never reference them.

Parse now skips _test.go files. TestParseSkipsTestFiles covers both an internal and an external test file. Two existing fixtures fed to Parse were named *_test.go and are renamed to plain .go files, assertions unchanged.

If an earlier run already wrote a broken <type>_enum.go with package foo_test, delete it once before regenerating, since that file itself still declares the second package.

The second commit adds two docs/backlog/ items: a //go:build ignore file of another package in the same directory still makes the package choice random, and README does not mention that test files are skipped.

Related to #11

Parse grouped every package in the directory and kept the name of
whichever came last in map order. With a black-box test file
(package foo_test) next to the enum, the generated file got
"package foo_test" in most runs and broke the build. Constants from
test files also leaked into the enum, though the generated non-test
file can never reference them.

Test files are now ignored. Two fixtures fed to Parse were named
*_test.go and are renamed to plain .go files.

Related to #11
A //go:build ignore file of another package in the enum directory still
makes Parse pick the package clause at random. README does not say that
_test.go files are skipped.

Related to #11
Copilot AI balanced review requested due to automatic review settings October 31, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@umputun
umputun merged commit ba90982 into master Oct 31, 2026
4 checks passed
@umputun
umputun deleted the skip-test-files branch October 31, 2026 17:32
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

Successfully merging this pull request may close these issues.

2 participants