Tutorial by Examples

Tests are an excellent way to ensure stable, bug-free applications. They serve as an interactive documentation and allow to modify code without fear to break functionality. D provides a convenient and native syntax for unittest block as part of the D language. Anywhere in a D module unittest blocks ...
If -unittest flag is passed to the D compiler, it will run all unittest blocks. Often it is useful to let the compiler generate a stubbed main function. Using the compile & run wrapper rdmd, testing your D program gets as easy as: rdmd -main -unittest yourcode.d Of course you can also split ...
For templated code it is often useful to verify that for function attributes (e.g. @nogc are inferred correctly. To ensure this for a specific test and thus type the entire unittest can be annotated @safe @nogc pure nothrow unittest { import std.math; assert(exp(0) == 1); assert(l...

Page 1 of 1