pull/895/head v1.5.1
Boyan 2020-02-20 06:36:43 +11:00 committed by Boyan Soubachov
parent 624f997379
commit 3ebf1ddaeb
3 changed files with 7 additions and 40 deletions

View File

@ -1,10 +1,12 @@
package suite
import "testing"
// TestingSuite can store and return the current *testing.T context
// generated by 'go test'.
type TestingSuite interface {
T() TestingT
SetT(TestingT)
T() *testing.T
SetT(*testing.T)
}
// SetupAllSuite has a SetupSuite method, which will run before the

View File

@ -17,31 +17,21 @@ import (
var allTestsFilter = func(_, _ string) (bool, error) { return true, nil }
var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run")
type TestingT interface {
Run(name string, f func(t *testing.T)) bool
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
FailNow()
Log(args ...interface{})
Logf(format string, args ...interface{})
Skip(args ...interface{})
}
// Suite is a basic testing suite with methods for storing and
// retrieving the current *testing.T context.
type Suite struct {
*assert.Assertions
require *require.Assertions
t TestingT
t *testing.T
}
// T retrieves the current *testing.T context.
func (suite *Suite) T() TestingT {
func (suite *Suite) T() *testing.T {
return suite.t
}
// SetT sets the current *testing.T context.
func (suite *Suite) SetT(t TestingT) {
func (suite *Suite) SetT(t *testing.T) {
suite.t = t
suite.Assertions = assert.New(t)
suite.require = require.New(t)

View File

@ -10,7 +10,6 @@ import (
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
@ -483,27 +482,3 @@ func (s *CallOrderSuite) Test_A() {
func (s *CallOrderSuite) Test_B() {
s.call("Test B")
}
func TestMockTCompatibility(t *testing.T) {
suiteTester := new(SuiteTester)
suiteTester.SetT(t)
// compatible with mock.T
_, ok := suiteTester.T().(mock.TestingT)
assert.True(t, ok)
// compatible with testing.T
_, ok = suiteTester.T().(*testing.T)
assert.True(t, ok)
// compatible with testing.TB
_, ok = suiteTester.T().(testing.TB)
assert.True(t, ok)
// control check
type wrongInterface interface {
NotInSuiteT() string
}
_, ok = suiteTester.T().(wrongInterface)
assert.False(t, ok)
}