-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use stricter check for controller type (#8)
- Loading branch information
1 parent
ee0f8d3
commit 34cb5d8
Showing
8 changed files
with
98 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package gomock | ||
|
||
// TestReporter is something that can be used to report test failures. | ||
// It imitates TestReporter from original gomock package. | ||
type TestReporter interface { | ||
Errorf(format string, args ...interface{}) | ||
Fatalf(format string, args ...interface{}) | ||
} | ||
|
||
// Controller imitates the original Controller from gomock package | ||
type Controller struct{} | ||
|
||
// Controller imitates the original Finish() on Controller from gomock package | ||
func (td *Controller) Finish() {} | ||
|
||
// NewController imitates the original NewController from gomock package. | ||
// It returns Controller imitation. | ||
func NewController(t TestReporter) *Controller { | ||
return &Controller{} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package examples_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"examples/gomock" // gomock imitation | ||
) | ||
|
||
// This file tests that the linter won't be tricked by another package source that has the same Controller object as the original package. | ||
|
||
func TestSimilarFinishCall(t *testing.T) { | ||
mock := gomock.NewController(t) | ||
mock.Finish() | ||
} | ||
|
||
func TestSimilarFinishCallDefer(t *testing.T) { | ||
mock := gomock.NewController(t) | ||
defer mock.Finish() | ||
} | ||
|
||
func TestSimilarFinishCallWithoutT(t *testing.T) { | ||
mock := gomock.NewController(nil) | ||
mock.Finish() | ||
} | ||
|
||
func TestSimilarFinsihCallInAnotherFunction(t *testing.T) { | ||
mock := gomock.NewController(t) | ||
callSimilarFinish(mock) | ||
} | ||
|
||
func callSimilarFinish(mock *gomock.Controller) { | ||
mock.Finish() | ||
} | ||
|
||
func TestSimilarNoFinishCall(t *testing.T) { | ||
gomock.NewController(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