Skip to content
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

cmd: relocate script test framework from cmd/go to cmd/internal #68606

Closed
thanm opened this issue Jul 26, 2024 · 13 comments
Closed

cmd: relocate script test framework from cmd/go to cmd/internal #68606

thanm opened this issue Jul 26, 2024 · 13 comments
Assignees
Labels
Friction Nuisances that make good candidates for our "friction" fix-it weeks NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@thanm
Copy link
Contributor

thanm commented Jul 26, 2024

The Go command has a very nice "script" testing framework that makes it easy to write regression tests that involve smallish multifile test cases and sequences of "go" command invocations. Other tools (compiler, linker, etc) would benefit from a similar facility. The convention for the compiler has been to add new test cases in $GOROOT/test, which then run by the harness in cmd/internal/testdir, howewer the harness code there has a lot of peculiarities: except for the simplest cases (e.g. compiler crash when run on a single file) it is difficult for test writers to pick out the correct flavor of test (rundir, runindir, compiledir, etc) to get the behavior they want.

To make it easier and simpler to code up more complicated test cases, I propose to relocate the cmd/go script test framework from cmd/go to cmd/internal, then make it available in some form for testing our various tools (compile, link, nm, etc). This is a tracking issue to record the progress on this effort.

@thanm thanm added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Friction Nuisances that make good candidates for our "friction" fix-it weeks labels Jul 26, 2024
@thanm thanm added this to the Backlog milestone Jul 26, 2024
@thanm thanm self-assigned this Jul 26, 2024
@gabyhelp
Copy link

@cuonglm
Copy link
Member

cuonglm commented Jul 26, 2024

When seeing "script", I thought it's the go test -run=TestScript, which involves writing test case using https://pkg.go.dev/golang.org/x/[email protected]/txtar

Either way, it would be a great improvement.

@thanm
Copy link
Contributor Author

thanm commented Jul 26, 2024

When seeing "script", I thought it's the go test -run=TestScript, which involves writing test case using https://pkg.go.dev/golang.org/x/[email protected]/txtar

Yes, the intent is to support txtar-style tests, such as this one in cmd/go:

https://go.googlesource.com/go/+/b788e91badd523e5bb0fc8d50cd76b8ae04ffb20/src/cmd/go/testdata/script/link_external_undef.txt

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601357 mentions this issue: cmd: extract out "known" os/arch tables into separate package

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601358 mentions this issue: cmd: relocate cmd/go/internal/script to cmd/internal/script

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601356 mentions this issue: cmd: relocate cmd/go/internal/robustio to cmd/internal/robustio

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601359 mentions this issue: cmd/internal/script/scriptest: add new apis for tool test use

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601361 mentions this issue: cmd/compile: add script testing facility for compiler use

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601355 mentions this issue: cmd: relocate cmd/go/internal/par to cmd/internal/par

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601360 mentions this issue: cmd/link: add script testing facility for linker use

gopherbot pushed a commit that referenced this issue Jul 29, 2024
Relocate cmd/go's internal/par package up a level into
cmd/internal/par, so that it can be used by other cmd/internal
packages. No change in functionality. This change is intended to be in
support of making the cmd/go script test framework available to other
commands in addition to just the Go command.

Updates #68606.

Change-Id: I920a5d5c9b362584fabdbb2305414325b42856a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/601355
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 29, 2024
Relocate cmd/go's internal/robustio package up a level into
cmd/internal/robustio, so that it can be used by other cmd/internal
packages. No change in functionality. This change is intended to be in
support of making the cmd/go script test framework available to other
commands in addition to just the Go command.

Updates #68606.

Change-Id: Ic8421ef59d9b7d79a50c3679d180cfa2546c4cd3
Reviewed-on: https://go-review.googlesource.com/c/go/+/601356
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 29, 2024
Common up the the "known OS/Arch" tables from { cmd/go/internal/imports,
cmd/go/internal/modindex, go/build } and relocate them to a new
package, internal/syslist. No change in functionality.

