-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/analysis/passes/tests: update for generics
Warn about Test functions that contain type parameters. For golang/go#48704 Change-Id: I3f6852613482ec6f33e5650a014564915f11b920 Reviewed-on: https://go-review.googlesource.com/c/tools/+/359494 Run-TryBot: Tim King <taking@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Tim King <taking@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
- Loading branch information
1 parent
4d2571b
commit a2be0cd
Showing
4 changed files
with
48 additions
and
3 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
go/analysis/passes/tests/testdata/src/typeparams/typeparams.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package typeparams | ||
|
||
func Zero[T any]() T { | ||
var zero T | ||
return zero | ||
} |
21 changes: 21 additions & 0 deletions
21
go/analysis/passes/tests/testdata/src/typeparams/typeparams_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package typeparams | ||
|
||
import "testing" | ||
|
||
func Test(*testing.T) { | ||
_ = Zero[int]() // It is fine to use generics within tests. | ||
} | ||
|
||
// Note: We format {Test,Benchmark}typeParam with a 't' in "type" to avoid an error from | ||
// cmd/go/internal/load. That package can also give an error about Test and Benchmark | ||
// functions with TypeParameters. These tests may need to be updated if that logic changes. | ||
func TesttypeParam[T any](*testing.T) {} // want "TesttypeParam has type parameters: it will not be run by go test as a TestXXX function" "TesttypeParam has malformed name" | ||
func BenchmarktypeParam[T any](*testing.B) {} // want "BenchmarktypeParam has type parameters: it will not be run by go test as a BenchmarkXXX function" "BenchmarktypeParam has malformed name" | ||
|
||
func ExampleZero[T any]() { // want "ExampleZero should not have type params" | ||
print(Zero[T]()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters