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/go: extract TestScript functionality to internal/script #29288

Closed
minux opened this issue Dec 15, 2018 · 6 comments
Closed

cmd/go: extract TestScript functionality to internal/script #29288

minux opened this issue Dec 15, 2018 · 6 comments

Comments

@minux
Copy link
Member

minux commented Dec 15, 2018

While writing a test for #29253, it is apparent that using the existing cmd/go script test framework makes the test writing easy and straightforward. However, I don't like the fact that a test for cmd/link has to be placed in cmd/go/testdata/script.

I think the underlying concept of the script is very useful and enables us to write very simple single file test cases for even the most complicated scenarios.

I'd like to suggest that we move its functionality to internal/script (and txtar) and also make it client extendable so that it's possible for all cmd/* packages to use it (perhaps we can even unify the $GOROOT/test/run.go with it?)

Also, I'd like to make it possible to run single text archive go test cases with something like:

   go test internal/script bug.txt

Perhaps we could even make a go report-bug command to automate the packaging of such test cases? (Then we don't need to create a repo just to show a Go bug, and I think a lot of other products support a way to bundle a test case into a single file, the text archive is quite useful in this context.)

Thoughts?

@minux minux added the Proposal label Dec 15, 2018
@minux minux added this to the Proposal milestone Dec 15, 2018
@bcmills
Copy link
Contributor

bcmills commented Dec 17, 2018

CC @rsc @rogpeppe @myitcv

@rogpeppe
Copy link
Contributor

rogpeppe commented Dec 17, 2018

FWIW I have extracted much of the script_test.go functionality into this package. Feel free to bring some or all of it back within the Go repository. It's missing some of the pieces that I considered were go-command-specific (particularly the bits that were about compiling Go programs, which added a reasonable amount of complexity). It should be extensible enough to add that functionality back in though.

@rsc
Copy link
Contributor

rsc commented Dec 19, 2018

This seems OK to try in Go 1.13 provided it stays as internal/script and we don't just grow an enormous number of "commands" in the scripting language. I don't want to commit to an API for external use. I'm also worried about, for example, the "go" command in the cmd/go tests. It doesn't make sense in a general internal/script test. What commands move? What commands stay? It's unclear to me how well this will generalize. But feel free to make a concrete proposal.

@rogpeppe
Copy link
Contributor

FWIW, that's the reason I removed the "go" command from my factored out version and made the set of commands extensible. I tried to keep the set of commands limited to those that were generally applicable.

@andybons
Copy link
Member

Per @golang/proposal-review, accepted for 1.13.

@andybons andybons changed the title proposal: extract cmd/go TestScript functionality to internal/script? cmd/go: extract TestScript functionality to internal/script? Mar 27, 2019
@andybons andybons changed the title cmd/go: extract TestScript functionality to internal/script? cmd/go: extract TestScript functionality to internal/script Mar 27, 2019
@jayconrod jayconrod modified the milestones: Proposal, Backlog Aug 23, 2021
@bcmills
Copy link
Contributor

bcmills commented Nov 28, 2023

This is essentially done — it was extracted to cmd/go/internal/script, but could easily be moved up to cmd/internal/script or internal/script with only trivial changes, if someone wants to use it elsewhere in the main repo.

The go test simplification has not been implemented yet; instead one runs something like go test cmd/go -run=TestScript/bug.txt, which doesn't seem terrible (and is easy enough to wrap with a shell script).

@bcmills bcmills closed this as completed Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants