gedaiu / fluent-asserts

DLang fluent assertions done right
http://fluentasserts.szabobogdan.com/
MIT License
43 stars 6 forks source link

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

Open mw66 opened 4 years ago

mw66 commented 4 years ago

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.

gedaiu commented 4 years ago

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.

mw66 commented 4 years ago

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) {}
}
}
gedaiu commented 4 years ago

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?

mw66 commented 4 years ago

last release v0.13.0.