[dmd-internals] changeset 455

Andrei Alexandrescu andrei at erdani.com
Fri Apr 30 07:43:10 PDT 2010


On 04/30/2010 07:25 AM, Steve Schveighoffer wrote:
> This is not important.  A library to print out the last unit test failure is really easy.  printf is not required, write will be sufficient.  All it needs is a little compiler help.
>
> At the beginning of every unit test, the compiler should insert the following code:
>
> unittest {    __unittestFile = __FILE__;    __unittestLine = __LINE__;
>      ...
> }
>
> Then, during unittest, the runtime inserts a signal handler for SEGV:
>
> __gshared string __unittestFile = "";
> __gshared uint __unittestLine = 0;
> __gshared string msg = "unittest SEGV: ";
>
> extern(C) void unittestSegv(int sig)
> {
>     char[11] lineno;
>     int linenostart = 0;
>     do
>     {
>        lineno[$-1-linenolength] = '0' + __unittestLine  % 10;
>        __unittestLine /= 10;
>        --linenostart;
>     } while(__unittestLine>  0);
>
>     write(2, msg.ptr, msg.length);
>     write(2, __unittestFile.ptr, __unittestFile.length);
>     write(2, "@", 1);
>     write(2, lineno.ptr + linenostart, lineno.length - linenostart);
>     write(2, "\n", 1);
>     exit(1);
> }

Walter, if this code does work, please do insert it in the compiler. 
Actually Steve, please bugzillize this so it doesn't get forgotten.

It's an important matter.


Andrei


More information about the dmd-internals mailing list