How do you test pre-/post-conditions and invariants?

spir denis.spir at gmail.com
Fri Feb 25 15:11:21 PST 2011


On 02/25/2011 11:20 PM, Magnus Lie Hetland wrote:
> On 2011-02-25 17:48:54 +0100, spir said:
>
>> On 02/25/2011 04:30 PM, Magnus Lie Hetland wrote:
>>> Or, more generally, how do you test asserts (which is what I'm using in my
>>> preconditions etc.)?
>>>
>>> As far as I can see, collectException() won't collect errors, which is what
>>> assert() throws -- so what's the standard way of writing unit tests for
>>> preconditions that use assert? (I.e., test that they will, in fact, throw when
>>> you break them.)
>>
>> See the page on DbC: http://www.digitalmars.com/d/2.0/dbc.html.
>>
>> Denis
>
> Hm. I'm not sure how this answers my question. I know how pre/postconditions
> etc. work -- I was asking for how to test them in a unit test (i.e., ensure
> that they'll kick in if you provide faulty intput, for example). Maybe I'm
> missing something in the doc you referred me to?

No, sorry, /I/ read your post too superficially: Hadn't caught you wanted to 
"meta-check" the checks.

Denis
-- 
_________________
vita es estrany
spir.wikidot.com



More information about the Digitalmars-d-learn mailing list