Add test.Helper, also works with Go 1.8

This commit is contained in:
Alexander Neumann
2018-03-30 22:49:49 +02:00
parent a472868e06
commit 0532f08048
4 changed files with 41 additions and 0 deletions

15
internal/test/helper.go Normal file
View File

@@ -0,0 +1,15 @@
// +build go1.9
package test
import "testing"
// Helperer marks the current function as a test helper.
type Helperer interface {
Helper()
}
// Helper returns a function that marks the current function as a helper function.
func Helper(t testing.TB) Helperer {
return t
}

View File

@@ -0,0 +1,19 @@
// +build !go1.9
package test
import "testing"
// Helperer marks the current function as a test helper.
type Helperer interface {
Helper()
}
type fakeHelper struct{}
func (fakeHelper) Helper() {}
// Helper returns a function that marks the current function as a helper function.
func Helper(t testing.TB) Helperer {
return fakeHelper{}
}