cmd/test2json: output is incorrect and fails to mark tests if using TestMain
#49866
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
In summary, using the JSON output format seems to not function correctly when using
TestMain()
.Assume two tests are available:
TestMain()
TestSomethingElse()
TestMain()
is reserved and triggersTestSomethingElse()
withm.Run()
. I noticed this when using ago test
to JUnit conversion tool. Initially, I thought that the bug was in the JUnit conversion tool, but then noted that the actions outputted by thejson
flag (in other wordsgo tool test2json
) had changed when I addedTestMain()
:TestMain()
passes, it does not get the"Action": "run"
field, and it is missing the"Test":
field in the JSON output. If it fails, it is registered as an individual test and has appropriate action fields.TestSomethingElse()
is called from TestMain, it is missing its"Test":
field in its JSON entirely on pass, but registers actions correctly if it fails.Without TestMain():
With TestMain() calling it:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
You can't actually run this in the code playground, as you need to run
go tool test2json
on a compiledgo test
binary (or use the-json
flag)Here's some test code you can paste into your environment, it's just TestMain() and a dummy test. https://go.dev/play/p/KDtlzPW9gDU
Compile it and run the binary as
go tool test2json -t ./your_binary
.The text was updated successfully, but these errors were encountered: