digitalmars.D - Compiler generated assertion error message
- safety0ff (27/27) Jun 19 2014 A year and a half ago Andrej Mitrovic created a DMD pull ([1])
- Dicebot (8/8) Jun 19 2014 On a related topic:
- Jacob Carlborg (7/15) Jun 20 2014 There's an assert handler in druntime [1], but that expects the
- Dicebot (7/19) Jun 20 2014 Yes I have already found it. There is also
- Walter Bright (3/6) Jun 19 2014 It appears to do more than that, such as always adding the assertion exp...
A year and a half ago Andrej Mitrovic created a DMD pull ([1]) which implements dmd adding a prefix string containing the failing assertion to the assertion error's "msg" field. necessary phobos unit test modifications in [5]. His patch should now pass the tests. An example of how this patch improves the generated "msg" field is given in [5], (note that it is generated by the code from [6].) It is worth noting that the bitfield's assertion message was recently modified in [6] to be more informative, perhaps with this patch, that change would not have been as necessary. It would be nice to have some feedback about this change. Personally, I found it more useful than I had first expected. I had forgotten that my local DMD was patched until I received a failed assertion message which gave me all the context I needed within the assertion message. I recommend giving it a try. [1] https://github.com/D-Programming-Language/dmd/pull/1426 [2] https://github.com/D-Programming-Language/dmd/pull/3624 [3] https://github.com/D-Programming-Language/dmd/pull/3622 [4] https://github.com/D-Programming-Language/dmd/pull/3669 [5] https://github.com/D-Programming-Language/phobos/pull/2252/files [6] https://github.com/D-Programming-Language/phobos/pull/2113/files
Jun 19 2014
On a related topic: Feature like this is extremely convenient for unit tests. However using assertions in unit test blocks does not fit well with any custom test runner that does not immediately terminate the application (because AssertionError is an Error). I'd personally love some way to get such formatted expression for any library function. What is the official stance on this?
Jun 19 2014
On 2014-06-19 19:52, Dicebot wrote:On a related topic: Feature like this is extremely convenient for unit tests. However using assertions in unit test blocks does not fit well with any custom test runner that does not immediately terminate the application (because AssertionError is an Error).There's an assert handler in druntime [1], but that expects the implementation to be nothrow, so you cannot throw an exception.I'd personally love some way to get such formatted expression for any library function. What is the official stance on this?[1] https://github.com/D-Programming-Language/druntime/blob/master/src/core/exception.d#L374 -- /Jacob Carlborg
Jun 20 2014
On Friday, 20 June 2014 at 20:04:32 UTC, Jacob Carlborg wrote:On 2014-06-19 19:52, Dicebot wrote:Yes I have already found it. There is also https://github.com/D-Programming-Language/druntime/blob/master/src/c re/exception.d#L447 but I don't see any way to replace it with user handler. Anyway some sort of library solution (probably via __traits) is much more desired because that will be applicable also to things like std.exception.enforce and alike.On a related topic: Feature like this is extremely convenient for unit tests. However using assertions in unit test blocks does not fit well with any custom test runner that does not immediately terminate the application (because AssertionError is an Error).There's an assert handler in druntime [1], but that expects the implementation to be nothrow, so you cannot throw an exception.
Jun 20 2014
On 6/19/2014 10:44 AM, safety0ff wrote:A year and a half ago Andrej Mitrovic created a DMD pull ([1]) which implements dmd adding a prefix string containing the failing assertion to the assertion error's "msg" field.It appears to do more than that, such as always adding the assertion expression to the output?
Jun 19 2014