Unit tests and verifying pre/post-conditions and invariants

2010-08-14 Thread Jonathan M Davis
Is there a standard and/or acceptable way to make sure that pre-conditions, post-conditions, or invariants _fail_ when running unit tests? That is, lets say I had a function like this void func(int x) in { assert(x < 8); } body { //... } and I wanted to test to make sure that func() cou

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-15 Thread Lutger
Jonathan M Davis wrote: > Is there a standard and/or acceptable way to make sure that pre-conditions, > post-conditions, or invariants _fail_ when running unit tests? That is, lets > say I had a function like this > > void func(int x) > in > { > assert(x < 8); > } > body > { > //... > } >

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Steven Schveighoffer
On Sat, 14 Aug 2010 23:49:18 -0400, Jonathan M Davis wrote: Is there a standard and/or acceptable way to make sure that pre-conditions, post-conditions, or invariants _fail_ when running unit tests? That is, lets say I had a function like this void func(int x) in { assert(x < 8); } b

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Jonathan M Davis
On Monday, August 16, 2010 05:43:08 Steven Schveighoffer wrote: > On Sat, 14 Aug 2010 23:49:18 -0400, Jonathan M Davis > > wrote: > > Is there a standard and/or acceptable way to make sure that > > pre-conditions, > > post-conditions, or invariants _fail_ when running unit tests? That is, > > let

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Steven Schveighoffer
On Mon, 16 Aug 2010 12:57:22 -0400, Jonathan M Davis wrote: Ideally, unit tests and contracts would be simple. However, I do believe that there is some value in verifying that you wrote you contracts correctly. Ideally, you could use a wrapper function/template to call the function to ver

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Steven Schveighoffer
On Sat, 14 Aug 2010 23:49:18 -0400, Jonathan M Davis wrote: and I wanted to test to make sure that func() couldn't be called with any int greater or equal to 8, what would I do? The best that I can think of is to catch an AssertError and ignore it. e.g. unittest { try {

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Jonathan M Davis
On Monday, August 16, 2010 14:36:13 Steven Schveighoffer wrote: > On Sat, 14 Aug 2010 23:49:18 -0400, Jonathan M Davis > > wrote: > > and I wanted to test to make sure that func() couldn't be called with > > any int > > greater or equal to 8, what would I do? The best that I can think of is > > t

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Ali Çehreli
Steven Schveighoffer wrote: > On Mon, 16 Aug 2010 12:57:22 -0400, Jonathan M Davis > wrote: >> Of greater value is testing that normal exceptions are thrown when >> they're >> supposed to - especially for bad input. Testing that is essentially >> the same as >> testing for AssertErrors except th

Re: Unit tests and verifying pre/post-conditions and invariants

2010-08-16 Thread Jonathan M Davis
On Monday, August 16, 2010 14:46:47 Ali Çehreli wrote: > I've used the same. :) We should have something like ensure_throws: > >ensure_throws!SpecificException(functionThatShouldThrow(badInput)); > > Perhaps some of the existing unit test libraries already have that. http://d.puremagic.com/i