Contract programming and unit tests
D has built-in support for contract programming and unit testing. D's contract programming implementation consists of two loosely related features: invariants and function contracts. None of these features would be as useful as they are without the assert expression.
Before we dig into the details, I'd like to point out that all of these features, except unit tests, are enabled by default. Passing -release
to the compiler will disable asserts, function contracts, and invariants. Typically, you'll want to leave that flag out during development and use it when you are ready to start testing the release version.
Assert contracts
The assert
expression evaluates a Boolean expression and throws an AssertError
when the ...
Get Learning D now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.