fluent-asserts icon indicating copy to clipboard operation
fluent-asserts copied to clipboard

is there a build config string, that will turn off all asserts into no-op?

Open mw66 opened this issue 5 years ago • 4 comments

Hi,

I use this library not just in unittest, but also as a replacement for the D built-in assert in the normal code. But I want to turn off these Asserts in release build, I'm wondering is there a build config string, that will turn off all asserts into no-op?

If currently there is none, can we add such build config?

Thanks.

mw66 avatar Sep 29 '20 17:09 mw66

Hmm... I think we can do this, but then you will have calls to empty functions, hoping that the compiler / optimiser will remove those calls, but I can not guarantee that will happen.

gedaiu avatar Sep 30 '20 10:09 gedaiu

I've done some code like this:

version (ASSERT) {
public import fluent.asserts;
} else {
  pragma(msg, "NOTE: using dummy Assert!");
class Assert {
  public static void cmp(X, Y)(X x, Y y, string msg="") {}
  alias greaterThan = cmp;
  alias lessThan = cmp;
  alias equal = cmp;
  public static void approximately(X, Y, Z)(X x, Y y, Z=0) {}
}
}

mw66 avatar Sep 30 '20 21:09 mw66

Yes, this is what I was talking about. With this solution you will still have this function call in your code. It can be done. Are you using the last release v13.x.x or master?

gedaiu avatar Oct 01 '20 07:10 gedaiu

last release v0.13.0.

mw66 avatar Oct 01 '20 17:10 mw66