Skip to content

Commit

Permalink
Add TestingT.Fatal().
Browse files Browse the repository at this point in the history
  • Loading branch information
jmalloc committed Nov 18, 2020
1 parent 2e489db commit a4c3a8e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package testkit
type TestingT interface {
Log(args ...interface{})
Logf(f string, args ...interface{})
Fatal(args ...interface{})
FailNow()
}

Expand Down
11 changes: 11 additions & 0 deletions internal/testingmock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ func (t *T) Logf(f string, args ...interface{}) {
t.Logs = append(t.Logs, lines...)
}

// Fatal is an implementation of testing.TB.Fatal().
func (t *T) Fatal(args ...interface{}) {
lines := strings.Split(fmt.Sprint(args...), "\n")
t.Logs = append(t.Logs, lines...)
t.Failed = true

if !t.FailSilently {
panic("test failed: " + lines[0])
}
}

// FailNow is an implementation of testing.TB.FailNow().
func (t *T) FailNow() {
t.Failed = true
Expand Down
12 changes: 4 additions & 8 deletions test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ func (t *Test) Prepare(actions ...Action) *Test {
OperationOptions: t.options(nil, assert.Nothing),
},
); err != nil {
t.t.Log(err)
t.t.FailNow()
t.t.Fatal(err)
}
}

Expand Down Expand Up @@ -103,8 +102,7 @@ func (t *Test) Expect(act Action, e Expectation, options ...ExpectOption) {
OperationOptions: t.options(nil, e),
},
); err != nil {
t.t.Log(err)
t.t.FailNow()
t.t.Fatal(err)
}

t.end(e)
Expand Down Expand Up @@ -188,8 +186,7 @@ func (t *Test) Call(
)

if err := fn(); err != nil {
t.t.Log(err)
t.t.FailNow()
t.t.Fatal(err)
}

t.end(a)
Expand Down Expand Up @@ -224,8 +221,7 @@ func (t *Test) dispatch(
opts := t.options(options, e)

if err := t.engine.Dispatch(t.ctx, m, opts...); err != nil {
t.t.Log(err)
t.t.FailNow()
t.t.Fatal(err)
}
}

Expand Down

0 comments on commit a4c3a8e

Please sign in to comment.