Re: Assert and the optional Message

2012-03-12 Thread Jacob Carlborg
On 2012-03-12 15:08, Steven Schveighoffer wrote: I contended that unit test asserts should result in a hook that by default kills the program, but could be hooked into a unit testing handler. But the consensus was just to switch back to the original behavior (all asserts kill the program). If you

Re: Assert and the optional Message

2012-03-12 Thread Jacob Carlborg
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

Re: Assert and the optional Message

2012-03-12 Thread Jonathan M Davis
On Monday, March 12, 2012 09:40:44 Jacob Carlborg wrote: > On 2012-03-11 22:12, Jonathan M Davis wrote: > > On Sunday, March 11, 2012 13:13:58 Jacob Carlborg wrote: > >> Yeah, exactly. And it feels a bit stupid to duplicate the assert > >> statement just to throw something that isn't an AssertError

Re: Assert and the optional Message

2012-03-12 Thread Steven Schveighoffer
On Sat, 10 Mar 2012 01:09:02 -0500, Jonathan M Davis wrote: On Friday, March 09, 2012 22:48:25 Timon Gehr wrote: On 03/09/2012 10:43 PM, Jonathan M Davis wrote: ... >> Jonathan is just speculating. And I think he is wrong. > > Speculating about what? > > - Jonathan M Davis About how assert

Re: Assert and the optional Message

2012-03-12 Thread Steven Schveighoffer
On Sat, 10 Mar 2012 11:03:43 -0500, Jacob Carlborg wrote: On 2012-03-09 20:06, Jonathan M Davis wrote: In what way? Yes, they're _catchable_, but everything that was on the unwound portion of the stack is now in an undefined state. So, recovering from the AssertError and continuing executi

Re: Assert and the optional Message

2012-03-12 Thread Jacob Carlborg
On 2012-03-11 22:12, Jonathan M Davis wrote: On Sunday, March 11, 2012 13:13:58 Jacob Carlborg wrote: Yeah, exactly. And it feels a bit stupid to duplicate the assert statement just to throw something that isn't an AssertError. Not to say that it's what you have to do, but I _would_ point ou

Re: Assert and the optional Message

2012-03-11 Thread Jonathan M Davis
On Sunday, March 11, 2012 13:13:58 Jacob Carlborg wrote: > On 2012-03-10 18:08, Jonathan M Davis wrote: > > I honestly don't think that Walter even considered unit testing frameworks > > when he came up with the design. He built unit tests into the language. > > So, > > from his point of view, why

Re: Assert and the optional Message

2012-03-11 Thread Jacob Carlborg
On 2012-03-10 18:08, Jonathan M Davis wrote: I honestly don't think that Walter even considered unit testing frameworks when he came up with the design. He built unit tests into the language. So, from his point of view, why would you need a unit testing framework? He probably didn't even conside

Re: Assert and the optional Message

2012-03-11 Thread Jacob Carlborg
On 2012-03-10 17:58, Jonathan M Davis wrote: 2. As long as unit tests are properly isolated, then it's unlikely to be a big issue, and even if it _is_ problem, it's only a problem as long as tests are failing. So, while this may cause problems in some cases, it's still arguably worth it, since t

Re: Assert and the optional Message

2012-03-11 Thread Jacob Carlborg
On 2012-03-10 17:48, Jonathan M Davis wrote: On Saturday, March 10, 2012 16:53:42 Jacob Carlborg wrote: On 2012-03-09 18:59, H. S. Teoh wrote: This opens up the question of, what's the *recommended* way of writing unittests that check for these sorts of stuff? For example, I believe in being t

Re: Assert and the optional Message

2012-03-10 Thread H. S. Teoh
On Sat, Mar 10, 2012 at 11:09:04AM -0800, Jonathan M Davis wrote: > On Saturday, March 10, 2012 09:04:42 H. S. Teoh wrote: [...] > > Hmm. The more I think about it, the more I'm leaning towards > > simplifying contracts so that most, if not all, of any complicated > > checks happen in an external f

Re: Assert and the optional Message

