go-check / check

Rich testing for the Go language
Other
696 stars 182 forks source link

Better Comment handling by Error*/Fail* #106

Open aronatkins opened 6 years ago

aronatkins commented 6 years ago

The check.Comment type does not implement fmt.Stringer. The Error* and Fail* functions do not support check.Comment values. This means that we currently need:

c.Errorf("unexpected callback: %s", comment.CheckCommentString())

The simplest change is probably to implement Comment#String, which then allows:

c.Errorf("unexpected callback: %s", comment)

The trouble with this approach is that existing implementations of CommentInterface outside the check package would not see the benefit without adding a String implementation. Maybe that's not much of an issue, as they're probably already calling CheckCommentString directly to support Error* and Fail* calls.

Alternatively, the Error* and Fail* functions could peek at their last argument to see if it implements CommentInterface. Comments would be handled in a similar way to what happens in internalCheck to support Check and Assert.