Skip to content

Commit 378b9e1

Browse files
committed
internal/lsp/analysis: add typeparams tests for nonewvars and noresultvalues
Also, change the way we test fillreturns to match the other analyzers. Change-Id: If2124775c583524ff61017452bf065965a6cc97e Reviewed-on: https://go-review.googlesource.com/c/tools/+/353171 Trust: Rebecca Stambler <[email protected]> Run-TryBot: Rebecca Stambler <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 24389d4 commit 378b9e1

File tree

11 files changed

+52
-23
lines changed

11 files changed

+52
-23
lines changed

internal/lsp/analysis/fillreturns/fillreturns_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import (
99

1010
"golang.org/x/tools/go/analysis/analysistest"
1111
"golang.org/x/tools/internal/lsp/analysis/fillreturns"
12+
"golang.org/x/tools/internal/typeparams"
1213
)
1314

1415
func Test(t *testing.T) {
1516
testdata := analysistest.TestData()
16-
analysistest.RunWithSuggestedFixes(t, testdata, fillreturns.Analyzer, "a")
17+
tests := []string{"a"}
18+
if typeparams.Enabled {
19+
tests = append(tests, "typeparams")
20+
}
21+
analysistest.RunWithSuggestedFixes(t, testdata, fillreturns.Analyzer, tests...)
1722
}

internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go

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

internal/lsp/analysis/fillreturns/testdata/src/a/a_118.go.golden

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fillreturns
2+
3+
func hello[T any]() int {
4+
return
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package fillreturns
2+
3+
func hello[T any]() int {
4+
return
5+
}

internal/lsp/analysis/nonewvars/nonewvars_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import (
99

1010
"golang.org/x/tools/go/analysis/analysistest"
1111
"golang.org/x/tools/internal/lsp/analysis/nonewvars"
12+
"golang.org/x/tools/internal/typeparams"
1213
)
1314

1415
func Test(t *testing.T) {
1516
testdata := analysistest.TestData()
16-
analysistest.RunWithSuggestedFixes(t, testdata, nonewvars.Analyzer, "a")
17+
tests := []string{"a"}
18+
if typeparams.Enabled {
19+
tests = append(tests, "typeparams")
20+
}
21+
analysistest.RunWithSuggestedFixes(t, testdata, nonewvars.Analyzer, tests...)
1722
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package nonewvars
2+
3+
func hello[T any]() int {
4+
var z T
5+
z := 1 // want "no new variables on left side of :="
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package nonewvars
2+
3+
func hello[T any]() int {
4+
var z T
5+
z = 1 // want "no new variables on left side of :="
6+
}

internal/lsp/analysis/noresultvalues/noresultvalues_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import (
99

1010
"golang.org/x/tools/go/analysis/analysistest"
1111
"golang.org/x/tools/internal/lsp/analysis/noresultvalues"
12+
"golang.org/x/tools/internal/typeparams"
1213
)
1314

1415
func Test(t *testing.T) {
1516
testdata := analysistest.TestData()
16-
analysistest.RunWithSuggestedFixes(t, testdata, noresultvalues.Analyzer, "a")
17+
tests := []string{"a"}
18+
if typeparams.Enabled {
19+
tests = append(tests, "typeparams")
20+
}
21+
analysistest.RunWithSuggestedFixes(t, testdata, noresultvalues.Analyzer, tests...)
1722
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package noresult
2+
3+
func hello[T any]() {
4+
var z T
5+
return z // want "no result values expected"
6+
}

0 commit comments

Comments
 (0)