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.

Comment From: gabyhelp

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Comment From: cuonglm

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/tools@v0.23.0/txtar

Either way, it would be a great improvement.

Comment From: thanm

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/tools@v0.23.0/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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: gopherbot

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

Comment From: thanm

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