summaryrefslogtreecommitdiff
path: root/vendor/github.com/stretchr/testify/suite
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-08-31 17:31:21 +0200
committerLibravatar GitHub <noreply@github.com>2022-08-31 17:31:21 +0200
commit0245c606d77c8b99833ccc2c0923a298fb482236 (patch)
tree16311e89656894f09cfaeb8b0f21b5ac9e4de502 /vendor/github.com/stretchr/testify/suite
parent[feature] add rate limit middleware (#741) (diff)
downloadgotosocial-0245c606d77c8b99833ccc2c0923a298fb482236.tar.xz
[chore] Test fixes (#788)
* use 'test' value for testrig storage backend * update test dependency * add WaitFor func in testrig * use WaitFor function instead of time.Sleep * tidy up tests * make SentMessages a sync.map * go fmt
Diffstat (limited to 'vendor/github.com/stretchr/testify/suite')
-rw-r--r--vendor/github.com/stretchr/testify/suite/suite.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/vendor/github.com/stretchr/testify/suite/suite.go b/vendor/github.com/stretchr/testify/suite/suite.go
index b9b5d1c56..895591878 100644
--- a/vendor/github.com/stretchr/testify/suite/suite.go
+++ b/vendor/github.com/stretchr/testify/suite/suite.go
@@ -7,6 +7,7 @@ import (
"reflect"
"regexp"
"runtime/debug"
+ "sync"
"testing"
"time"
@@ -21,17 +22,22 @@ var matchMethod = flag.String("testify.m", "", "regular expression to select tes
// retrieving the current *testing.T context.
type Suite struct {
*assert.Assertions
+ mu sync.RWMutex
require *require.Assertions
t *testing.T
}
// T retrieves the current *testing.T context.
func (suite *Suite) T() *testing.T {
+ suite.mu.RLock()
+ defer suite.mu.RUnlock()
return suite.t
}
// SetT sets the current *testing.T context.
func (suite *Suite) SetT(t *testing.T) {
+ suite.mu.Lock()
+ defer suite.mu.Unlock()
suite.t = t
suite.Assertions = assert.New(t)
suite.require = require.New(t)
@@ -39,6 +45,8 @@ func (suite *Suite) SetT(t *testing.T) {
// Require returns a require context for suite.
func (suite *Suite) Require() *require.Assertions {
+ suite.mu.Lock()
+ defer suite.mu.Unlock()
if suite.require == nil {
suite.require = require.New(suite.T())
}
@@ -51,14 +59,20 @@ func (suite *Suite) Require() *require.Assertions {
// assert.Assertions with require.Assertions), this method is provided so you
// can call `suite.Assert().NoError()`.
func (suite *Suite) Assert() *assert.Assertions {
+ suite.mu.Lock()
+ defer suite.mu.Unlock()
if suite.Assertions == nil {
suite.Assertions = assert.New(suite.T())
}
return suite.Assertions
}
-func failOnPanic(t *testing.T) {
+func recoverAndFailOnPanic(t *testing.T) {
r := recover()
+ failOnPanic(t, r)
+}
+
+func failOnPanic(t *testing.T, r interface{}) {
if r != nil {
t.Errorf("test panicked: %v\n%s", r, debug.Stack())
t.FailNow()
@@ -81,7 +95,7 @@ func (suite *Suite) Run(name string, subtest func()) bool {
// Run takes a testing suite and runs all of the tests attached
// to it.
func Run(t *testing.T, suite TestingSuite) {
- defer failOnPanic(t)
+ defer recoverAndFailOnPanic(t)
suite.SetT(t)
@@ -126,10 +140,12 @@ func Run(t *testing.T, suite TestingSuite) {
F: func(t *testing.T) {
parentT := suite.T()
suite.SetT(t)
- defer failOnPanic(t)
+ defer recoverAndFailOnPanic(t)
defer func() {
+ r := recover()
+
if stats != nil {
- passed := !t.Failed()
+ passed := !t.Failed() && r == nil
stats.end(method.Name, passed)
}
@@ -142,6 +158,7 @@ func Run(t *testing.T, suite TestingSuite) {
}
suite.SetT(parentT)
+ failOnPanic(t, r)
}()
if setupTestSuite, ok := suite.(SetupTestSuite); ok {