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

Runtime interrogation of assertions-enabled status #76

Open
ELLIOTTCABLE opened this issue Jan 26, 2017 · 1 comment
Open

Runtime interrogation of assertions-enabled status #76

ELLIOTTCABLE opened this issue Jan 26, 2017 · 1 comment

Comments

@ELLIOTTCABLE
Copy link

So, for relatively simple assertions, it's possible to keep the entire assertion within the single assert( … ) statement; but I have a few places in my code where monstrosities like the following arise:

assert( null != blah.first_complicated_state() ?
   (null != blah.second_complicated_state() ?
      _.every(blah, element => ...)
    : _.every(blah, element => ...))
 : _.every(blah, element => ...)
)

Basically, sometimes, there's an expensive operation (i.e. not something I can safely leave laying around outside the assert, to end up in production code) that's necessary to choose how to assert something else.

Since I suspect asking for a to-be-compiled-out assert { … } block is unlikely to be in-line with the project goals, can I simply get a runtime-cheap boolean-property that I can test, to preform more complicated assertions that won't be compiled-out?

if (assert.enabled) {
   if (blah.first_complicated_state())
      assert( ... )

   else if (blah.second_complicated_state())
      assert( ... )
   ...
}
@twada
Copy link
Member

twada commented Jan 27, 2017

@ELLIOTTCABLE Thank you for your feature request.

For removing development-only blocks, I recommend you to use features like Conditional compilation of UglifyJS, in conjunction with:

With them you can remove development-only blocks safely.

Since power-assert aims to be 100% compatible and replaceable with native assert, I do not want to add property that Node's assert doesn't have.

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