Skip to content

Commit a02ee35

Browse files
timothy-kingGo LUCI
authored and
Go LUCI
committed
go/analysis/passes/stdversion: reenable tests
Enable units tests after 1.23. Tests were rewritten for the changes to the 1.21 file version event horizon. The test is not enabled for 1.22. A backport for golang/go#68658 may be required. For golang/go#68658 Change-Id: I15f46e3ff3de7c02592d5a357ae199116323c29f Reviewed-on: https://go-review.googlesource.com/c/tools/+/615685 Reviewed-by: Alan Donovan <[email protected]> Commit-Queue: Tim King <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent a24facf commit a02ee35

File tree

2 files changed

+142
-61
lines changed

2 files changed

+142
-61
lines changed

go/analysis/passes/stdversion/stdversion_test.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ import (
1010

1111
"golang.org/x/tools/go/analysis/analysistest"
1212
"golang.org/x/tools/go/analysis/passes/stdversion"
13+
"golang.org/x/tools/internal/testenv"
1314
"golang.org/x/tools/internal/testfiles"
1415
)
1516

1617
func Test(t *testing.T) {
17-
t.Skip("Disabled for golang.org/cl/603895. Fix and re-enable.")
18+
testenv.NeedsGo1Point(t, 23) // TODO(#68658): Waiting on 1.22 backport.
19+
1820
// The test relies on go1.21 std symbols, but the analyzer
1921
// itself requires the go1.22 implementation of versions.FileVersions.
2022
dir := testfiles.ExtractTxtarFileToTmp(t, filepath.Join(analysistest.TestData(), "test.txtar"))
2123
analysistest.Run(t, dir, stdversion.Analyzer,
22-
"example.com/a",
23-
"example.com/sub",
24-
"example.com/sub20",
25-
"example.com/old")
24+
"example.com/basic",
25+
"example.com/despite",
26+
"example.com/mod20",
27+
"example.com/mod21",
28+
"example.com/mod22",
29+
"example.com/old",
30+
)
2631
}

go/analysis/passes/stdversion/testdata/test.txtar

+132-56
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ Test of "too new" diagnostics from the stdversion analyzer.
22

33
This test references go1.21 and go1.22 symbols from std.
44

5-
It uses a txtar file due to golang/go#37054.
6-
75
See also gopls/internal/test/marker/testdata/diagnostics/stdversion.txt
86
which runs the same test within the gopls analysis driver, to ensure
97
coverage of per-file Go version support.
108

119
-- go.work --
12-
go 1.21
10+
go 1.22
1311

1412
use .
15-
use sub
16-
use sub20
13+
use mod20
14+
use mod21
15+
use mod22
1716
use old
1817

1918
-- go.mod --
2019
module example.com
2120

2221
go 1.21
2322

24-
-- a/a.go --
25-
package a
23+
-- basic/basic.go --
24+
// File version is 1.21.
25+
package basic
2626

2727
import "go/types"
2828

@@ -43,13 +43,77 @@ func _() {
4343
a.Underlying() // no diagnostic
4444
}
4545

46-
-- sub/go.mod --
47-
module example.com/sub
46+
-- despite/errors.go --
47+
// File version is 1.21.
48+
49+
// Check that RunDespiteErrors is enabled.
50+
package ignore
51+
52+
import "go/types"
53+
54+
func _() {
55+
// report something before the syntax error.
56+
_ = new(types.Info).FileVersions // want `types.FileVersions requires go1.22 or later \(module is go1.21\)`
57+
}
58+
59+
invalid syntax // exercise RunDespiteErrors
60+
61+
-- mod20/go.mod --
62+
module example.com/mod20
63+
64+
go 1.20
65+
66+
-- mod20/notag.go --
67+
// The 1.20 module is before the forward compatibility regime:
68+
// The file's build tag effects selection, but
69+
// not language semantics, so stdversion is silent.
70+
71+
package mod20
72+
73+
import "go/types"
74+
75+
func _() {
76+
var _ types.Alias
77+
}
78+
79+
-- mod20/tag16.go --
80+
// The 1.20 module is before the forward compatibility regime:
81+
// The file's build tag effects selection, but
82+
// not language semantics, so stdversion is silent.
83+
84+
//go:build go1.16
85+
86+
package mod20
87+
88+
import "bytes"
89+
import "go/types"
90+
91+
var _ = bytes.Clone
92+
var _ = types.Alias
93+
94+
-- mod20/tag22.go --
95+
// The 1.20 module is before the forward compatibility regime:
96+
// The file's build tag effects selection, but
97+
// not language semantics, so stdversion is silent.
98+
99+
//go:build go1.22
100+
101+
package mod20
102+
103+
import "bytes"
104+
import "go/types"
105+
106+
var _ = bytes.Clone
107+
var _ = types.Alias
108+
109+
-- mod21/go.mod --
110+
module example.com/mod21
48111

