Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

proposal: add control to change printing for failure output #233

Closed
poy opened this issue Nov 28, 2018 · 1 comment
Closed

proposal: add control to change printing for failure output #233

poy opened this issue Nov 28, 2018 · 1 comment

Comments

@poy
Copy link
Collaborator

poy commented Nov 28, 2018

Problem

When working with certain types (e.g., []byte) the output is not helpful:

Expected call at some_test.go:25 doesn't match the argument at index 0.
        Got: [123 34 116 101 120 116 34 58 34 86 101 114 115 105 111 110 58 32 48 46 48 46 49 34 125]
        Want: [123 34 116 101 120 116 34 58 34 86 101 114 115 115 111 110 58 32 48 46 48 46 49 34 125]

This is made worse when using a custom matcher.

Expected call at /Users/poy/workspace/go/src/user/poy/chat-bots/registrar/registrar_test.go:25 doesn't match the argument at index 0.
        Got: [123 34 116 101 120 116 34 58 34 86 101 114 115 105 111 110 58 32 48 46 48 46 49 34 125]
        Want: is equal to map[text:0.0.1]

Proposal

Add a new interface GotFormatter that a custom matcher could implement. Before printing the failure's "Got" field, check to see if the matcher implements the new interface and use it to convert the value into a string.

type GotFormatter interface {
  Format(actual interface{}) string
}
@codyoss
Copy link
Member

codyoss commented Jan 15, 2020

This feature has been added with #236

@codyoss codyoss closed this as completed Jan 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants