Open andre2007 opened 4 years ago
Just out of curiosity: what's the use case for such assertions?
To express the intent, an alias
could help. Also, the error message could be improved that way:
alias assertInitial = actual => assertEqual(actual, typeof(actual).init, "not inital");
In my test I want to check whether the http service call was triggered. The http client is mocked for the test and while it is triggered a delegate is called. In the delegate I stored the Request structure and with assertInitial I want to check whether it was filled:
@Test void createBinding()
{
Request request;
requests.setNoContentResponse(HttpMethod.post, "/apps/myapp/bindings", (r) {
request = r;
});
cut.execute(["myapp", "--binding", "b1"]);
assertFalse(request == Request.init);
}
OK: this is a problem related to mocking. With hand-made mocks, there are several approaches:
bool called;
int callCount;
Request request;
Request[] requests;
(where you replace request = r;
with request ~= r;
)I don't like the idea of supporting "approach 3" with a rather special assertion.
So, I would suggest that you try the alias
proposal.
BTW: we abandoned hand-made mocks in favour of a mocking framework: https://github.com/funkwerk/dmocks.
I would like to test whether a struct is initial or not.
As workaround assertTrue, assertSame could be used but two new assertions
assertInitial
andassertNotInitial
would be more expressive.