Attempt to implement mocking of shared methods/shared objects.#12
Attempt to implement mocking of shared methods/shared objects.#12chris0210 wants to merge 7 commits intonomad-software:masterfrom
Conversation
|
It looks interesting, i'll take a closer look this weekend (when i get more time) and in the meantime i'll have a think about the general design. I wonder if we could do it more elegantly? I noticed you've use token strings |
|
Using token strings wherever there are string literals containing source code is a very good idea. My IDE (Eclipse + DDT) as well as GitHub keeps highlighting the source code even within these string literals. The only problem I have encountered with these literals is the following: template MyMixin(string someVariable) {
immutable char[] MyMixin = q{
if (someCondition) {
} ~ someVariable ~ q{
}
};
}This won't compile because the closing bracket template MyMixin(string someVariable) {
import std.array : replace;
immutable char[] MyMixin = q{
if (someCondition) {
%someVariable%
}
}.replace("%someVariable%", someVariable);
}Using |
|
I'll have a closer look to the source code and see, if I have any idea to improve the design.... |
|
I have found a clean solution to determine if a type is shared. Removed the dirty hack . |
Nice! I wonder if there is a way of |
|
How about a second method |
…er to create a shared mock.
DMD in conjunction with valgrind.
Here is my attempt to implement mocking for
sharedmethods. The major problem here is that you can only callsharedmethods onsharedobjects. The current implementation ofgetMock()always returns a notsharedobject - therefore nosharedmethod could be called.It was not possible to do things like that:
The solution I present here enables mocking of
sharedobject by using theMockablemixin in the following way:By specifying the
sharedqualifier thegetMock()method will return a shared object. All methods of the mock - likemockMethod()orassertMethodCalls-will by qualified assharedand so you can call them.The only two problems here are:
What's your opinion on this solution?