From 93d4be3623fe046fce05139701605127838857e9 Mon Sep 17 00:00:00 2001 From: Stephen Shirley Date: Thu, 13 Oct 2016 16:27:51 +0200 Subject: [PATCH 1/2] SoMsg proof of concept. Adds a variant of So() that allows you to specify a message that is reported on error. --- convey/context.go | 11 +++++++++++ convey/doc.go | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/convey/context.go b/convey/context.go index 2c75c2d7..3cfbd590 100644 --- a/convey/context.go +++ b/convey/context.go @@ -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) diff --git a/convey/doc.go b/convey/doc.go index e4f7b51a..628f5013 100644 --- a/convey/doc.go +++ b/convey/doc.go @@ -125,6 +125,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{}) { From 63cc4eee0dbc998a86d3aef8b7d7eb8fc765b748 Mon Sep 17 00:00:00 2001 From: Lukas Vogel Date: Wed, 13 Nov 2019 12:48:39 +0100 Subject: [PATCH 2/2] Add SoMsg to interface (#1) --- convey/doc.go | 1 + 1 file changed, 1 insertion(+) diff --git a/convey/doc.go b/convey/doc.go index 628f5013..30f29149 100644 --- a/convey/doc.go +++ b/convey/doc.go @@ -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())