Skip to content

Commit f1b4a0b

Browse files
committed
feat: overwrite Run method.
1 parent ebb5636 commit f1b4a0b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

assertion.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ func New(t *testing.T) *Assertion {
1919

2020
return a
2121
}
22+
23+
// Run runs f as a subtest of a called name. It runs f in a separate goroutine
24+
// and blocks until f returns or calls a.Parallel to become a parallel test.
25+
// Run reports whether f succeeded (or at least did not fail before calling t.Parallel).
26+
//
27+
// Run may be called simultaneously from multiple goroutines, but all such calls
28+
// must return before the outer test function for a returns.
29+
func (assertion *Assertion) Run(name string, f func(a *Assertion)) bool {
30+
return assertion.T.Run(name, func(t *testing.T) {
31+
subAssertion := New(t)
32+
f(subAssertion)
33+
})
34+
}

assertion_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ func TestNewAssertion(t *testing.T) {
1313
New(new(testing.T))
1414
})
1515
}
16+
17+
func TestRun(t *testing.T) {
18+
a := New(t)
19+
isSubTestRun := false
20+
21+
a.Run("sub test", func(sub *Assertion) {
22+
DeepEqualNow(t, sub.Name(), "TestRun/sub_test")
23+
isSubTestRun = true
24+
})
25+
26+
DeepEqualNow(t, isSubTestRun, true)
27+
}

0 commit comments

Comments
 (0)