Assert and the optional Message
Jacob Carlborg
doob at me.com
Mon Mar 12 11:22:44 PDT 2012
On 2012-03-12 15:08, Steven Schveighoffer wrote:
> My thoughts on assert/unit test:
>
> 1. AssertError (and any other Error) should not be caught by normal user
> code. Ever. It should only be caught by the runtime. However, the
> handler in the runtime could provide a hook specific to the
> OS/application and whether it is running unit tests. Obviously the hook
> would have to be set up before main runs, so that is an issue, but you
> may just need to alter the runtime in that case.
That's a good idea.
> 2. Any assert in a unit test block should halt execution in the unit
> test block. Often subsequent asserts are just noise because you are
> depending on the conditions that make the prior asserts pass.
> 3. unit test blocks should be tested individually, not on a module-level
> IMO. I'm not sure if this currently is the case.
> 4. Jonathan's statement that the program is in an "undefined state" is
> not quite true. It's in an unwound state, but not undefined. Certainly,
> you should be able to continue running more unit tests. Unit tests
> should be a) unaffected by other unit test blocks, and b) should not
> affect the running of any other code in any way. Otherwise, a program
> would run differently depending on whether unit tests ran.
> 5. If *any* unit tests fail, the main() function should not be run. If
> an assert is triggered while running main(), the program should exit.
>
> -Steve
Makes sense.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list