Skip to content

Commit

Permalink
SoMsg proof of concept.
Browse files Browse the repository at this point in the history
Adds a variant of So() that allows you to specify a message that is
reported on error.
  • Loading branch information
kormat committed Aug 21, 2019
1 parent 505e419 commit 727cc15
Show file tree
Hide file tree
Showing 2 changed files with 15 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
4 changes: 4 additions & 0 deletions convey/doc.go
Expand Up @@ -125,6 +125,10 @@ func So(actual interface{}, assert assertion, expected ...interface{}) {
mustGetCurrentContext().So(actual, assert, expected...)
}

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 727cc15

Please sign in to comment.