-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Colliding MockingContext ids when used in multiple translation units because of __COUNTER__ #294
Comments
Hadn't seen that one before. A quick fix to fakeit could be using the filename, line number with the counter .. not sure how much work. Would need to make the id a string instead of an int. Note sure of proper fix, or a solution to avoid the whole problem in the first place. |
Combining counter, line number and filename would still produce multiple entries for the same stub in the invocationHandlerCollection. I am not sure if there are any pitfalls doing this for properly handling different flavors of stubbing (Return, AlwaysReturn, ...) and verification (AtLeast, Exactly, ...) |
String literals cannot be used as non type template parameter, there are workarounds but only in C++20 as far as I know. We could create a hash from filename +
I haven't looked too deep into this part of the code but I don't understand what you mean. When the method I there something I don't understand ? Could you detail a bit more what kind of issues an ID generated from the filename would cause ? |
Actually, you are most likely right that it's not a problem. Multiple calls to the same stub do indeed already generate multiple ids. I don't have the knowledge to determine if generating an ID from the filename could lead to other issues. If it's a possible fix, it should definitely be explored as a solution. |
I am about to submit a pull request for this one. I got working code locally. The id is hashed from combining I need to get the length of the string literal to compute its hash. What are the requirements regarding the support of different versions of the standard? |
Every features should work on C++11 and beyond, but you can have some optimizations or compile-time checks that are only on newer versions. For example for the |
If you don't want to manually write a loop, something like that also work: template <int Size>
constexpr int hash(const char (&filename)[Size], int counter)
{
return Size + counter;
}
int main()
{
hash(__FILE__, __COUNTER__);
return 0;
} |
MyInterface.h
MyMock.h
MyMock.cpp
MyMethodStubs.h
MyMethodStubs.cpp
MyTest.cpp
I am using Visual Studio 2017.
The above code snippet is a simplified demonstration of the problem. It is a lot more difficult to pinpoint in a real test setup.
I cannot propose a solution since I don't have a deep understanding of fakeit internal wizardry.
This is a major show stopper to better architecture a testing setup, especially considering the bloating of obj files by fakeit symbols rapidly breaking the maximum number of sections allowed, requiring to either split the source files in multiple translation units, or using the /bigobj switch.
The text was updated successfully, but these errors were encountered: