cmd/go/internal/test: go test -list doesn't always display all examples #21205
Labels
FrozenDueToAge
GoCommand
cmd/go
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
Go 1.9 adds a new feature described at https://beta.golang.org/doc/go1.9#go-test-list:
go test -help
says:It's issue #17209, implemented in CL 41195 (ba8ff87). /cc @nemith @mpvl
What version of Go are you using (
go version
)?go version go1.9rc1 darwin/amd64
What operating system and processor architecture are you using (
go env
)?What did you do?
I ran
go test -v
andgo test -list=Example
on a sample package with 3 examples, two of which are runnable (i.e., they have a "Output:" comment at the end), and one is not runnable (no "Output:" comment):Note, the above is just a minimal reproduce sample. I ran into this issue in a real Go package
github.com/shurcooL/issuesapp/httpclient
:What did you expect to see?
What did you see instead?
ExampleQuiet
is not listed ingo test -list=Example
output, even though it's a valid runnable example [1] that runs as part ofgo test -v
.[1] https://golang.org/cmd/go/#hdr-Description_of_testing_functions
Cause
The cause is simple and can be seen in the code implementing the feature at ba8ff87#diff-70e628298261565d825f7199d13042f2R972.
testing.listTests
function has this loop for printing examples:Notably, it checks that
example.Output != ""
. I'm assuming it does that to try to find runnable examples. However, some runnable examples (i.e., ones with last comment that starts with "Output:" or "Unordered output:") have empty expected output.They're still runnable, and should be included in output of
go test -list
, just like they are in output ofgo test -v
.The text was updated successfully, but these errors were encountered: