3 ms·
D has support for nested functions: I love nested functions. It's good when you need a quick local function, and don't want to expose it to the rest of the co
by blackrock 8y ago
D has support for nested functions:
I love nested functions. It's good when you need a quick local function, and don't want to expose it to the rest of the code base.
But, how do you systematically unit test nested functions?
- coherentpony 8y ago> But, how do you systematically unit test nested functions? You expose it. If you want to test a local nested function, you test the enclosing function.
- maxxxxx 8y ago"But, how do you systematically unit test nested functions?" You don't. You test the enclosing function. The nested function is just an implementation detail like any other line of code in that function.
- EpicEng 8y agoWhy would you need to? If you unit test the top level function then you're implicitly testing anything it does, e.g., use of the local function.
- CyberShadow 8y ago> But, how do you systematically unit test nested functions? Why, with nested unittests, of course! Just put them in a nested type first: void main() { static int nested(int x) { return x * 2; } struct Test { unittest { assert(nested(2) == 4); } } } Well, OK, that's more of a hack than a feature, and you obviously can't test non-static nested functions (as there'd be no way to give values to the outer function's frame variables). But you asked :)
- deleted 8y ago[deleted]