mirror of https://github.com/stretchr/testify.git
Merge pull request #1535 from arjunmahishi/fix-suit-deadlock
suite: fix deadlock in suite.Require()/Assert()pull/1537/head
commit
14ffa908e6
|
@ -58,7 +58,7 @@ func (suite *Suite) Require() *require.Assertions {
|
|||
suite.mu.Lock()
|
||||
defer suite.mu.Unlock()
|
||||
if suite.require == nil {
|
||||
suite.require = require.New(suite.T())
|
||||
panic("'Require' must not be called before 'Run' or 'SetT'")
|
||||
}
|
||||
return suite.require
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func (suite *Suite) Assert() *assert.Assertions {
|
|||
suite.mu.Lock()
|
||||
defer suite.mu.Unlock()
|
||||
if suite.Assertions == nil {
|
||||
suite.Assertions = assert.New(suite.T())
|
||||
panic("'Assert' must not be called before 'Run' or 'SetT'")
|
||||
}
|
||||
return suite.Assertions
|
||||
}
|
||||
|
|
|
@ -692,3 +692,27 @@ func TestSubtestPanic(t *testing.T) {
|
|||
assert.True(t, suite.inTearDownTest)
|
||||
assert.True(t, suite.inTearDownSuite)
|
||||
}
|
||||
|
||||
type unInitialisedSuite struct {
|
||||
Suite
|
||||
}
|
||||
|
||||
// TestUnInitialisedSuites asserts the behaviour of the suite methods when the
|
||||
// suite is not initialised
|
||||
func TestUnInitialisedSuites(t *testing.T) {
|
||||
t.Run("should panic on Require", func(t *testing.T) {
|
||||
suite := new(unInitialisedSuite)
|
||||
|
||||
assert.Panics(t, func() {
|
||||
suite.Require().True(true)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("should panic on Assert", func(t *testing.T) {
|
||||
suite := new(unInitialisedSuite)
|
||||
|
||||
assert.Panics(t, func() {
|
||||
suite.Assert().True(true)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue