Skip to content

Commit 228d3b5

Browse files
author
Nishanth Shanmugham
committed
typeparam test file does not need to be separate
The typeparam test was in a separate file with a go1.18 build constraint. However the test doesn't necessarily have to be in a separate file; we can instead make the typeparam testdata package, that is used by the test, build with all go versions.
1 parent 746c972 commit 228d3b5

File tree

5 files changed

+31
-37
lines changed

5 files changed

+31
-37
lines changed

exhaustive.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ To ignore specific constants in exhaustiveness checks, use the
194194
-ignore-enum-members flag. Similarly, to ignore specific types, use the
195195
-ignore-enum-types flag. For example:
196196
197-
exhaustive -ignore-enum-types '^time\.Duration$|^example.org/measure\.Unit$'
197+
exhaustive -ignore-enum-types '^time\.Duration$|^example\.org/measure\.Unit$'
198198
199199
[language spec]: https://golang.org/ref/spec
200200
*/

exhaustive_go118_test.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

exhaustive_test.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ import (
77
"golang.org/x/tools/go/analysis/analysistest"
88
)
99

10-
func runTest(t *testing.T, pattern string, setup ...func()) {
11-
t.Helper()
12-
t.Run(pattern, func(t *testing.T) {
13-
resetFlags()
14-
// default to checking switch and map for test.
15-
fCheck = stringsFlag{
16-
[]string{
17-
string(elementSwitch),
18-
string(elementMap),
19-
},
20-
nil,
21-
}
22-
for _, f := range setup {
23-
f()
24-
}
25-
analysistest.Run(t, analysistest.TestData(), Analyzer, pattern)
26-
})
27-
}
28-
2910
func TestExhaustive(t *testing.T) {
11+
runTest := func(t *testing.T, pattern string, setup ...func()) {
12+
t.Helper()
13+
t.Run(pattern, func(t *testing.T) {
14+
resetFlags()
15+
// default to checking switch and map for test.
16+
fCheck = stringsFlag{
17+
[]string{
18+
string(elementSwitch),
19+
string(elementMap),
20+
},
21+
nil,
22+
}
23+
for _, f := range setup {
24+
f()
25+
}
26+
analysistest.Run(t, analysistest.TestData(), Analyzer, pattern)
27+
})
28+
}
29+
3030
if !testing.Short() {
3131
// Analysis of code that uses complex packages, such as package os and
3232
// package reflect, should not fail.
@@ -76,6 +76,7 @@ func TestExhaustive(t *testing.T) {
7676
runTest(t, "duplicate-enum-value/...")
7777

7878
runTest(t, "typealias/...")
79+
runTest(t, "typeparam/...")
7980

8081
// mixture of general tests.
8182
runTest(t, "general/...")

testdata/src/complexpkg/complexpkg.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import (
1414
func useComplexPackages() {
1515
// see issue 25: https://github.com/nishanths/exhaustive/issues/25
1616
var (
17-
_ http.Server
17+
_ elliptic.Curve
1818
_ tls.Conn
19-
_ reflect.ChanDir
2019
_ json.Encoder
21-
_ elliptic.Curve
22-
_ time.Ticker
20+
_ fmt.Formatter
21+
_ http.Server
2322
_ os.File
23+
_ reflect.ChanDir
24+
_ time.Ticker
2425
)
25-
fmt.Println(os.LookupEnv(""))
26+
fmt.Println(os.Getgid())
2627
}

testdata/src/typeparam/build.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package typeparam
2+
3+
// This file exists so that the package (which, otherwise, consists only of
4+
// go1.18 files) can build with all go versions.

0 commit comments

Comments
 (0)