2012-03-10 Thread Jonathan M Davis
On Saturday, March 10, 2012 09:04:42 H. S. Teoh wrote: > On Sat, Mar 10, 2012 at 08:48:32AM -0800, Jonathan M Davis wrote: > > On Saturday, March 10, 2012 16:53:42 Jacob Carlborg wrote: > > > On 2012-03-09 18:59, H. S. Teoh wrote: > [.[..] > > > > > I agree, though, that catching Errors outside of

Re: Assert and the optional Message

2012-03-10 Thread Jonathan M Davis
On Saturday, March 10, 2012 17:03:43 Jacob Carlborg wrote: > On 2012-03-09 20:06, Jonathan M Davis wrote: > > In what way? Yes, they're _catchable_, but everything that was on the > > unwound portion of the stack is now in an undefined state. So, recovering > > from the AssertError and continuing e

Re: Assert and the optional Message

2012-03-10 Thread H. S. Teoh
On Sat, Mar 10, 2012 at 08:48:32AM -0800, Jonathan M Davis wrote: > On Saturday, March 10, 2012 16:53:42 Jacob Carlborg wrote: > > On 2012-03-09 18:59, H. S. Teoh wrote: [.[..] > > > I agree, though, that catching Errors outside of unittests is a > > > very, very bad idea in general. > > > > I don

Re: Assert and the optional Message

2012-03-10 Thread Jonathan M Davis
On Saturday, March 10, 2012 16:52:43 Jacob Carlborg wrote: > On 2012-03-09 17:56, Jonathan M Davis wrote: > > The current implementation may not skip them, but if so, that might > > actually be a bug. Errors are not intended to be recoverable, so you > > can't rely on them hitting finally blocks, s

Re: Assert and the optional Message

2012-03-10 Thread Jonathan M Davis
On Saturday, March 10, 2012 16:53:42 Jacob Carlborg wrote: > On 2012-03-09 18:59, H. S. Teoh wrote: > > This opens up the question of, what's the *recommended* way of writing > > unittests that check for these sorts of stuff? > > > > For example, I believe in being thorough in unit tests, so I lik

Re: Assert and the optional Message

2012-03-10 Thread Jacob Carlborg
On 2012-03-09 20:06, Jonathan M Davis wrote: In what way? Yes, they're _catchable_, but everything that was on the unwound portion of the stack is now in an undefined state. So, recovering from the AssertError and continuing execution doesn't work. So, a handler can catch the AssertError and do

Re: Assert and the optional Message

2012-03-10 Thread Jacob Carlborg
On 2012-03-09 18:59, H. S. Teoh wrote: This opens up the question of, what's the *recommended* way of writing unittests that check for these sorts of stuff? For example, I believe in being thorough in unit tests, so I like to use them to verify that the complicated in-contract I just wrote actu

Re: Assert and the optional Message

2012-03-10 Thread Jacob Carlborg
On 2012-03-09 17:56, Jonathan M Davis wrote: The current implementation may not skip them, but if so, that might actually be a bug. Errors are not intended to be recoverable, so you can't rely on them hitting finally blocks, scope statements, or destructors. They may very well do so at present.

Re: Assert and the optional Message

2012-03-10 Thread Jacob Carlborg
On 2012-03-09 17:56, Jonathan M Davis wrote: It was never intended that AssertError or any other Error be particularly catchable, but it's also true that D is a systems programming language, so it'll let you do stuff which is unsafe, so if you know what you're doing, then there are circumstances

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 22:48:25 Timon Gehr wrote: > On 03/09/2012 10:43 PM, Jonathan M Davis wrote: > ... > > >> Jonathan is just speculating. And I think he is wrong. > > > > Speculating about what? > > > > - Jonathan M Davis > > About how assertion failures affect struct destructors, final

Re: Assert and the optional Message

2012-03-09 Thread Ali Çehreli
On 03/09/2012 03:02 AM, Jonathan M Davis wrote: > contorting your program to try and print assert > messages to a file just because VisualD has problems with closing the Window on > you is a _bad_ idea IMHO. Absolutely! Inserting lines at the end of programs is not the correct solution to th

Re: Assert and the optional Message

2012-03-09 Thread Timon Gehr
On 03/09/2012 10:43 PM, Jonathan M Davis wrote: ... Jonathan is just speculating. And I think he is wrong. Speculating about what? - Jonathan M Davis About how assertion failures affect struct destructors, finally statements and scope statements. If they wouldn't be executed upon thrown A

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 22:03:11 Timon Gehr wrote: > On 03/09/2012 08:29 PM, H. S. Teoh wrote: > > On Fri, Mar 09, 2012 at 01:37:38PM -0500, Jonathan M Davis wrote: > >> On Friday, March 09, 2012 09:59:42 H. S. Teoh wrote: > > [...] > > > >>> This opens up the question of, what's the *recommende

Re: Assert and the optional Message

2012-03-09 Thread Timon Gehr
On 03/09/2012 08:29 PM, H. S. Teoh wrote: On Fri, Mar 09, 2012 at 01:37:38PM -0500, Jonathan M Davis wrote: On Friday, March 09, 2012 09:59:42 H. S. Teoh wrote: [...] This opens up the question of, what's the *recommended* way of writing unittests that check for these sorts of stuff? For exam

Re: Assert and the optional Message

2012-03-09 Thread Timon Gehr
On 03/09/2012 07:37 PM, H. S. Teoh wrote: On Fri, Mar 09, 2012 at 07:23:20PM +0100, Timon Gehr wrote: On 03/09/2012 05:56 PM, Jonathan M Davis wrote: [...] It was never intended that AssertError or any other Error be particularly catchable, but it's also true that D is a systems programming la

Re: Assert and the optional Message

2012-03-09 Thread H. S. Teoh
On Fri, Mar 09, 2012 at 02:38:48PM -0500, Jonathan M Davis wrote: > On Friday, March 09, 2012 11:29:43 H. S. Teoh wrote: > > Hmph. Well, then that defeats the purpose of checking contracts, > > because checking contracts is only justifiable if it's complex > > enough, which means that it's liable t

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 11:29:43 H. S. Teoh wrote: > Hmph. Well, then that defeats the purpose of checking contracts, because > checking contracts is only justifiable if it's complex enough, which > means that it's liable to involve things like dtors and scope > statements. It's silly to want to

Re: Assert and the optional Message

2012-03-09 Thread H. S. Teoh
On Fri, Mar 09, 2012 at 01:37:38PM -0500, Jonathan M Davis wrote: > On Friday, March 09, 2012 09:59:42 H. S. Teoh wrote: [...] > > This opens up the question of, what's the *recommended* way of > > writing unittests that check for these sorts of stuff? > > > > For example, I believe in being thoro

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 19:23:20 Timon Gehr wrote: > On 03/09/2012 05:56 PM, Jonathan M Davis wrote: > > The current implementation may not skip them, but if so, that might > > actually be a bug. Errors are not intended to be recoverable, so you > > can't rely on them hitting finally blocks, scop

Re: Assert and the optional Message

2012-03-09 Thread Chris Pons
You are right, there is also an option to "Pause when program finishes". I never saw it until now. Thank you for all the replies. On Friday, 9 March 2012 at 13:39:02 UTC, Dmitry Olshansky wrote: On 09.03.2012 11:42, Chris Pons wrote: I am new to D and have been playing around with Assert. I f

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 09:59:42 H. S. Teoh wrote: > On Fri, Mar 09, 2012 at 08:56:10AM -0800, Jonathan M Davis wrote: > > On Friday, March 09, 2012 16:07:10 Timon Gehr wrote: > > > On 03/09/2012 03:24 PM, Jacob Carlborg wrote: > [...] > > > > > I still want it to call finally blocks, scope stat

Re: Assert and the optional Message

2012-03-09 Thread H. S. Teoh
On Fri, Mar 09, 2012 at 07:23:20PM +0100, Timon Gehr wrote: > On 03/09/2012 05:56 PM, Jonathan M Davis wrote: [...] > >It was never intended that AssertError or any other Error be > >particularly catchable, but it's also true that D is a systems > >programming language, so it'll let you do stuff wh

Re: Assert and the optional Message

2012-03-09 Thread Timon Gehr
On 03/09/2012 05:56 PM, Jonathan M Davis wrote: The current implementation may not skip them, but if so, that might actually be a bug. Errors are not intended to be recoverable, so you can't rely on them hitting finally blocks, scope statements, or destructors. They may very well do so at present

Re: Assert and the optional Message

2012-03-09 Thread H. S. Teoh
On Fri, Mar 09, 2012 at 08:56:10AM -0800, Jonathan M Davis wrote: > On Friday, March 09, 2012 16:07:10 Timon Gehr wrote: > > On 03/09/2012 03:24 PM, Jacob Carlborg wrote: [...] > > > I still want it to call finally blocks, scope statements, and > > > destructors. > > > > I have never actually obse

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 16:07:10 Timon Gehr wrote: > On 03/09/2012 03:24 PM, Jacob Carlborg wrote: > > On 2012-03-09 15:13, Timon Gehr wrote: > >> On 03/09/2012 01:20 PM, Jacob Carlborg wrote: > >>> On 2012-03-09 12:12, Jonathan M Davis wrote: > On Friday, March 09, 2012 11:03:38 Regan Heath

Re: Assert and the optional Message

2012-03-09 Thread Timon Gehr
On 03/09/2012 03:24 PM, Jacob Carlborg wrote: On 2012-03-09 15:13, Timon Gehr wrote: On 03/09/2012 01:20 PM, Jacob Carlborg wrote: On 2012-03-09 12:12, Jonathan M Davis wrote: On Friday, March 09, 2012 11:03:38 Regan Heath wrote: On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: Any idea

Re: Assert and the optional Message

2012-03-09 Thread Jacob Carlborg
On 2012-03-09 15:13, Timon Gehr wrote: On 03/09/2012 01:20 PM, Jacob Carlborg wrote: On 2012-03-09 12:12, Jonathan M Davis wrote: On Friday, March 09, 2012 11:03:38 Regan Heath wrote: On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: Any idea why, system("PAUSE") does work? As Jonathan

Re: Assert and the optional Message

2012-03-09 Thread Timon Gehr
On 03/09/2012 01:20 PM, Jacob Carlborg wrote: On 2012-03-09 12:12, Jonathan M Davis wrote: On Friday, March 09, 2012 11:03:38 Regan Heath wrote: On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: Any idea why, system("PAUSE") does work? As Jonathan says, assert throws AssertError... which

Re: Assert and the optional Message

2012-03-09 Thread Dmitry Olshansky
On 09.03.2012 11:42, Chris Pons wrote: I am new to D and have been playing around with Assert. I figured that using a message with assert would be very helpful, but unfortunately when the message is printed to the console, the console closes and my program ends. Is there any way to get a more pe

Re: Assert and the optional Message

2012-03-09 Thread Jacob Carlborg
On 2012-03-09 12:12, Jonathan M Davis wrote: On Friday, March 09, 2012 11:03:38 Regan Heath wrote: On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: Any idea why, system("PAUSE") does work? As Jonathan says, assert throws AssertError... which means, if you wanted to you could catch it, f

Re: Assert and the optional Message

2012-03-09 Thread Regan Heath
On Fri, 09 Mar 2012 11:12:44 -, Jonathan M Davis wrote: On Friday, March 09, 2012 11:03:38 Regan Heath wrote: On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: > Any idea why, system("PAUSE") does work? As Jonathan says, assert throws AssertError... which means, if you wanted to y

Re: Assert and the optional Message

2012-03-09 Thread Mike Parker
On 3/9/2012 4:42 PM, Chris Pons wrote: I am new to D and have been playing around with Assert. I figured that using a message with assert would be very helpful, but unfortunately when the message is printed to the console, the console closes and my program ends. Is there any way to get a more pe

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 11:03:38 Regan Heath wrote: > On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: > > Any idea why, system("PAUSE") does work? > > As Jonathan says, assert throws AssertError... which means, if you wanted > to you could catch it, for example... > > module asserting; >

Re: Assert and the optional Message

2012-03-09 Thread Regan Heath
On Fri, 09 Mar 2012 08:20:33 -, Chris Pons wrote: Any idea why, system("PAUSE") does work? As Jonathan says, assert throws AssertError... which means, if you wanted to you could catch it, for example... module asserting; import std.stdio; import core.exception; debug { import st

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 10:55:10 Mars wrote: > On Friday, 9 March 2012 at 07:55:56 UTC, Jonathan M Davis wrote: > > What you should almost certainly be doing is changing Visual > > Studio's settings > > so that it doesn't close the Window when the program exits. I > > know that it's > > possible.

Re: Assert and the optional Message

2012-03-09 Thread Mars
On Friday, 9 March 2012 at 07:55:56 UTC, Jonathan M Davis wrote: What you should almost certainly be doing is changing Visual Studio's settings so that it doesn't close the Window when the program exits. I know that it's possible. I've done it, but I rarely use Windows, and I don't remember wha

Re: Assert and the optional Message

2012-03-09 Thread Jonathan M Davis
On Friday, March 09, 2012 09:20:33 Chris Pons wrote: > Any idea why, system("PAUSE") does work? Because that line never gets run. A failed assertion throws an AssertError which skips everything until it gets handled by the runtime after it exits main. So, if you have assert(condition); system("

Re: Assert and the optional Message

2012-03-09 Thread Chris Pons
Any idea why, system("PAUSE") does work?

Re: Assert and the optional Message

2012-03-09 Thread Chris Pons
Ok, thank you for the advice. I will look into it.

Re: Assert and the optional Message

2012-03-08 Thread Jonathan M Davis
On Friday, March 09, 2012 08:42:25 Chris Pons wrote: > I am new to D and have been playing around with Assert. I figured > that using a message with assert would be very helpful, but > unfortunately when the message is printed to the console, the > console closes and my program ends. > > Is there