Thread overview
[Issue 8765] New: assert should print the source code for the condition when no message argument present
Oct 06, 2012
Val Markovic
Oct 20, 2012
Andrej Mitrovic
Oct 20, 2012
Andrej Mitrovic
Oct 21, 2012
Andrej Mitrovic
Oct 22, 2012
Val Markovic
Oct 23, 2012
Andrej Mitrovic
Jan 01, 2013
Andrej Mitrovic
October 06, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765

           Summary: assert should print the source code for the condition
                    when no message argument present
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: val@markovic.io


--- Comment #0 from Val Markovic <val@markovic.io> 2012-10-05 19:59:52 PDT ---
I'd love to see the following:

assert(5 == 4);

print out the actual source code of the condition on failure, that is "core.exception.AssertError@foo.d(123): 5 == 4". This should happen when there is no user-defined message (and maybe _in addition to_ the provided message). Currently I just get "unittest failure" instead of the condition source, which is useless.

This would make it far, far easier to track down which assert failed without having to actually go look at the line number in the file. Also, this is what most unit-testing libraries for other languages do already, like for example GoogleTest for C++ etc.

Since assert() is not a function but an expression in the language, this should
not be impossible to implement, should it? GoogleTest does it with macros, but
(thank God) we don't have those in D.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-20 16:33:23 PDT ---
(In reply to comment #0)
> assert(5 == 4);

When there is no message I can change this to:

core.exception.AssertError@test.d(5): assert(5 == 4)

Would this be ok with Walter? It's a 2 line change in the front-end.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 20, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765



--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-20 16:44:41 PDT ---
(In reply to comment #1)
> (In reply to comment #0)
> > assert(5 == 4);

Actually wait a minute, it already does this in 2.060. Is there some other example where this doesn't work?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from bearophile_hugs@eml.cc 2012-10-21 14:04:36 PDT ---
(In reply to comment #2)

> Actually wait a minute, it already does this in 2.060. Is there some other example where this doesn't work?

If I compile and run this program (Windows):


void main() {
    assert(5 == 4);
}


It gives me:

core.exception.AssertError@test(2): Assertion failure

Followed by a stack trace.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|nobody@puremagic.com        |andrej.mitrovich@gmail.com


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-21 14:07:48 PDT ---
(In reply to comment #3)
> (In reply to comment #2)
> 
> > Actually wait a minute, it already does this in 2.060. Is there some other example where this doesn't work?
> 
> If I compile and run this program (Windows):
> 
> 
> void main() {
>     assert(5 == 4);
> }
> 
> 
> It gives me:
> 
> core.exception.AssertError@test(2): Assertion failure
> 
> Followed by a stack trace.

OK will fix then.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 22, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765



--- Comment #5 from Val Markovic <val@markovic.io> 2012-10-21 20:52:19 PDT ---
Same as bearophile; the following program

void main() {
    assert(5 == 4);
}

gives me the following output:

core.exception.AssertError@test(2): Assertion failure
----------------
5   test                                0x000000010d95b05a _d_assertm + 38
6   test                                0x000000010d948df7 void
test.__assert(int) + 23
7   test                                0x000000010d948dda _Dmain + 14
8   test                                0x000000010d95b9ae extern (C) int
rt.dmain2.main(int, char**).void runMain() + 34
9   test                                0x000000010d95b365 extern (C) int
rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 45
10  test                                0x000000010d95b9f8 extern (C) int
rt.dmain2.main(int, char**).void runAll() + 56
11  test                                0x000000010d95b365 extern (C) int
rt.dmain2.main(int, char**).void tryExec(scope void delegate()) + 45
12  test                                0x000000010d95b2ef main + 235
13  libdyld.dylib                       0x00007fff89dae7e1 start + 0
14  ???                                 0x0000000000000001 0x0 + 1
----------------

My system/configuration is as follows:

OS: Mac OS X Mountain Lion 10.8
DMD64 v2.060
rdmd build 20120724
command: rdmd -unittest test.d

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8765


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tim.dolores@gmail.com


--- Comment #6 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-22 21:00:45 PDT ---
*** Issue 8058 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 01, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8765


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-01-01 15:20:16 PST ---
https://github.com/D-Programming-Language/dmd/pull/1426

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------