fff
fff copied to clipboard
Implement FFF_RESET_CALLED_FAKES macro
Thank you for your contribution.
Before submitting this PR, please make sure:
- [x] Your code builds clean without any errors or warnings
- [x] You are not breaking consistency
- [x] You have added unit tests
- [x] All tests and other checks pass
Hi! long time user of fff but one thing always annoyed me:
Why do we have to call RESET_FAKE()
for each fake function individually? Wouldn't it be nice to have a reset all fakes macro?
Personally I don't see a reason why not. So I went ahead and implemented a crude solution I thought I'd share.
This PR adds a FFF_RESET_CALLED_FAKES()
macro which, similar to FFF_RESET_HISTORY()
can be placed in the global setup section of your unit-test. Internally we maintain a reset_list
inside the global fff
struct. Once a fake function is called, the respective _reset
function pointer is placed in this list. FFF_RESET_CALLED_FAKES
simply invokes every function inside fff.reset_list
.
Best regards
PS: FFF is awesome!
:white_check_mark: Build fff 83-appveyor completed (commit https://github.com/meekrosoft/fff/commit/3b92adddab by @ChiefGokhlayeh)
:white_check_mark: Build fff 84-appveyor completed (commit https://github.com/meekrosoft/fff/commit/7dd95b55b5 by @ChiefGokhlayeh)
This is brilliant! This always annoyed me as well. Why isn't this merged yet? Now, is there any reason the code for FFF_RESET_CALLED_FAKES
should not be called automatically from FFF_RESET_HISTORY
? I never had the need to reset individual fakes in any of my projects.
@rubiot,
Thought about that, but as far as I remember FFF_RESET_HISTORY
strictly resets the global call history (fff.call_history_idx = 0
) and is not tied to any fakes. I agree, it makes more sense to merge these two together and have a single FFF_RESET_ALL
(or simply FFF_RESET
?).
Regarding why this hasn't been merged yet, I don't know. To my own discredit, I didn't follow up on this PR very diligently.
Rebased source branch to fix merge conflicts.