gotests icon indicating copy to clipboard operation
gotests copied to clipboard

Underscores in Generated Tests

Open taiidani opened this issue 6 years ago • 4 comments

Our team is currently having a discussion over underscores being present in the generated Tests for gotests. These underscores appear to match the naming convention defined in https://golang.org/pkg/testing/#hdr-Examples but that convention implies that is for Examples only, not Tests.

Wondering what discussion occurred that led to this convention in gotests applying for the generated Tests? We'd love to know!

taiidani avatar Aug 02 '19 23:08 taiidani

@taiidani: It was a solution to the fact that in Golang you can have a function called Foo and foo in the same package or on the same struct. So if you generated a test for both, they would have identical test names. The examples link shows an example of when you can have the underscores, but I agree that it's not the most aesthetically pleasing. :)

That being said, there was no formal discussion with the Go core team about this feature, and I would love to get other opinions.

cweill avatar Aug 14 '19 00:08 cweill

Ah, thank you for the explanation! Yes the discussion on our side centered mainly around aesthetics. Not a big deal, but it cut a swath through our team on which each engineer preferred.

We've been using the test auto-generator built into VS Code's Golang extension to get quickly generated table tests. Some of the argument centered exactly around your explanation -- that in order to delineate between exported and unexported functions some extra symbol (the _) would be required. It makes sense, and I bet can lead to excellent IDE integrations like "Jump to Test for Function" / "Jump to Function for Test" actions. I'd hoped that the formatting decision was more baked into the Golang standards though in order to justify that feature :(

If you think it's worth additional discussion, perhaps I should create an equivalent issue in the main golang/go repository? Either way, thanks again for clarifying!

taiidani avatar Aug 14 '19 15:08 taiidani

@taiidani: I agree, it might be worth reaching out to the Golang team and getting their opinion.

cweill avatar Aug 16 '19 03:08 cweill

@cweill Upgraded this to a proposal issue in golang/go: https://github.com/golang/go/issues/33688

taiidani avatar Aug 16 '19 16:08 taiidani