How to get call stack for InvalidMemoryOperationError while doing unittest?

apz28 home at home.com
Wed Jan 13 18:22:21 UTC 2021


core.exception.InvalidMemoryOperationError at src\core\exception.d(647): Invalid memory operation

reference D runtime unittest executor codes
         try
         {
             fp();
             ++results.passed;
         }
         catch ( Throwable e )
         {
             import core.stdc.stdio;
             printf("%.*s(%llu): [unittest] %.*s\n",
                 cast(int) e.file.length, e.file.ptr, cast(ulong) 
e.line,
                 cast(int) e.message.length, e.message.ptr);

             if ( typeid(e) == typeid(AssertError) )
             {
                 // Crude heuristic to figure whether the 
assertion originates in
                 // the unittested module. TODO: improve.
                 auto moduleName = m.name;
                 if (moduleName.length && e.file.length > 
moduleName.length
                     && e.file[0 .. moduleName.length] == 
moduleName)
                 {
                     // Exception originates in the same module, 
don't print
                     // the stack trace.
                     // TODO: omit stack trace only if assert was 
thrown
                     // directly by the unittest.
                     continue;
                 }
             }
             // TODO: perhaps indent all of this stuff.
             _d_print_throwable(e);
         }



More information about the Digitalmars-d-learn mailing list