| 1 |
# Test go mod tidy -diff |
| 2 |
# If set, -diff should not update go.mod or go.sum and instead return a non-zero exit code if updates are needed. |
| 3 |
|
| 4 |
# Missing go.mod and go.sum should fail and not display diff. |
| 5 |
! exists go.mod |
| 6 |
! exists go.sum |
| 7 |
! go mod tidy -diff |
| 8 |
! exists go.mod |
| 9 |
! exists go.sum |
| 10 |
! stdout 'diff current/go.mod tidy/go.mod' |
| 11 |
! stdout 'diff current/go.sum tidy/go.sum' |
| 12 |
stderr 'go.mod file not found' |
| 13 |
|
| 14 |
# Missing go.mod and existing go.sum should fail and not display diff. |
| 15 |
cp go.sum.orig go.sum |
| 16 |
! exists go.mod |
| 17 |
exists go.sum |
| 18 |
! go mod tidy -diff |
| 19 |
! exists go.mod |
| 20 |
! stdout 'diff current/go.mod tidy/go.mod' |
| 21 |
! stdout 'diff current/go.sum tidy/go.sum' |
| 22 |
stderr 'go.mod file not found' |
| 23 |
|
| 24 |
# Existing go.mod and missing go.sum should display diff. |
| 25 |
go mod init example.com |
| 26 |
go mod tidy |
| 27 |
rm go.sum |
| 28 |
exists go.mod |
| 29 |
! exists go.sum |
| 30 |
! go mod tidy -diff |
| 31 |
! exists go.sum |
| 32 |
! stdout 'diff current/go.mod tidy/go.mod' |
| 33 |
stdout 'diff current/go.sum tidy/go.sum' |
| 34 |
|
| 35 |
# Everything is tidy, should return zero exit code. |
| 36 |
go mod tidy |
| 37 |
go mod tidy -diff |
| 38 |
! stdout 'diff current/go.mod tidy/go.mod' |
| 39 |
! stdout 'diff current/go.sum tidy/go.sum' |
| 40 |
|
| 41 |
# go.mod requires updates, should return non-zero exit code. |
| 42 |
cp go.mod.orig go.mod |
| 43 |
! go mod tidy -diff |
| 44 |
stdout 'diff current/go.mod tidy/go.mod' |
| 45 |
! stdout 'diff current/go.sum tidy/go.sum' |
| 46 |
cmp go.mod.orig go.mod |
| 47 |
|
| 48 |
# go.sum requires updates, should return non-zero exit code. |
| 49 |
go mod tidy |
| 50 |
cp go.sum.orig go.sum |
| 51 |
! go mod tidy -diff |
| 52 |
! stdout 'diff current/go.mod tidy/go.mod' |
| 53 |
stdout 'diff current/go.sum tidy/go.sum' |
| 54 |
cmp go.sum.orig go.sum |
| 55 |
|
| 56 |
# go.mod and go.sum require updates, should return non-zero exit code. |
| 57 |
cp go.mod.orig go.mod |
| 58 |
cp go.sum.orig go.sum |
| 59 |
! go mod tidy -diff |
| 60 |
stdout 'diff current/go.mod tidy/go.mod' |
| 61 |
stdout 'diff current/go.sum tidy/go.sum' |
| 62 |
cmp go.mod.orig go.mod |
| 63 |
cmp go.sum.orig go.sum |
| 64 |
|
| 65 |
# Save the result from running tidy. |
| 66 |
[exec:patch] cp go.mod.orig go.mod |
| 67 |
[exec:patch] cp go.sum.orig go.sum |
| 68 |
[exec:patch] go mod tidy |
| 69 |
[exec:patch] cp go.mod go.mod.tidyResult |
| 70 |
[exec:patch] cp go.sum go.sum.tidyResult |
| 71 |
|
| 72 |
# Compare output of -diff to running tidy. |
| 73 |
# Apply the patch from -diff |
| 74 |
[exec:patch] cp go.mod.orig go.mod |
| 75 |
[exec:patch] cp go.sum.orig go.sum |
| 76 |
[exec:patch] ! go mod tidy -diff |
| 77 |
[exec:patch] cp stdout diff.patch |
| 78 |
[exec:patch] exec patch -p1 -i diff.patch |
| 79 |
[exec:patch] go mod tidy -diff |
| 80 |
[exec:patch] ! stdout . |
| 81 |
[exec:patch] cmp go.mod go.mod.tidyResult |
| 82 |
[exec:patch] cmp go.sum go.sum.tidyResult |
| 83 |
|
| 84 |
|
| 85 |
-- main.go -- |
| 86 |
package main |
| 87 |
|
| 88 |
import "rsc.io/quote" |
| 89 |
|
| 90 |
func main() { |
| 91 |
println(quote.Hello()) |
| 92 |
} |
| 93 |
|
| 94 |
-- go.mod.orig -- |
| 95 |
module example.com |
| 96 |
|
| 97 |
go 1.22 |
| 98 |
-- go.sum.orig -- |
| 99 |
rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0= |