Debian Codegraph @

testdata/script/diagnose.txtar

raw
1 env GO_VERSION_TEST=go1.18.29
2
3 # First, test a local build of gofumpt resulting from 'git clone'.
4 # Its version will be inferred from VCS, but since we want a stable test,
5 # we mock the VCS information. Note that test binaries do not have VCS info.
6 # Data obtained from a real build while developing.
7 env GARBLE_TEST_BUILDSETTINGS='[{"Key":"vcs","Value":"git"},{"Key":"vcs.revision","Value":"8dda8068d9f339047fc1777b688afb66a0a0db17"},{"Key":"vcs.time","Value":"2022-07-27T15:58:40Z"},{"Key":"vcs.modified","Value":"true"}]'
8 exec gofumpt foo.go
9 cmp stdout foo.go.golden
10
11 exec gofumpt outdated.go
12 cmp stdout foo.go.golden
13
14 exec gofumpt -extra foo.go
15 cmp stdout foo.go.golden-extra
16
17 exec gofumpt -lang=1.0 foo.go
18 cmp stdout foo.go.golden-lang
19
20 exec gofumpt -d nochange.go
21 ! stdout .
22
23 exec gofumpt -d foo.go.golden
24 ! stdout .
25
26 exec gofumpt -d -extra foo.go.golden-extra
27 ! stdout .
28
29 # A local build without VCS information will result in a missing version.
30 env GARBLE_TEST_BUILDSETTINGS='[]'
31 exec gofumpt foo.go
32 cmp stdout foo.go.golden-devel
33
34 [short] stop 'the rest of this test builds gofumpt binaries'
35
36 # We want a published version of gofumpt on the public module proxies,
37 # because that's the only way that its module version will be included.
38 # Using a directory replace directive will not work.
39 # This means that any change in how gofumpt reports its own version
40 # will require two pull requests, the second one updating the test script.
41 # We could consider using go-internal/goproxytest, but then we would need to
42 # manually run something like go-internal/cmd/txtar-addmod reguarly.
43 # Or teach goproxytest to serve a mock version of gofumpt from its local checkout.
44 # Either way, both are relatively overkill for now.
45 env GOBIN=${WORK}/bin
46 env GOFUMPT_PUBLISHED_VERSION=v0.3.2-0.20220627183521-8dda8068d9f3
47
48 # TODO: update these once the library fix hits master
49
50 # gofumpt as the main binary with a real module version.
51 go install mvdan.cc/gofumpt@${GOFUMPT_PUBLISHED_VERSION}
52 exec ${GOBIN}/gofumpt foo.go
53 cmp stdout foo.go.golden-released
54
55 # gofumpt as a library with a real module version.
56 cd ${GOMOD_DIR}/testdata/gofumpt-external
57 go install .
58 cd ${WORK}
59 stdin foo.go
60 exec ${GOBIN}/gofumpt-external
61 cmp stdout foo.go.golden-external
62
63 -- go.mod --
64 module test
65
66 go 1.16
67 -- foo.go --
68 package p
69
70 //gofumpt:diagnose
71 -- outdated.go --
72 package p
73
74 //gofumpt:diagnose v0.1.0
75 -- nochange.go --
76 package p
77
78 //gofumpt:diagnosefoobar
79 -- foo.go.golden --
80 package p
81
82 //gofumpt:diagnose version: v0.0.0-20220727155840-8dda8068d9f3 (go1.18.29) flags: -lang=v1.16 -modpath=test
83 -- foo.go.golden-devel --
84 package p
85
86 //gofumpt:diagnose version: (devel) (go1.18.29) flags: -lang=v1.16 -modpath=test
87 -- foo.go.golden-extra --
88 package p
89
90 //gofumpt:diagnose version: v0.0.0-20220727155840-8dda8068d9f3 (go1.18.29) flags: -lang=v1.16 -modpath=test -extra
91 -- foo.go.golden-lang --
92 package p
93
94 //gofumpt:diagnose version: v0.0.0-20220727155840-8dda8068d9f3 (go1.18.29) flags: -lang=v1.0 -modpath=test
95 -- foo.go.golden-released --
96 package p
97
98 //gofumpt:diagnose v0.3.2-0.20220627183521-8dda8068d9f3 -lang=v1.16 -modpath=test
99 -- foo.go.golden-external --
100 package p
101
102 //gofumpt:diagnose (devel) -lang=v1.16 -modpath=