mirror of https://github.com/stretchr/testify.git
parent
624f997379
commit
3ebf1ddaeb
|
@ -1,10 +1,12 @@
|
||||||
package suite
|
package suite
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
// TestingSuite can store and return the current *testing.T context
|
// TestingSuite can store and return the current *testing.T context
|
||||||
// generated by 'go test'.
|
// generated by 'go test'.
|
||||||
type TestingSuite interface {
|
type TestingSuite interface {
|
||||||
T() TestingT
|
T() *testing.T
|
||||||
SetT(TestingT)
|
SetT(*testing.T)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetupAllSuite has a SetupSuite method, which will run before the
|
// SetupAllSuite has a SetupSuite method, which will run before the
|
||||||
|
|
|
@ -17,31 +17,21 @@ import (
|
||||||
var allTestsFilter = func(_, _ string) (bool, error) { return true, nil }
|
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")
|
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
|
// Suite is a basic testing suite with methods for storing and
|
||||||
// retrieving the current *testing.T context.
|
// retrieving the current *testing.T context.
|
||||||
type Suite struct {
|
type Suite struct {
|
||||||
*assert.Assertions
|
*assert.Assertions
|
||||||
require *require.Assertions
|
require *require.Assertions
|
||||||
t TestingT
|
t *testing.T
|
||||||
}
|
}
|
||||||
|
|
||||||
// T retrieves the current *testing.T context.
|
// T retrieves the current *testing.T context.
|
||||||
func (suite *Suite) T() TestingT {
|
func (suite *Suite) T() *testing.T {
|
||||||
return suite.t
|
return suite.t
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetT sets the current *testing.T context.
|
// SetT sets the current *testing.T context.
|
||||||
func (suite *Suite) SetT(t TestingT) {
|
func (suite *Suite) SetT(t *testing.T) {
|
||||||
suite.t = t
|
suite.t = t
|
||||||
suite.Assertions = assert.New(t)
|
suite.Assertions = assert.New(t)
|
||||||
suite.require = require.New(t)
|
suite.require = require.New(t)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/mock"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -483,27 +482,3 @@ func (s *CallOrderSuite) Test_A() {
|
||||||
func (s *CallOrderSuite) Test_B() {
|
func (s *CallOrderSuite) Test_B() {
|
||||||
s.call("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)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue