When doing test driven development, I often find it useful to scaffold functions that intentionally fail testing, then fill in the details of the functions to achieve a "pass" for the unit tests.
In D, is there a standard way to scaffold an empty function, or otherwise approach this aspect of test-driven development?
For example, coming in the C# world NotImplementedException
would be one way to achieve this:
int Foo(int x, int y) {
throw new NotImplementedException();
}
Being new to D, I can see that there is a base Exception
class, that all exceptions seem to inherit from. But is there a better way to scaffold new functions in a TDD D environment?
Generally I use assert(false)
. And I have seen this used by others as well. You can also add a message assert (false, "Unimplemented")
D does not have as many types of exceptions as C#. Unless the exception would have reason to be caught in a try-catch it is merely a message for a human (coder) so there is no real reason to have code representation for an exception type.
You could also just throw a generic exception but using assert is more convenient.
(the doc for assert https://dlang.org/spec/contracts.html)