@@ -16,76 +16,29 @@ func failNowPtr(v bool) *bool {
1616 return & v
1717}
1818
19- // `FailNow` turns a flag on to stop further test execution immediately if one test fails.
19+ // The method `FailNow` turns a flag on to stop further test execution immediately if one test fails.
2020/*
2121 actually.Got(something).FailNow().Nil(t) // Fail now for only this test
2222*/
23- func FailNow () * testingA {
24- return & testingA {
25- failNow : failNowPtr (true ),
26- }
27- }
2823func (a * testingA ) FailNow () * testingA {
2924 a .failNow = failNowPtr (true )
3025
3126 return a
3227}
3328
34- // FailNowOn function turns an ENV flag on to stop further test execution immediately if one test fails.
35- // This switch is enabled within the test. Not only during function.
36- /*
37- func Test(t *testing.T) {
38- actually.FailNowOn(t)
39- actually.Got(something).Nil(t) // Fail Now
40- actually.Got(something).Expect(something).Same(t) // Fail Now
41- }
42- */
43- // Warning: Do not use FailNowOn along with t.Parallel.
44- func FailNowOn (t * testing.T ) {
45- t .Setenv (envKey_FailNow , envKey_FailNow )
46- }
47-
48- // FailNotNowOn function turns an ENV flag off to stop further test execution immediately if one test fails.
49- // If you want to turn the ENV flag on, then you should call `FailNowOn`.
50- /*
51- func Test(t *testing.T) {
52- // turn on to fail right now
53- actually.FailNowOn(t)
54- actually.Got(something).Nil(t) // Fail Now
55- actually.Got(something).Expect(something).Same(t) // Fail Now
56-
57- // turn off
58- actually.FailNotNowOn(t)
59- actually.Got(something).Nil(t) // NOT Fail Now
60- actually.Got(something).Expect(something).Same(t) // NOT Fail Now
61-
62- // Fail Now by FailNow() in the chain
63- actually.Got(something).FailNow().Nil(t) // Fail Now
64-
65- // Again, turn on to fail right now
66- actually.FailNowOn(t)
67- actually.Got(something).Nil(t) // Fail Now
68- }
69- */
70- // This switch is enabled within the test. Not only during function.
71- func FailNotNowOn (t * testing.T ) {
72- t .Setenv (envKey_FailNow , "" )
73- }
74-
75- // FailNotNow turns a flag off, so that even if the test fails, execution does not stop immediately.
29+ // The function `FailNow` receives a func that is including tests of `actually`.
30+ // The included tests inside `FailNow` will stop execution immediately upon failure,
31+ // even without explicitly calling `FailNow` individually.
7632/*
77- It behaves this way by default. If you want the opposite behavior, call `FailNow` method.
33+ actually.FailNow(func() {
34+ actually.Got(false).True(t) // stop this failuer
35+ actually.Got(true).True(t) // not executed
36+ })
7837*/
79- // Deprecated: Anyone uses? This method will be removed in the near future.
80- func FailNotNow () * testingA {
81- return & testingA {
82- failNow : failNowPtr (false ),
83- }
84- }
85- func (a * testingA ) FailNotNow () * testingA {
86- a .failNow = failNowPtr (false )
87-
88- return a
38+ func FailNow (fn func ()) {
39+ aCtx .failNowOn ()
40+ defer aCtx .failNotNow ()
41+ fn ()
8942}
9043
9144// X turns on a flag to show test values as raw in a fail report.
0 commit comments