Document guidelines for reviewing proposed additions to the API for v2.0.0 #1560
Replies: 2 comments 2 replies
-
I think it would be better to just make a cleaner and stricter API: Equal(t TestingT, actual, expected any) bool // No msgAndArgs!
Equalf(t TestingT, actual, expected any, msg string, args ...interface{}) bool like package fmt
Print(a ...any) (n int, err error)
Printf(format string, a ...any) (n int, err error) And |
Beta Was this translation helpful? Give feedback.
-
A maintainer's manifesto about Testify
|
Beta Was this translation helpful? Give feedback.
-
Note
Since writing this proposal I've come to agree with most testify maintainers that v2 shouldn't be made.
Testify frequently sees requests for new assertions, and we are trying to make the API more consistent in v2.0.0. It's not always clear what should be included (as evidenced by some of the more clunky functions already in the API). I propose that we should write as a wiki page or maybe a markdown file somewhere; the agreed standards which an assertion should meet before it is included in the API.
I've written a draft. It is only my own opinions so please do critique it rigorously. I expect there are good assertions in the API now that contravene some of these ideas.
Proposed Assertion Guidelines
This document is a set of guidelines for the inclusion of the existing and any new assertion functions in the v2.0.0 release.
Language
The function name and argument list should lead to use which documents the intended assertion in reasonably good but terse English.
Good ✅
Unclear ❌
Argument order
As #399 states, the order of arguments should be:
TestingT
msgAndArgs ...interface{}
Eg
Format functions (
Assertionf(t TestingT, actual, expected, msg string, args ...interface{})
) should not be accepted as they are equivalent to their "non-f" counterparts.Argument Names
If there is a likely actual value and expected value; then
actual
andexpected
should be the argument names.If there is no obvious actual value and there are multiple values of the same type; then consistently use
v1, v2, ...
to differentiate thev
s from any other arguments that might be present.If there is no obvious actual value and there is only one value, or values of different types; then take example from the standard library or use plain english. Be careful not to follow the stdlib examples if their argument type is descriptive but the assertion uses
interface{}
.Meta Assertions
A wrapper around an existing assertion should exist only if it improves on the readability of a pure Go implementation.
Useful ✅
Less valuable ❓
Inverse Assertions
I don't know whether to do anything here, it's tempting to say that all inverted functions should be prefixed with "Not", eg:
Equal()
andNotEqual
, ButNoError()
is perhaps better Language thanNotError()
andLess()
is definitely better thanNotGreater()
.IsNonDecreasing()
however is terrible, every assertion could be prefixed with "Is".Beta Was this translation helpful? Give feedback.
All reactions