]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add compatibility tests for go mod tidy -diff
authorSam Thanawalla <samthanawalla@google.com>
Thu, 23 May 2024 20:57:32 +0000 (20:57 +0000)
committerSam Thanawalla <samthanawalla@google.com>
Thu, 30 May 2024 14:56:56 +0000 (14:56 +0000)
For #27005
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Change-Id: I90ab8c21222ac2189abb40e8c8e7549e2d940dd2
Reviewed-on: https://go-review.googlesource.com/c/go/+/587941
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
13 files changed:
src/cmd/go/alldocs.go
src/cmd/go/internal/modcmd/tidy.go
src/cmd/go/internal/modfetch/fetch.go
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/mod_tidy_compat.txt
src/cmd/go/testdata/script/mod_tidy_compat_added.txt
src/cmd/go/testdata/script/mod_tidy_compat_ambiguous.txt
src/cmd/go/testdata/script/mod_tidy_compat_deleted.txt
src/cmd/go/testdata/script/mod_tidy_compat_implicit.txt
src/cmd/go/testdata/script/mod_tidy_compat_incompatible.txt
src/cmd/go/testdata/script/mod_tidy_compat_irrelevant.txt
src/cmd/go/testdata/script/mod_tidy_diff.txt
src/cmd/go/testdata/script/mod_tidy_diff_compat.txt [deleted file]

index 3804d331cbe031bd76bf7748fb54fb39ff0550a2..ad8e17e3585130404d1e1b8c65148cbb1f0dee5d 100644 (file)
 // The -e flag causes tidy to attempt to proceed despite errors
 // encountered while loading packages.
 //
-// The -diff flag causes tidy not to modify the files but instead print the
-// necessary changes as a unified diff. It exits with a non-zero code
-// if updates are needed.
+// The -diff flag causes tidy not to modify go.mod or go.sum but
+// instead print the necessary changes as a unified diff. It exits
+// with a non-zero code if the diff is not empty.
 //
 // The -go flag causes tidy to update the 'go' directive in the go.mod
 // file to the given version, which may change which module dependencies
index 50992c9bfd8eade387835ecc21d25dc91a02a1f3..2efa33a7c343dddabd8e694cd5ce932e2f056ab4 100644 (file)
@@ -35,9 +35,9 @@ to standard error.
 The -e flag causes tidy to attempt to proceed despite errors
 encountered while loading packages.
 
-The -diff flag causes tidy not to modify the files but instead print the
-necessary changes as a unified diff. It exits with a non-zero code
-if updates are needed.
+The -diff flag causes tidy not to modify go.mod or go.sum but
+instead print the necessary changes as a unified diff. It exits
+with a non-zero code if the diff is not empty.
 
 The -go flag causes tidy to update the 'go' directive in the go.mod
 file to the given version, which may change which module dependencies
index 455deded54f3ec7c3cb84fcc9fe086f7f99ff8a5..ad4eb8ecd25b483a79264624fa58a5471c14cd61 100644 (file)
@@ -898,7 +898,7 @@ func TidyGoSum(keep map[module.Version]bool) (before, after []byte) {
        return before, after
 }
 
