unittest under betterC

DLearner bmqazwsx123 at gmail.com
Mon Jun 5 18:14:31 UTC 2023


On Monday, 5 June 2023 at 14:25:33 UTC, Mike Parker wrote:
> [...]
>
> The docs say it should work:
>
> https://dlang.org/spec/betterc.html#unittests
>
> [...]

Thank you for the link, can confirm that:
```
int foo() {

    return 4;
}

unittest {

    assert(foo() != 4, "!= Assert triggered.");
    assert(foo() == 4, "== Assert triggered.");
}

extern(C) void main()
{
     static foreach(u; __traits(getUnitTests, __traits(parent, 
main)))
         u();
}
```
run via:
```
dmd -betterC -unittest -i -run foo2
```
works as expected.


However, as a suggestion to create a consistent experience with 
'Full D',
should not the combination of '-main' and '-betterC' cause the 
generation
and attachment of the boilerplate code
```
extern(C) void main()
{
     static foreach(u; __traits(getUnitTests, __traits(parent, 
main)))
         u();
}
```
to a source file containing just the original function and it's 
unittests?



More information about the Digitalmars-d-learn mailing list