-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassertion.go
More file actions
47 lines (41 loc) · 1.19 KB
/
assertion.go
File metadata and controls
47 lines (41 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package assert
import (
"testing"
)
// Assertion is the extension of the Go builtin `testing.T`.
//
// Please do not create an Assertion instance without the New function, every assertion function
// will panic if no inner testing.T set.
type Assertion struct {
*testing.T
}
// New returns an assertion instance for verifying invariants.
//
// assertion := assert.New(t)
// assertion.Equal(actual, expect)
// // ...
func New(t *testing.T) *Assertion {
a := new(Assertion)
if t == nil {
panic(ErrRequireT)
}
a.T = t
return a
}
// Run runs f as a subtest of a called name. It runs f in a separate goroutine
// and blocks until f returns or calls a.Parallel to become a parallel test.
// Run reports whether f succeeded (or at least did not fail before calling t.Parallel).
//
// Run may be called simultaneously from multiple goroutines, but all such calls
// must return before the outer test function for a returns.
//
// assertion := assert.New(t)
// assertion.Run("SubTest", func (a *assert.Assertion) bool {
// // TODO...
// })
func (assertion *Assertion) Run(name string, f func(a *Assertion)) bool {
return assertion.T.Run(name, func(t *testing.T) {
subAssertion := New(t)
f(subAssertion)
})
}