-// tidyGoSum will return a tidy version of the go.sum file.
+// tidyGoSum returns a tidy version of the go.sum file.
 // The goSum lock must be held.
 func tidyGoSum(data []byte, keep map[module.Version]bool) []byte {
        if !goSum.overwrite {
index bb232eb04b1af36f2ee2da4deb9e6e68620723f2..5b0ecee09a99f20096860cf9cd94309b394a2d4a 100644 (file)
@@ -155,9 +155,9 @@ type PackageOpts struct {
        // packages.
        Tidy bool
 
-       // TidyDiff, if true, analyzes the necessary changes to go.mod and go.sum
-       // to make them tidy. It does not modify these files, but exits with
-       // a non-zero code if updates are needed.
+       // TidyDiff, if true, causes tidy not to modify go.mod or go.sum but
+       // instead print the necessary changes as a unified diff. It exits
+       // with a non-zero code if the diff is not empty.
        TidyDiff bool
 
        // TidyCompatibleVersion is the oldest Go version that must be able to
@@ -445,7 +445,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
                        if err != nil {
                                base.Fatal(err)
                        }
-                       goModDiff := diff.Diff("current go.mod", currentGoMod, "tidy go.mod", updatedGoMod)
+                       goModDiff := diff.Diff("current/go.mod", currentGoMod, "tidy/go.mod", updatedGoMod)
 
                        modfetch.TrimGoSum(keep)
                        // Dropping compatibility for 1.16 may result in a strictly smaller go.sum.
@@ -454,7 +454,7 @@ func LoadPackages(ctx context.Context, opts PackageOpts, patterns ...string) (ma
                                keep = keepSums(ctx, loaded, requirements, addBuildListZipSums)
                        }
                        currentGoSum, tidyGoSum := modfetch.TidyGoSum(keep)
-                       goSumDiff := diff.Diff("current go.sum", currentGoSum, "tidy go.sum", tidyGoSum)
+                       goSumDiff := diff.Diff("current/go.sum", currentGoSum, "tidy/go.sum", tidyGoSum)
 
                        if len(goModDiff) > 0 {
                                fmt.Println(string(goModDiff))
index 724c83e14eeb582e6b3a84a27ba719dcd180d30b..0a9d2ff8436b7cb8d2cb0350257870245d2bddb8 100644 (file)
@@ -30,6 +30,17 @@ cp go.mod go.mod.orig
 go mod tidy
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -diff
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go list -m all
 cmp stdout m_all.txt
 
@@ -45,6 +56,17 @@ cp go.mod.orig go.mod
 go mod tidy -compat=1.17
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -compat=1.17 -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -compat=1.17 -diff
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go list -m all
 cmp stdout m_all.txt
 
index b3f75adfe9a839b990db9da21fe42fbbcd90c825..0831d0f0854326b63b40d8f0288d7008a9f03b5c 100644 (file)
@@ -21,6 +21,12 @@ stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/a
 
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! exists go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added$'
 
 # When we run 'go mod tidy -e', we should proceed past the first error and follow
 # it with a second error describing the version discrepancy.
@@ -37,6 +43,20 @@ stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/a
 
 cmp go.mod go.mod.tidy
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod go.mod.tidyResult
+[exec:patch] ! exists go.sum
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -e -diff
+[exec:patch] stdout 'diff current/go.mod tidy/go.mod'
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/added: module example\.net/added@latest found \(v0\.3\.0, replaced by \./a1\), but does not contain package example\.net/added\ngo: example\.net/added failed to load from any module,\n\tbut go 1\.16 would load it from example\.net/added@v0\.2\.0$'
+[exec:patch] ! stderr '\n\tgo mod tidy'
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -e -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] ! exists go.sum
 
 -- go.mod --
 module example.com/m
index 5316220f62e13970049766d04e193137e973ec39..28d9c1f2f65b8e861749053af5c9a3aa0f106e7b 100644 (file)
@@ -27,6 +27,14 @@ stderr '\n\nTo proceed despite packages unresolved in go 1\.16:\n\tgo mod tidy -
 
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! exists go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/indirect imports\n\texample\.net/ambiguous/nested/pkg loaded from example\.net/ambiguous/nested@v0\.1\.0,\n\tbut go 1.16 would fail to locate it:\n\tambiguous import: found package example\.net/ambiguous/nested/pkg in multiple modules:\n\texample\.net/ambiguous v0.1.0 \(.*\)\n\texample\.net/ambiguous/nested v0.1.0 \(.*\)\n\n'
+[exec:patch] stderr '\n\nTo proceed despite packages unresolved in go 1\.16:\n\tgo mod tidy -e\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
+
 
 # If we run 'go mod tidy -e', we should still save enough checksums to run
 # 'go list -m all' reproducibly with go 1.16, even though we can't list
@@ -36,6 +44,19 @@ go mod tidy -e
 ! stderr '\n\tgo mod tidy'
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -e -diff
+[exec:patch] ! stderr '\n\tgo mod tidy'
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -e -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go list -m all
 cmp stdout all-m.txt
 
@@ -60,6 +81,19 @@ go mod tidy -compat=1.17
 go list -m all
 cmp stdout all-m.txt
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -compat=1.17 -diff
+[exec:patch] ! stderr .
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -compat=1.17 -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go mod edit -go=1.16
 ! go list -m all
 stderr '^go: example\.net/indirect@v0\.1\.0 requires\n\texample\.net/ambiguous@v0\.1\.0: missing go\.sum entry for go\.mod file; to add it:\n\tgo mod download example\.net/ambiguous\n'
index b148fc1c01b4d37b9ec5642718f3fa35c153ddad..28342ec269ec21248ed5bc8b2c7cfea2ec7e788e 100644 (file)
@@ -21,12 +21,30 @@ stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\
 
 stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! exists go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted loaded from example\.net/deleted@v0\.1\.0,\n\tbut go 1\.16 would fail to locate it in example\.net/deleted@v0\.2\.0\n\n'
+[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1.16, leaving some packages unresolved:\n\tgo mod tidy -e -go=1\.16 && go mod tidy -e -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1\.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
 
 # The suggested 'go mod tidy -e' command should proceed anyway.
 
 go mod tidy -e
 cmp go.mod go.mod.tidy
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod go.mod.tidyResult
+[exec:patch] ! exists go.sum
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -e -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -e -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] ! exists go.sum
 
 # In 'go 1.16' mode we should error out in the way we claimed.
 
@@ -39,9 +57,16 @@ go mod edit -go=1.16
 ! go list -deps -f $MODFMT example.com/m
 stderr '^go: updates to go\.mod needed; to update it:\n\tgo mod tidy$'
 
+[exec:patch] cp go.mod go.mod.orig
 ! go mod tidy
 stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$'
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! exists go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/deleted: module example\.net/deleted@latest found \(v0\.2\.0, replaced by \./d2\), but does not contain package example\.net/deleted$'
 
 -- go.mod --
 module example.com/m
index 26e4749203a7d2f8bf4d33dc9ecc3196cd63145b..c98e343d6e57c8d94e6b0294fdc71efb528b79fa 100644 (file)
@@ -37,6 +37,14 @@ stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=
 
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! exists go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/lazy tested by\n\texample\.net/lazy.test imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n'
+[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
+
 # The suggested '-compat' flag to ignore differences should silence the error
 # and leave go.mod unchanged, resulting in checksum errors when Go 1.16 tries
 # to load a module pruned out by Go 1.17.
@@ -45,6 +53,18 @@ go mod tidy -compat=1.17
 ! stderr .
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -compat=1.17 -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -compat=1.17 -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go list -deps -test -f $MODFMT ./...
 stdout '^example.net/lazy v0.1.0$'
 
index 9e2a9ee29e18343754b6e3be2aae55fc2e4d58ec..15d50317e84f541071bce40a8de442d7bdac51e1 100644 (file)
@@ -37,6 +37,13 @@ stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=
 
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! exists go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] stderr '^go: example\.com/m imports\n\texample\.net/lazy imports\n\texample\.com/retract/incompatible loaded from example\.com/retract/incompatible@v1\.0\.0,\n\tbut go 1\.16 would select v2\.0\.0\+incompatible\n\n'
+[exec:patch] stderr '\n\nTo upgrade to the versions selected by go 1\.16:\n\tgo mod tidy -go=1\.16 && go mod tidy -go=1\.17\nIf reproducibility with go 1\.16 is not needed:\n\tgo mod tidy -compat=1.17\nFor other options, see:\n\thttps://golang\.org/doc/modules/pruning\n'
 
 # The suggested '-compat' flag to ignore differences should silence the error
 # and leave go.mod unchanged, resulting in checksum errors when Go 1.16 tries
@@ -46,6 +53,18 @@ go mod tidy -compat=1.17
 ! stderr .
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -compat=1.17 -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -compat=1.17 -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go mod edit -go=1.16
 ! go list -f $MODFMT -deps ./...
 stderr -count=1 '^go: example\.net/lazy@v0\.1\.0 requires\n\texample\.net/requireincompatible@v0\.1\.0 requires\n\texample\.com/retract/incompatible@v2\.0\.0\+incompatible: missing go.sum entry for go.mod file; to add it:\n\tgo mod download example.com/retract/incompatible$'
index e4eaea0dd6242abc14aca4dd51d3c669f8eeebcd..75c16d19184264cc1112205e231cc20988f65a04 100644 (file)
@@ -27,6 +27,18 @@ cp go.mod go.mod.orig
 go mod tidy
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] mv go.mod go.mod.tidyResult
+[exec:patch] mv go.sum go.sum.tidyResult
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] ! go mod tidy -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
 go list -deps -test -f $MODFMT all
 cp stdout out-117.txt
 
@@ -42,6 +54,12 @@ cp go.mod.orig go.mod
 go mod tidy -compat=1.17
 cmp go.mod go.mod.orig
 
+# Make sure that -diff behaves the same as tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] rm go.sum
+[exec:patch] go mod tidy -compat=1.17 -diff
+[exec:patch] ! stdout .
+
 go list -deps -test -f $MODFMT all
 cmp stdout out-117.txt
 
index 336dcb41f4eaf704eb653555189e7e543129b68f..23138b70321c515ab48acbec16d4b4e9007c035c 100644 (file)
@@ -7,8 +7,8 @@
 ! go mod tidy -diff
 ! exists go.mod
 ! exists go.sum
-! stdout 'diff current go.mod tidy go.mod'
-! stdout 'diff current go.sum tidy go.sum'
+! stdout 'diff current/go.mod tidy/go.mod'
+! stdout 'diff current/go.sum tidy/go.sum'
 stderr 'go.mod file not found'
 
 # Missing go.mod and existing go.sum should fail and not display diff.
@@ -17,8 +17,8 @@ cp go.sum.orig go.sum
 exists go.sum
 ! go mod tidy -diff
 ! exists go.mod
-! stdout 'diff current go.mod tidy go.mod'
-! stdout 'diff current go.sum tidy go.sum'
+! stdout 'diff current/go.mod tidy/go.mod'
+! stdout 'diff current/go.sum tidy/go.sum'
 stderr 'go.mod file not found'
 
 # Existing go.mod and missing go.sum should display diff.
@@ -29,46 +29,59 @@ exists go.mod
 ! exists go.sum
 ! go mod tidy -diff
 ! exists go.sum
-! stdout 'diff current go.mod tidy go.mod'
-stdout 'diff current go.sum tidy go.sum'
+! stdout 'diff current/go.mod tidy/go.mod'
+stdout 'diff current/go.sum tidy/go.sum'
 
 # Everything is tidy, should return zero exit code.
 go mod tidy
 go mod tidy -diff
-! stdout 'diff current go.mod tidy go.mod'
-! stdout 'diff current go.sum tidy go.sum'
+! stdout 'diff current/go.mod tidy/go.mod'
+! stdout 'diff current/go.sum tidy/go.sum'
 
 # go.mod requires updates, should return non-zero exit code.
 cp go.mod.orig go.mod
 ! go mod tidy -diff
+stdout 'diff current/go.mod tidy/go.mod'
+! stdout 'diff current/go.sum tidy/go.sum'
 cmp go.mod.orig go.mod
-stdout 'diff current go.mod tidy go.mod'
-! stdout 'diff current go.sum tidy go.sum'
 
 # go.sum requires updates, should return non-zero exit code.
 go mod tidy
 cp go.sum.orig go.sum
 ! go mod tidy -diff
+! stdout 'diff current/go.mod tidy/go.mod'
+stdout 'diff current/go.sum tidy/go.sum'
 cmp go.sum.orig go.sum
-! stdout 'diff current go.mod tidy go.mod'
-stdout 'diff current go.sum tidy go.sum'
 
 # go.mod and go.sum require updates, should return non-zero exit code.
 cp go.mod.orig go.mod
 cp go.sum.orig go.sum
 ! go mod tidy -diff
-stdout '^\+\s*require rsc.io/quote v1.5.2'
-stdout '^\+\s*golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect'
-stdout '^\+\s*rsc.io/sampler v1.3.0 // indirect'
-stdout '^\+\s*rsc.io/testonly v1.0.0 // indirect'
-stdout '.*\+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c h1:pvCbr/wm8HzDD3fVywevekufpn6tCGPY3spdHeZJEsw='
-stdout '.*\+golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW\+pc6Ldnwhi/IjpwHt7yyuwOQ='
-! stdout '^\+rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0='
-stdout '^\+rsc.io/sampler v1.3.0 h1:HLGR/BgEtI3r0uymSP/nl2uPLsUnNJX8toRyhfpBTII='
-stdout '^\+rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA='
+stdout 'diff current/go.mod tidy/go.mod'
+stdout 'diff current/go.sum tidy/go.sum'
 cmp go.mod.orig go.mod
 cmp go.sum.orig go.sum
 
+# Save the result from running tidy.
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] cp go.sum.orig go.sum
+[exec:patch] go mod tidy
+[exec:patch] cp go.mod go.mod.tidyResult
+[exec:patch] cp go.sum go.sum.tidyResult
+
+# Compare output of -diff to running tidy.
+# Apply the patch from -diff
+[exec:patch] cp go.mod.orig go.mod
+[exec:patch] cp go.sum.orig go.sum
+[exec:patch] ! go mod tidy -diff
+[exec:patch] cp stdout diff.patch
+[exec:patch] exec patch -p1 -i diff.patch
+[exec:patch] go mod tidy -diff
+[exec:patch] ! stdout .
+[exec:patch] cmp go.mod go.mod.tidyResult
+[exec:patch] cmp go.sum go.sum.tidyResult
+
+
 -- main.go --
 package main
 