Updates #68606.

Change-Id: I6414a05c96b8fddbdbd9678d322cb49d9b1b0af3
Reviewed-on: https://go-review.googlesource.com/c/go/+/601357
Reviewed-by: Ian Lance Taylor <[email protected]>
Reviewed-by: Michael Matloob <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 29, 2024
Relocate cmd/go's internal/script package up a level into
cmd/internal/script, so as to enable the use of script tests in
other cmd packages.  No change in functionality.

Updates #68606.

Change-Id: I3974b0bf59c76e0f459184c9f3090d6077dd5d91
Reviewed-on: https://go-review.googlesource.com/c/go/+/601358
Reviewed-by: Michael Matloob <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 29, 2024
Add top level apis to provide a general-purpose "script test" runner
for clients within cmd, e.g. tools such as compile, link, nm, and so
on. This patch doesn't add any uses of the new apis, this will
happen in follow-on CLs.

Updates #68606.

Change-Id: Ib7200a75d4dc7dc50897628f1a6269937be15a76
Reviewed-on: https://go-review.googlesource.com/c/go/+/601359
Reviewed-by: David Chase <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 29, 2024
Add support for running script tests as part of the linker's suite of
tests, hooking in the script test engine packages recently moved from
cmd/go to cmd/internal. Linker script tests will use the test binary
itself as the linker for Go builds, and can also run the C compiler if
needed. New script test cases (*.txt files) should be added to the
directory cmd/link/testdata/script.

For demo purposes, this patch also adds a new "randlayout_option.txt"
script test that replicates the existing linker's TestRandLayout
testpoint in script form.

Updates #68606.

Change-Id: Icf26bf657850e39548d6ea819f2542fc68a3899b
Reviewed-on: https://go-review.googlesource.com/c/go/+/601360
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: David Chase <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 29, 2024
Add support for running script tests as part of the compiler's suite
of tests, hooking in the script test engine packages recently moved
from cmd/go to cmd/internal. These script tests will use the test
binary itself as the compile tool for Go builds, and can also run the
C compiler if needed. New script test cases (*.txt files) should be
added to the directory cmd/compile/testdata/script.

Updates #68606.

Change-Id: I9b056a07024b0a72320a89ad734e4b4a51f1c10c
Reviewed-on: https://go-review.googlesource.com/c/go/+/601361
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: David Chase <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601715 mentions this issue: cmd/internal/script: new hook for adding in toolchain script conditions

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/601756 mentions this issue: cmd: add README generation for compiler + linker script tests

gopherbot pushed a commit that referenced this issue Jul 31, 2024
Introduce a new function AddToolChainScriptConditions that augments a
default "script.Cond" set with a collection of useful conditions,
including godebug/goexperiment, cgo, race support, buildmode, asan,
msan, and so on. Having these conditions available makes it easier to
write script tests that deal with specific build-flavor corner cases.
The functions backing the new conditions are helper functions migrated
over from the Go command's script test setup.

Updates #68606.

Change-Id: I14def1115b54dc47529c983abcd2c5ea9326b9de
Reviewed-on: https://go-review.googlesource.com/c/go/+/601715
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
gopherbot pushed a commit that referenced this issue Jul 31, 2024
Add in automatic README generation and README consistency checking for
the cmd/compile and cmd/link script tests. This code is adapted from
the similar facility in cmd/go (e.g. scriptreadme_test.go); the README
helps folks writing new tests understand the mechanics.

Updates #68606.

Change-Id: I8ff7ff8e814abd4385bd670440511b2c60a4cef6
Reviewed-on: https://go-review.googlesource.com/c/go/+/601756
Reviewed-by: Cherry Mui <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
@thanm
Copy link
Contributor Author

thanm commented Jul 31, 2024

Closing out this issue, the new framework is running + functional. Happy script test writing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Friction Nuisances that make good candidates for our "friction" fix-it weeks NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

4 participants