...
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'
12stderr 'go.mod file not found'
13
14# Missing go.mod and existing go.sum should fail and not display diff.
15cp go.sum.orig go.sum
16! exists go.mod
17exists 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'
22stderr 'go.mod file not found'
23
24# Existing go.mod and missing go.sum should display diff.
25go mod init example.com
26go mod tidy
27rm go.sum
28exists go.mod
29! exists go.sum
30! go mod tidy -diff
31! exists go.sum
32! stdout 'diff current/go.mod tidy/go.mod'
33stdout 'diff current/go.sum tidy/go.sum'
34
35# Everything is tidy, should return zero exit code.
36go mod tidy
37go 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.
42cp go.mod.orig go.mod
43! go mod tidy -diff
44stdout 'diff current/go.mod tidy/go.mod'
45! stdout 'diff current/go.sum tidy/go.sum'
46cmp go.mod.orig go.mod
47
48# go.sum requires updates, should return non-zero exit code.
49go mod tidy
50cp go.sum.orig go.sum
51! go mod tidy -diff
52! stdout 'diff current/go.mod tidy/go.mod'
53stdout 'diff current/go.sum tidy/go.sum'
54cmp go.sum.orig go.sum
55
56# go.mod and go.sum require updates, should return non-zero exit code.
57cp go.mod.orig go.mod
58cp go.sum.orig go.sum
59! go mod tidy -diff
60stdout 'diff current/go.mod tidy/go.mod'
61stdout 'diff current/go.sum tidy/go.sum'
62cmp go.mod.orig go.mod
63cmp 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 --
86package main
87
88import "rsc.io/quote"
89
90func main() {
91 println(quote.Hello())
92}
93
94-- go.mod.orig --
95module example.com
96
97go 1.22
98-- go.sum.orig --
99rsc.io/quote v1.5.2 h1:3fEykkD9k7lYzXqCYrwGAf7iNhbk4yCjHmKBN9td4L0=
View as plain text