diff --git a/src/cmd/go/testdata/script/mod_tidy_diff_compat.txt b/src/cmd/go/testdata/script/mod_tidy_diff_compat.txt
deleted file mode 100644 (file)
index abba139..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-# https://golang.org/issue/27005 and https://golang.org/issue/46141:
-# This test covers the interaction between -diff and -compat.
-# This test is based on mod_tidy_compat.txt
-# The tidy go.mod produced to be diffed with the current go.mod with -compat
-# should by default preserve enough checksums for the module to be used by Go 1.16.
-#
-# We don't have a copy of Go 1.16 handy, but we can simulate it by editing the
-# 'go' version in the go.mod file to 1.16, without actually updating the
-# requirements to match.
-
-[short] skip
-
-env MODFMT='{{with .Module}}{{.Path}} {{.Version}}{{end}}'
-
-
-# This module has the same module dependency graph in Go 1.16 as in Go 1.17,
-# but in 1.16 requires (checksums for) additional (irrelevant) go.mod files.
-#
-# The module graph under both versions looks like:
-#
-# m ---- example.com/version v1.1.0
-# |
-# + ---- example.net/lazy v0.1.0 ---- example.com/version v1.0.1
-#
-# Go 1.17 avoids loading the go.mod file for example.com/version v1.0.1
-# (because it is lower than the version explicitly required by m,
-# and the module that requires it — m — specifies 'go 1.17').
-#
-# That go.mod file happens not to affect the final 1.16 module graph anyway,
-# so the pruned graph is equivalent to the unpruned one.
-
-cp go.mod go.mod.orig
-! go mod tidy -diff
-stdout 'diff current go.sum tidy go.sum'
-stdout '\+example.com/version v1.0.1/go.mod h1:S7K9BnT4o5wT4PCczXPfWVzpjD4ud4e7AJMQJEgiu2Q='
-stdout '\+example.com/version v1.1.0 h1:VdPnGmIF1NJrntStkxGrF3L/OfhaL567VzCjncGUgtM='
-stdout '\+example.com/version v1.1.0/go.mod h1:S7K9BnT4o5wT4PCczXPfWVzpjD4ud4e7AJMQJEgiu2Q='
-! stdout 'diff current go.mod tidy go.mod'
-go mod tidy
-cmp go.mod go.mod.orig
-
-
-# If we explicitly drop compatibility with 1.16, we retain fewer checksums,
-# which gives a cleaner go.sum file but causes 1.16 to fail in readonly mode.
-
-cp go.mod.orig go.mod
-! go mod tidy -compat=1.17 -diff
-stdout 'diff current go.sum tidy go.sum'
-stdout '\-example.com/version v1.0.1/go.mod h1:S7K9BnT4o5wT4PCczXPfWVzpjD4ud4e7AJMQJEgiu2Q='
-go mod tidy -compat=1.17
-cmp go.mod go.mod.orig
-
--- go.mod --
-// Module m happens to have the exact same build list as what would be
-// selected under Go 1.16, but computes that build list without looking at
-// as many go.mod files.
-module example.com/m
-
-go 1.17
-
-replace example.net/lazy v0.1.0 => ./lazy
-
-require (
-       example.com/version v1.1.0
-       example.net/lazy v0.1.0
-)
--- compatible.go --
-package compatible
-
-import (
-       _ "example.com/version"
-       _ "example.net/lazy"
-)
--- lazy/go.mod --
-// Module lazy requires example.com/version v1.0.1.
-//
-// However, since this module is lazy, its dependents
-// should not need checksums for that version of the module
-// unless they actually import packages from it.
-module example.net/lazy
-
-go 1.17
-
-require example.com/version v1.0.1
--- lazy/lazy.go --
-package lazy
-
-import _ "example.com/version"