[phobos] Silent failure of std.container unittests

Walter Bright walter at digitalmars.com
Fri Jul 16 22:08:03 PDT 2010



Michel Fortin wrote:
>
> And here's an illustration of a second test modelling a sequence of events. If one of these test fails, all others will fail too because they depend on each other:
>
> 	unittest {
> 		S s = new S;
> 		s.giveMeAName();
> 		assert(s.fileName);
> 		s.value = 1;
> 		assert(s.value == 1);
> 		assert(s.needsToBeSaved);
> 		s.save();
> 		assert(!s.needsToBeSaved);
> 		s.value = 2;
> 		assert(s.value == 2);
> 		assert(s.needsToBeSaved);
> 		s.revert();
> 		assert(s.value == 1);
> 		assert(!s.needsToBeSaved);
> 		...
> 	}
>
> So here you only need to know about the first error, and the rest is garbage.
>   

Yes, for that sequence, the rest are irrelevant. But what I don't
understand is why is it so bad that they also generate messages, which
you just ignore looking over the log file? Me, I'd rather see a few
extra cascaded messages, fix the ones that matter and ignore the extra,
than be short messages and have to rebuild/rerun the tests just to get
dinged again.


> It also highlights another problem about the current behaviour: what happens if one of the functions called in this test throws an exception?

The special behavior of assert() inside unittest blocks is only for the
assert()s that are lexically enclosed by the unittest block. I.e. any
others will have the usual behavior.




More information about the phobos mailing list