Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SoMsg #451

Merged
merged 3 commits into from Apr 27, 2021
Merged

SoMsg #451

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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