www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8765] New: assert should print the source code for the condition when no message argument present

reply d-bugmail puremagic.com writes:
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



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: -------
Oct 05 2012
next sibling parent d-bugmail puremagic.com writes:
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



16:33:23 PDT ---

 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: -------
Oct 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8765




16:44:41 PDT ---


 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: -------
Oct 20 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8765


bearophile_hugs eml.cc changed:

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





 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: -------
Oct 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



14:07:48 PDT ---


 
 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: -------
Oct 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8765




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: -------
Oct 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Oct 22 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8765


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

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



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: -------
Jan 01 2013