Running unittests of a module with -betterC

mipri mipri at minimaltype.com
Tue Oct 29 08:45:15 UTC 2019


On Monday, 28 October 2019 at 08:51:02 UTC, Daniel Kozak wrote:
> On Mon, Oct 28, 2019 at 9:40 AM Per Nordlöw via 
> Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:
>>
>> Is it possible to run the unittests of a module with -betterC 
>> like
>>
>>      dmd -D -g -main -unittest -betterC f.d
>>
>> ?
>>
>> This currently errors as
>>
>> /usr/include/dmd/druntime/import/core/internal/entrypoint.d:34: error: undefined reference to '_d_run_main'
>>
>> for an empty file f.d
>
> AFAIK no,
>
> https://dlang.org/spec/betterc.html#unittests

-unittest sets the 'unittest' version identifier. So this works:

   unittest {
      assert(0);
   }

   version(unittest) {
       extern(C) void main() {
           static foreach(u; __traits(getUnitTests, 
__traits(parent, main)))
               u();
       }
   }

dmd -betterC -unittest -run module.d


More information about the Digitalmars-d-learn mailing list