Let's bikeshed std.experimental.testing assertions/checks/whatchamacallits
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Sun Jul 12 08:15:02 PDT 2015
On 2015-07-10 14:37, Atila Neves wrote:
> So... unconvinced again. I tried implementing it and it started getting
> to be a right royal pain, and then I realised that there's nothing to
> prevent a user from writing their own matchers right now. From your
> example:
>
> void shouldBeParsedAs(Code code, ASTNode node) { //I don't really
> know what the types should be
> if(...) {
> throw new UnitTestException(...);
> }
> }
>
> And... done. No need for a `Should` struct, no need for the
> complications I faced trying to use one. I think the design is as good
> as it can be.
If I compare this with RSpec. A custom matcher in RSpec would implement
one method, returning a bool, to indicate if the assertion passed or
not. In your example the user need to worry about throwing exceptions
and which kind to throw. I consider that an implementation detail.
Also, RSpec is able to automatically infer a failure message based on
the name of the matcher. Optionally the matcher can customize the
failing message.
It seems like with your version you need to implement both a positive
and negative version.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list