Functions with default parameters not mockable
Closed this issue · 1 comments
belka-ew commented
static class Dependency
{
void withDefaultParameter(string = null)
{
}
}
auto mock = Mocker().mock!Dependency.expect.withDefaultParameter();
belka-ew commented
Overridden methods may skip default parameters, i.e. this is valid:
class A
{
void foo(string phrase = "simplex sigillum veri")
{
}
}
class B : A
{
override void foo(string phrase)
{
}
}
phrase
is "simplex sigillum veri" if B.foo
is called without any arguments. Though this behaviour is buggy, for example dmd fails to compile the code if it can determine statically, that .foo
is called on B
, so (new B).foo()
fails:
tests/mocked/tests/mocking.d(424,16): Error: function mocked.tests.mocking.B.foo(string phrase) is not callable using argument types ()
tests/mocked/tests/mocking.d(424,16): missing argument for parameter #1: string phrase
Anyway it explains why the mocked class works, but the mock builder (that doesn't inherit from the base class) does not.