June 06, 2023
On 06/06/2023 2:25 AM, Mike Parker wrote:
> On Monday, 5 June 2023 at 14:16:39 UTC, ryuukk_ wrote:
> 
>> In my book this is broken and needs to be fixed, as a user i don't care about under the hood things, it's a you problem, user should be able to unit test
> 
> The docs say it should work:
> 
> https://dlang.org/spec/betterc.html#unittests
> 
> So either the docs are wrong or the implementation is bugged. If there's no issue yet, could you please file one?

Yes that is what I recommended earlier in the thread. But automatic running requires druntime.
June 05, 2023
On Monday, 5 June 2023 at 14:29:35 UTC, Richard (Rikki) Andrew Cattermole wrote:
> On 06/06/2023 2:25 AM, Mike Parker wrote:
>> On Monday, 5 June 2023 at 14:16:39 UTC, ryuukk_ wrote:
>> 
>>> In my book this is broken and needs to be fixed, as a user i don't care about under the hood things, it's a you problem, user should be able to unit test
>> 
>> The docs say it should work:
>> 
>> https://dlang.org/spec/betterc.html#unittests
>> 
>> So either the docs are wrong or the implementation is bugged. If there's no issue yet, could you please file one?
>
> Yes that is what I recommended earlier in the thread. But automatic running requires druntime.

Ah, I see now. It's working as expected then.
June 05, 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?

June 05, 2023

On Monday, 5 June 2023 at 18:14:31 UTC, DLearner wrote:

>

On Monday, 5 June 2023 at 14:25:33 UTC, Mike Parker wrote:

>

[...]

Thank you for the link, can confirm that:

int foo() {

[...]

It's not so easy to deal automatically in case of multiple modules

June 06, 2023

On Monday, 5 June 2023 at 18:22:45 UTC, Ernesto Castellotti wrote:
[...]

>

It's not so easy to deal automatically in case of multiple modules

multiple modules

The following code, in a batch (.bat) file, works for me:

@echo off
:loop
if [%1]==[] goto loopexit
type .\%1.d > .\__temp_%1.d
echo extern(C) void main() { static foreach(u; __traits(getUnitTests, __traits(parent, main)))   u();} >> .\__temp_%1.d
dmd -betterC -unittest -i -run .\__temp_%1.d
del .\__temp_%1.d
shift
goto loop
:loopexit
1 2
Next ›   Last »