On Sunday, 6 December 2015 at 03:23:53 UTC, Chris Wright wrote:
I quickly hacked up something to make assertions slightly more verbose: http://dpaste.dzfl.pl/f94b6ed80b3a

This can be extended quite a bit without a ton of effort, but it would eventually devolve into fully parsing D using compile-time function execution. Still, Catch can't even handle logical or, so it should be trivial to beat it in terms of quality of error reports. No real hope of matching Spock.

The interface leaves something to be desired:
mixin enforce!(q{i == j});

Say what you will, C preprocessor macros are very low on syntactic overhead.

The other ways I know of for passing in an expression involve eager evaluation or convert the expression to an opaque delegate. The mixin is required in order to access local variables.

The name "enforce" is obviously not appropriate, and it should ideally have pluggable error reporting mechanisms. But for a first hack, it's not so bad.

I might clean this up and put it on DUB.

I guess you missed the discussions on std.experimental.testing? I thought of doing something like your enforce, but decided it was too ugly and unwieldy. It's the only way to copy what Catch does... but unfortunately it's not as nice to read or write. Like you, I came to the realization that at least this once preprocessor macros made things easier.

I still think that considering all the alternatives, the `should` functions in unit-threaded are the best way to go. Not surprising since I wrote them, but still.

Atila

Reply via email to