Skip to content

Commit

Permalink
Merge pull request #451 from kormat/SoMsg
Browse files Browse the repository at this point in the history
Add SoMsg to allow tagging So assertions with an extra message.
  • Loading branch information
riannucci committed Apr 27, 2021
2 parents 5f060cc + f724034 commit 677d5b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions convey/context.go
Expand Up @@ -177,6 +177,17 @@ func (ctx *context) So(actual interface{}, assert Assertion, expected ...interfa
}
}

func (ctx *context) SoMsg(msg string, actual interface{}, assert assertion, expected ...interface{}) {
if result := assert(actual, expected...); result == assertionSuccess {
ctx.assertionReport(reporting.NewSuccessReport())
return
} else {
ctx.reporter.Enter(reporting.NewScopeReport(msg))
defer ctx.reporter.Exit()
ctx.assertionReport(reporting.NewFailureReport(result))
}
}

func (ctx *context) Reset(action func()) {
/* TODO: Failure mode configuration */
ctx.resets = append(ctx.resets, action)
Expand Down
6 changes: 6 additions & 0 deletions convey/doc.go
Expand Up @@ -24,6 +24,7 @@ type C interface {
FocusConvey(items ...interface{})

So(actual interface{}, assert Assertion, expected ...interface{})
SoMsg(msg string, actual interface{}, assert Assertion, expected ...interface{})
SkipSo(stuff ...interface{})

Reset(action func())
Expand Down Expand Up @@ -125,6 +126,11 @@ func So(actual interface{}, assert Assertion, expected ...interface{}) {
mustGetCurrentContext().So(actual, assert, expected...)
}

// SoMsg is an extension of So that allows you to specify a message to report on error.
func SoMsg(msg string, actual interface{}, assert assertion, expected ...interface{}) {
mustGetCurrentContext().SoMsg(msg, actual, assert, expected...)
}

// SkipSo is analogous to So except that the assertion that would have been passed
// to So is not executed and the reporter is notified that the assertion was skipped.
func SkipSo(stuff ...interface{}) {
Expand Down

0 comments on commit 677d5b6

Please sign in to comment.