Unittests and assert

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Feb 27 21:21:04 PST 2013


On Wed, Feb 27, 2013 at 08:57:57PM -0800, Jonathan M Davis wrote:
> On Wednesday, February 27, 2013 20:50:02 H. S. Teoh wrote:
> > I just had a sinking realization today: I have been using assert inside
> > unittests to check for test results, but actually, this is wrong!
> > 
> > Why? Because when you compile with -release -unittest, all those asserts
> > disappear, and the unittests become useless.  The correct way is to use
> > enforce instead of assert.
> > 
> > Unfortunately, Phobos unittests are full of asserts rather than enforce.
> 
> Actually, building with -release doesn't disable assertions if you build with 
> -unittest. This code will assert if you bulid with both -release and -
> unittest:
[...]

Hmm. I was using assertNotThrown... which disappears with -release. I
was under the impression that it was implemented using assert, but I
guess I was wrong.


T

-- 
"Uhh, I'm still not here." -- KD, while "away" on ICQ.


More information about the Digitalmars-d mailing list