49112
go 1.21
50113

51-
-- sub/sub.go --
52-
package sub
114+
-- mod21/notag.go --
115+
// File version is 1.21.
116+
package mod21
53117

54118
import "go/types"
55119

@@ -70,79 +134,91 @@ func _() {
70134
a.Underlying() // no diagnostic
71135
}
72136

73-
invalid syntax // exercise RunDespiteErrors
137+
-- mod21/tag16.go --
138+
// File version is 1.21.
139+
//
140+
// The module is within the forward compatibility regime so
141+
// the build tag (1.16) can modify the file version, but it cannot
142+
// go below the 1.21 "event horizon" (#68658).
74143

75-
-- sub/tagged.go --
76-
//go:build go1.22
144+
//go:build go1.16
77145

78-
package sub
146+
package mod21
79147

148+
import "bytes"
80149
import "go/types"
81150

82-
func _() {
83-
// old package-level type
84-
var _ types.Info
151+
var _ = bytes.Clone
152+
var _ = types.Alias // want `types.Alias requires go1.22 or later \(module is go1.21\)`
85153

86-
// new field of older type
87-
_ = new(types.Info).FileVersions
154+
-- mod21/tag22.go --
155+
// File version is 1.22.
156+
//
157+
// The module is within the forward compatibility regime so
158+
// the build tag (1.22) updates the file version to 1.22.
88159

89-
// new method of older type
90-
new(types.Info).PkgNameOf
160+
//go:build go1.22
91161

92-
// new package-level type
93-
var a types.Alias
162+
package mod21
94163

95-
// new method of new type
96-
a.Underlying()
97-
}
164+
import "bytes"
165+
import "go/types"
98166

99-
-- old/go.mod --
100-
module example.com/old
167+
var _ = bytes.Clone
168+
var _ = types.Alias
101169

102-
go 1.5
170+
-- mod22/go.mod --
171+
module example.com/mod22
103172

104-
-- old/old.go --
105-
package old
173+
go 1.22
174+
175+
-- mod22/notag.go --
176+
// File version is 1.22.
177+
package mod22
106178

107179
import "go/types"
108180

109-
var _ types.Alias // no diagnostic: go.mod is too old for us to care
181+
func _() {
182+
var _ = bytes.Clone
183+
var _ = types.Alias
184+
}
110185

111-
-- sub/oldtagged.go --
112-
// The file Go version (1.16) overrides the go.mod Go version (1.21),
113-
// even when this means a downgrade (#67123).
114-
// (stdversion is silent for go.mod versions before 1.21:
115-
// before the forward compatibility regime, the meaning
116-
// of the go.mod version was not clearly defined.)
186+
-- mod22/tag16.go --
187+
// File version is 1.21.
188+
//
189+
// The module is within the forward compatibility regime so
190+
// the build tag (1.16) can modify the file version, but it cannot
191+
// go below the 1.21 "event horizon" (#68658).
117192

118193
//go:build go1.16
119194

120-
package sub
195+
package mod22
121196

122197
import "bytes"
123198
import "go/types"
124199

125-
var _ = bytes.Clone // want `bytes.Clone requires go1.20 or later \(file is go1.16\)`
126-
var _ = types.Alias // want `types.Alias requires go1.22 or later \(file is go1.16\)`
200+
var _ = bytes.Clone
201+
var _ = types.Alias // want `types.Alias requires go1.22 or later \(file is go1.21\)`
127202

128-
-- sub20/go.mod --
129-
module example.com/sub20
203+
-- old/go.mod --
204+
module example.com/old
130205

131-
go 1.20
206+
go 1.5
132207

133-
-- sub20/oldtagged.go --
134-
// Same test again, but with a go1.20 mod,
135-
// before the forward compatibility regime:
136-
// The file's build tag effects selection, but
137-
// not language semantics, so stdversion is silent.
208+
-- old/notag.go --
209+
package old
138210

139-
//go:build go1.16
211+
import "go/types"
140212

141-
package sub
213+
var _ types.Alias // no diagnostic: go.mod is too old for us to care
142214

143-
import "bytes"
144-
import "go/types"
215+
-- old/tag21.go --
216+
// The build tag is ignored due to the module version.
145217

146-
var _ = bytes.Clone
147-
var _ = types.Alias
218+
//go:build go1.21
219+
220+
package old
221+
222+
import "go/types"
148223

224+
var _ = types.Alias // no diagnostic: go.mod is too old for us to care

0 commit comments

Comments
 (0)