Skip to content

Commit

Permalink
Add Fi method to get result of test chain. It should be true with a…
Browse files Browse the repository at this point in the history
…ny failer.
  • Loading branch information
bayashi committed Feb 25, 2024
1 parent bffe2ef commit 909049f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions actually.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type testingA struct {
failNow *bool
showRawData bool
name string
failed bool
}

// Got sets the value you actually got. Got() creates *testingA and returns it.
Expand Down
1 change: 1 addition & 0 deletions actually_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var funcFail = func(a *testingA, w *w.Witness, reason string) {

func (a *testingA) doFail(w *w.Witness, reason string) {
a.t.Helper()
a.failed = true
funcFail(a, w, reason)
}

Expand Down
15 changes: 15 additions & 0 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,21 @@ func (a *testingA) Name(n string) *testingA {
return a
}

// Fi doesn NOT return `*testingA`, returns whether a test failed instead.
// If even there is only one test fails in a one chain to test, then it will be `true` anyway.
/*
func Test(t *testing.T) {
love := true
// Fi returns `true` if either `NotNil(t)`, `True(t)` or 'Same(t)' failed
if res := a.Got(love).NotNil(t).True(t).Expect(true).Same(t).Fi(); !res {
// your own some action on fail
}
}
*/
func (a *testingA) Fi() bool {
return a.failed
}

// Diff is a helper function to get a diff string of 2 objects for debugging
func Diff(a any, b any) string {
return witness.Diff(a, b)
Expand Down
11 changes: 11 additions & 0 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ func TestDump(t *testing.T) {

Got(Dump(got)).Expect(expect).X().Same(t)
}

func TestFi(t *testing.T) {
isFailed := Got(nil).Nil(t).Fi()
Got(isFailed).False(t) // Passed, so it should be `false`

stubConfirm(t, func() {
if fi := Got(isFailed).True(t).Fi(); !fi {
t.Fatal("If the test got fail, fi must return `true`. Actually, got `false`, somehow")
}
}, message_ExpectTrue)
}

0 comments on commit 909049f

Please sign in to comment.