Skip to content

Commit

Permalink
Message Formatting function for assert package
Browse files Browse the repository at this point in the history
This should make it easier to have fmt style formatted messages in the assertions.
  • Loading branch information
adamluzsi committed Mar 6, 2024
1 parent 3b49124 commit 851b69b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions assert/message.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions assert/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 851b69b

Please sign in to comment.