Skip to content

Commit

Permalink
Fix go1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
maroux committed Nov 29, 2021
1 parent cd1a757 commit 58b5a16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 76 deletions.
76 changes: 7 additions & 69 deletions suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,78 +20,12 @@ var matchMethod = flag.String("testify.m", "", "regular expression to select tes
// appropriate *testing.T objects in tests.
type T struct {
*assert.Assertions
require *require.Assertions
testingT *testing.T
}

func (t *T) Cleanup(f func()) {
t.testingT.Cleanup(f)
}

func (t *T) Error(args ...interface{}) {
t.testingT.Error(args...)
require *require.Assertions
}

func (t *T) Errorf(format string, args ...interface{}) {
t.testingT.Errorf(format, args...)
}

func (t *T) Fail() {
t.testingT.Fail()
}

func (t *T) FailNow() {
t.testingT.FailNow()
}

func (t *T) Failed() bool {
return t.testingT.Failed()
}

func (t *T) Fatal(args ...interface{}) {
t.testingT.Fatal(args...)
}

func (t *T) Fatalf(format string, args ...interface{}) {
t.testingT.Fatalf(format, args...)
}

func (t *T) Helper() {
t.testingT.Helper()
}

func (t *T) Log(args ...interface{}) {
t.testingT.Log(args...)
}

func (t *T) Logf(format string, args ...interface{}) {
t.testingT.Logf(format, args...)
}

func (t *T) Name() string {
return t.testingT.Name()
}
func (t *T) Skip(args ...interface{}) {
t.testingT.Skip(args...)
}

func (t *T) SkipNow() {
t.testingT.SkipNow()
}

func (t *T) Skipf(format string, args ...interface{}) {
t.testingT.Skipf(format, args...)
}
func (t *T) Skipped() bool {
return t.testingT.Skipped()
}

func (t *T) TempDir() string {
return t.testingT.TempDir()
}

func (t *T) Parallel() {
t.testingT.Parallel()
t.Errorf(format, args...)
}

// setT sets the current *testing.T context.
Expand All @@ -104,6 +38,10 @@ func (t *T) setT(testingT *testing.T) {
t.require = require.New(testingT)
}

func (t *T) T() *testing.T {
return t.testingT
}

// Require returns a require context for suite.
func (t *T) Require() *require.Assertions {
if t.testingT == nil {
Expand All @@ -115,7 +53,7 @@ func (t *T) Require() *require.Assertions {
func failOnPanic(t *T) {
r := recover()
if r != nil {
t.Errorf("test panicked: %v\n%s", r, debug.Stack())
t.testingT.Errorf("test panicked: %v\n%s", r, debug.Stack())
t.testingT.FailNow()
}
}
Expand Down
14 changes: 7 additions & 7 deletions suite/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (s *SuiteTester) TestTwo(t *suite.T) {
}

func (s *SuiteTester) TestSkip(t *suite.T) {
t.Skip()
t.T().Skip()
// T should be from the right test
assert.True(t, t == s.TestT["TestSkip"])
}
Expand Down Expand Up @@ -294,7 +294,7 @@ type SuiteSkipTester struct {

func (s *SuiteSkipTester) SetupSuite(t *suite.T) {
s.SetupSuiteRunCount++
t.Skip()
t.T().Skip()
}

func (s *SuiteSkipTester) TestNothing(_ *suite.T) {
Expand Down Expand Up @@ -409,11 +409,11 @@ func TestSkippingSuiteSetup(t *testing.T) {
type SuiteLoggingTester struct{}

func (s *SuiteLoggingTester) TestLoggingPass(t *suite.T) {
t.Log("TESTLOGPASS")
t.T().Log("TESTLOGPASS")
}

func (s *SuiteLoggingTester) TestLoggingFail(t *suite.T) {
t.Log("TESTLOGFAIL")
t.T().Log("TESTLOGFAIL")
assert.NotNil(t, nil) // expected to fail
}

Expand Down Expand Up @@ -595,7 +595,7 @@ func (s *FailfastSuite) TearDownTest(_ *suite.T) {

func (s *FailfastSuite) Test_A_Fails(t *suite.T) {
s.call("Test A Fails")
t.Error("Test A meant to fail")
t.T().Error("Test A meant to fail")
}

func (s *FailfastSuite) Test_B_Passes(t *suite.T) {
Expand Down Expand Up @@ -664,15 +664,15 @@ func (s *parallelSuite) AfterTest(_ *suite.T, _, testName string) {
}

func (s *parallelSuite) Test_A(t *suite.T) {
t.Parallel()
t.T().Parallel()
s.call("Test_A")
s.mutex.Lock()
defer s.mutex.Unlock()
s.data.parallelSuiteT["Test_A"] = t
}

func (s *parallelSuite) Test_B(t *suite.T) {
t.Parallel()
t.T().Parallel()
s.call("Test_B")
s.mutex.Lock()
defer s.mutex.Unlock()
Expand Down

0 comments on commit 58b5a16

Please sign in to comment.