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: in tests, populate go.sum files and reduce usage of -mod=mod #41302

Open
jayconrod opened this issue Sep 9, 2020 · 4 comments
Open
Labels
NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@jayconrod
Copy link
Contributor

This issue acts as a TODO for a number of comments raised in review of CL 251881, which enables -mod=readonly by default for #40278. Two broad issues should be fixed in the cmd/go integration tests.

First, -mod=mod is used in a lot of places with go list or go build. We should make the tests follow more idiomatic usage. If something is missing from go.mod or go.sum, we should run go get -d, go mod tidy, or go mod download first. The following tests need changes. There are probably more.

  • mod_doc
  • mod_download.
  • mod_invalid_version
  • mod_list
  • mod_load_badzip
  • mod_replace
  • mod_replace_gopkgin
  • mod_require_exclude
  • mod_sumdb_golang

Second, many tests fail without -mod=mod because the test archive doesn't include a go.sum file. I'd rather not include literal go.sum files in tests, since they'll make tests more difficult to write and act as change detectors. Instead, we should have a command or sequence of commands run at the beginning of a test that fills in missing sums without modifying go.mod. Something like:

cp go.mod go.mod.orig
go get -d ./...
cmp go.mod go.mod.orig

If this turns out to be too repetitive, we may want to add a script_test.go command to shorten it.

The following tests need changes. Again, there are probably more.

  • mod_list_dir
  • mod_list_replace_dir
  • mod_list_upgrade
  • mod_load_badmod
  • mod_modinfo
@jayconrod jayconrod added Testing An issue that has been verified to require only test changes, not just a test failure. NeedsFix The path to resolution is known, but the work has not been done. labels Sep 9, 2020
@jayconrod jayconrod added this to the Go1.16 milestone Sep 9, 2020
@jayconrod jayconrod self-assigned this Sep 9, 2020
@jayconrod
Copy link
Contributor Author

Also, mod_missingpkg_prerelease. go get -d should report errors on transitively imported packages.

@jayconrod jayconrod modified the milestones: Go1.16, Go1.17 Jan 6, 2021
@gopherbot
Copy link

Change https://golang.org/cl/311189 mentions this issue: cmd/go: in tests, reduce usage of -mod=mod and populate go.sum files

@jayconrod jayconrod modified the milestones: Go1.17, Backlog May 17, 2021
@gopherbot
Copy link

Change https://golang.org/cl/336150 mentions this issue: [dev.cmdgo] cmd/go: add -testsum flag to update go.sum in script tests

gopherbot pushed a commit that referenced this issue Jul 27, 2021
-testsum may be set to "tidy", "listm", or "listall". When set,
TestScript runs 'go mod tidy', 'go list -m -mod=mod all', or
'go list -mod=mod all' at the beginning of each test that has a go.mod
file in its root directory. If the test passes and go.mod or go.sum
was updated, TestScript will rewrite the test file with the initial
content of go.mod and go.sum (after the above command).

This is useful for writing tests that need a working go.sum and for
fixing tests that rely on -mod=mod.

For #41302

Change-Id: I63a5667621a5082ccedfc1bff33c3969c29e8b3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/336150
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
@gopherbot
Copy link

Change https://golang.org/cl/341932 mentions this issue: cmd/go: add -testsum flag to update go.sum in script tests

gopherbot pushed a commit that referenced this issue Aug 13, 2021
-testsum may be set to "tidy", "listm", or "listall". When set,
TestScript runs 'go mod tidy', 'go list -m -mod=mod all', or
'go list -mod=mod all' at the beginning of each test that has a go.mod
file in its root directory. If the test passes and go.mod or go.sum
was updated, TestScript will rewrite the test file with the initial
content of go.mod and go.sum (after the above command).

This is useful for writing tests that need a working go.sum and for
fixing tests that rely on -mod=mod.

For #41302

Change-Id: I63a5667621a5082ccedfc1bff33c3969c29e8b3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/336150
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-on: https://go-review.googlesource.com/c/go/+/341932
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@jayconrod jayconrod removed their assignment Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

2 participants