From 851b69baf92d2bb98364d75750be0e8a59c03df9 Mon Sep 17 00:00:00 2001 From: Adam Luzsi Date: Wed, 6 Mar 2024 23:28:44 +0100 Subject: [PATCH] Message Formatting function for assert package This should make it easier to have fmt style formatted messages in the assertions. --- assert/message.go | 6 ++++++ assert/message_test.go | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/assert/message.go b/assert/message.go index 541b4fd..caa90f6 100644 --- a/assert/message.go +++ b/assert/message.go @@ -1,7 +1,13 @@ package assert +import "fmt" + type Message string +func MessageF(format string, args ...any) Message { + return Message(fmt.Sprintf(format, args...)) +} + func toMsg(msg []Message) []any { var out []any for _, m := range msg { diff --git a/assert/message_test.go b/assert/message_test.go index e0a6a5b..ef57991 100644 --- a/assert/message_test.go +++ b/assert/message_test.go @@ -22,3 +22,8 @@ func TestMessage(t *testing.T) { a.True(false, exp) assert.Contain(t, dtb.Logs.String(), strings.TrimSpace(string(exp))) } + +func TestMessagef(t *testing.T) { + exp := assert.MessageF("answer:%d", 42) + assert.Equal[assert.Message](t, exp, "answer:42") +}