It'd be useful if the playground could run tests -- more like `go test` instead of `go run`. This is possible now (http://play.golang.org/p/K0gFil6jFC), but it's clumsy and non-obvious. Just to get the conversation started, here's a concrete proposal: * Tests and examples are supported, but not benchmarks. (Benchmarks are going to unreliable anyway, right?) * If main is not present and there is an appropriate test function (or example function with output), then the playground executes in test mode. Otherwise, behavior is unchanged. * "Test mode" is equivalent to `go test -v`. * Add text to the About page explaining how to use playground for tests.
CL https://golang.org/cl/102420043 mentions this issue.
@adg any new thoughts about this? I could bring that old CL back to life if you were interested.
If we're to do this, we could be more general: extend the API to accept multiple input files, which are built together as a package. We could even permit building a tree of packages. Then we could provide execution options (run, test, bench, others?) to run against those packages. I think the implementation of this would be pretty straightforward. The hardest part would be designing a nice JSON API for the requests.
@adg, we could even introduce magic comments as a way to mark new files, which is common in people's bug reports anyway.
But I see no reason to tie that feature to this. They seem separable.
Change https://golang.org/cl/98155 mentions this issue: playground: support running tests
I have committed a change based mostly on the way @josharian did it 3.5 years ago. I was going different direction at first but ended with something very close to that old change by Josh. At worst it was very good learning experience for me. I would be glad of somebody gave it a proper review.
Most helpful comment
If we're to do this, we could be more general: extend the API to accept multiple input files, which are built together as a package. We could even permit building a tree of packages. Then we could provide execution options (run, test, bench, others?) to run against those packages. I think the implementation of this would be pretty straightforward. The hardest part would be designing a nice JSON API for the requests.