Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mw66 opened this issue Sep 29, 2020 · 4 comments
Open

Comments

@mw66
Copy link

mw66 commented Sep 29, 2020

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
Copy link
Owner

gedaiu commented Sep 30, 2020

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
Copy link
Author

mw66 commented Sep 30, 2020

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
Copy link
Owner

gedaiu commented Oct 1, 2020

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
Copy link
Author

mw66 commented Oct 1, 2020

last release v0.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants