-
Notifications
You must be signed in to change notification settings - Fork 18k
test: add JSON output support to the run.go program #56844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One complication to this I just discovered is that some of the misc/cgo tests (at least misc/cgo/stdio and misc/cgo/life) actually use the run.go runner. We'll need to rewrite those to not use run.go either by 1) just doing the tests directly because they're really not complicated or 2) exporting the functionality of run.go so tests can use it directly. For other tests, having some of run.go's functionality would actually be really nice, but I don't think it's necessary for these tests. |
I've started working on this more actively recently and made enough progress to post an update. I think I have a good idea for the general implementation plan here: as expected, it'll be to migrate to using The test/run.go runner handles tests, one for each .go file in the directories listed here (relative to GOROOT/test): Line 103 in 27b6ace
For example, using a recent tip commit, there's a total of 2424 test cases:
(That number is before any skips are applied due to build constraints or other factors, so it doesn't depend on the GOOS/GOARCH you're trying it on.) For each of those test cases, I plan to make a subtest in a new internal Go package. For prototyping I've used The test directory contains tests of the Go tool chain and runtime.
It includes black box tests, regression tests, and error output tests.
They are run as part of all.bash.
To run just these tests, execute:
- ../bin/go run run.go
+ ../bin/go test internal/testdir
To run just tests from specified files in this directory, execute:
- ../bin/go run run.go -- file1.go file2.go ...
+ ../bin/go test internal/testdir -run='Test/(file1.go|file2.go|...)'
Standard library tests should be written as regular Go tests in the appropriate package.
[...] I've done some basic timing, and by using the aforementioned subtest arrangement with It's likely important to keep -shard and -shards flags operational for purposes of sharded test execution, but that turns up to be trivial. There are more flags in run.go, and I plan to keep most of them as they are. A few will go away because they're obsolete (e.g., -n is obsolete given go test's own parallelism controls; -showSkips will likely get replaced by t.Skip, etc.). I haven't yet decided how I'll deal with misc/cgo/stdio and misc/cgo/life, but I'm aiming to just simplify them. Given that GOROOT/test/run.go is fairly large (2139 lines), I'm looking to do this in a way that makes it easier to review and be confident we're not dropping some tests on the floor. At least one of the CLs will be large to do migration atomically, but fortunately I should be able to make the diff between GOROOT/test/run.go and GOROOT/src/internal/testdir/main_test.go quite small and readable in it. The rest can be split off into smaller preparatory and clean up changes. |
Change https://go.dev/cl/463276 mentions this issue: |
A few more things for me not to forget to update:
|
Change https://go.dev/cl/466155 mentions this issue: |
Change https://go.dev/cl/465755 mentions this issue: |
The misc/cgo/life and misc/cgo/stdio tests started out as fairly simple test cases when they were added, but the machinery to execute them has grown in complexity over the years. They currently reuse the test/run.go runner and its "run" action without needing much of the additional flexibility that said runner implements. Given that runner isn't well documented, it makes it harder to see that ultimately these tests just do 'go run' on a few test programs and check that the output matches a golden file. Maybe these test cases should move out of misc to be near similar tests, or the machinery to execute them can made available in a package that is easier and safer to reuse. I'd rather not block the refactor of the test directory runner on that, so for now rewrite these to be self-contained. Also delete misc/cgo/stdio/testdata/run.out which has no effect on the test. It was seemingly accidentally kept behind during the refactor in CL 6220049. For #56844. Change-Id: I5e2f542824925092cdddb03b44b6295a4136ccb4 Reviewed-on: https://go-review.googlesource.com/c/go/+/465755 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Austin Clements <austin@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Now that the bare minimum change to make the run.go test runner into a normal go test is done, there remain many opportunities to simplify, modernize and generally clean up the test code. Of all the opportunities available, this change tries to fit somewhere between doing "not enough" and "way too much". This ends up including: • replace verbose flag with testing.Verbose() • replace custom temporary directory creation, removal, -keep flag with testing.T.TempDir • replace custom code to find the go command with testenv.GoToolPath • replace many instances of "t.err = err; return" with "return err", or with t.Fatal when it's clearly a test infrastructure error • replace reliance on changing working directory to GOROOT/test to computing and using absolute paths • replace uses of log.Fatal with t.Fatal • replace uses of deprecated ioutil package with their replacements • add some missing error checks, use more idiomatic identifier names For #56844. Change-Id: I5b301bb83a8e5b64cf211d7f2f4b14d38d48fea0 Reviewed-on: https://go-review.googlesource.com/c/go/+/466155 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Change https://go.dev/cl/471895 mentions this issue: |
The top-level test suite in $GOROOT/test is implemented as a normal go test in the new internal/testenv package as of CL 463276. Update the contribution guide accordingly. Updates golang/go#56844. Change-Id: I73bfa8e4fc7c35f63efdde42ddf3552b5a518136 Reviewed-on: https://go-review.googlesource.com/c/website/+/471895 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Change https://go.dev/cl/493876 mentions this issue: |
Change https://go.dev/cl/493915 mentions this issue: |
Change https://go.dev/cl/494656 mentions this issue: |
It's changed slightly to be inside 'cmd'. For golang/go#56844. For golang/go#60059. Change-Id: I244f0ae627978a7b59d6a56d20aebc3ff81b3179 Reviewed-on: https://go-review.googlesource.com/c/website/+/493915 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
The effect and motivation is for the test to be selected when doing 'go test cmd' and not when doing 'go test std' since it's primarily about testing the Go compiler and linker. Other than that, it's run by all.bash and 'go test std cmd' as before. For #56844. Fixes #60059. Change-Id: I2d499af013f9d9b8761fdf4573f8d27d80c1fccf Reviewed-on: https://go-review.googlesource.com/c/go/+/493876 Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
It was my oversight in CL 463276 to skip registerStdTestSpecially packages in the race bench test registration loop. Package testdir has no benchmarks and doesn't need to be skipped. (And if it had benchmarks, it's very unlikely they'd need any special handling.) By now there are more cmd/cgo/internal/... packages that are registered specially, and there isn't a need for their few benchmarks not to be used for the purpose of race bench tests. If the 3 benchmarks in cmd/cgo/internal/test were to require something special, then we can add it to a new registerRaceBenchTestSpecially map with a comment, and do register them specially in registerTests instead of forgetting to. This restores the automatic 'go_test_bench:cmd/cgo/internal/test' registration and reduces prevalence of registerStdTestSpecially a bit. For #37486. For #56844. Change-Id: I1791fe5bf94cb4b4e0859c5fff4e7a3d5a23723e Reviewed-on: https://go-review.googlesource.com/c/go/+/494656 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
Change https://go.dev/cl/498271 mentions this issue: |
The go command already places $GOROOT/bin at the beginning of $PATH in the test's environment as of Go 1.19¹, so there's no need for the test to do it anymore. Start enjoying yet another benefit of using 'go test'. ¹ See go.dev/issue/57050. For #56844. Change-Id: If7732cd8b8979eabf185485d3c73858a4e546d69 Reviewed-on: https://go-review.googlesource.com/c/go/+/498271 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This is a tracking issue for adding JSON output support to the test/run.go program, which is invoked by cmd/dist to run tests in the GOROOT/test directory. This is a subset of #37486, broken out into a smaller tracking issue.
This can ideally be implemented by refactoring this program into a normal Go test that can be invoked with
go test
(which will then automatically have support JSON output via go test's-json
flag), or possibly adding a lightweight Go test on top of the existing test/run.go program. It is in principle also possible to add JSON output support to test/run.go directly, without making it a normal Go test. These are implementation details, need to investigate what approach works out better.CC @aclements, @golang/release.
The text was updated successfully, but these errors were encountered: