D beginner's article about D's Metaprogramming and Testing

Steven Schveighoffer schveiguy at gmail.com
Tue Dec 19 23:56:59 UTC 2023


On Sunday, 17 December 2023 at 21:51:59 UTC, Renato wrote:
> Hi.
>
> I'm new to D and after playing around with D a bit I decided to 
> publish my thoughts about the language, focusing on its 
> metaprogramming and testing support.
>
> https://renato.athaydes.com/posts/testing-dlang
>

Excellent!

> I would be interested in feedback and corrections from more 
> experienced D enthusiasts :).

Some comments:

"static if is an if block that’s executed at compile-time… it 
doesn’t exist at runtime."

I see what you are going for, but the static if *block* is 
included or excluded based on what the compile-time condition is. 
The *condition* is executed at compile time, and if the condition 
is true, the block exists, if not, it doesn't exist. But in the 
case of your code, clearly the block exists at runtime (you are 
adding 2 runtime values together).

Regarding more descriptive unittests, try out the compiler 
parameter `-checkaction=context` to get more descriptive asserts: 
https://dlang.org/dmd-osx.html#switch-checkaction

there are also options to build your own unittest runner, see 
https://dlang.org/phobos/core_runtime.html#.Runtime.extendedModuleUnitTester

While this gives you only granularity of the module-level 
unittests, it allows you to do things like select only certain 
modules to run. And you do not need to build compile-time lists 
of all unittests yourself, the compiler links it all together for 
you (see the example in that function on what the default does).

-Steve


More information about the Digitalmars-d mailing list