meekrosoft / fff

A testing micro framework for creating function test doubles
Other
761 stars 167 forks source link

Implement FFF_RESET_CALLED_FAKES macro #82

Open ChiefGokhlayeh opened 4 years ago

ChiefGokhlayeh commented 4 years ago

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!

AppVeyorBot commented 4 years ago

:white_check_mark: Build fff 83-appveyor completed (commit https://github.com/meekrosoft/fff/commit/3b92adddab by @ChiefGokhlayeh)

AppVeyorBot commented 4 years ago

:white_check_mark: Build fff 84-appveyor completed (commit https://github.com/meekrosoft/fff/commit/7dd95b55b5 by @ChiefGokhlayeh)

rubiot commented 3 years ago

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.

ChiefGokhlayeh commented 3 years ago

@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.

ChiefGokhlayeh commented 1 year ago

Rebased source branch to fix merge conflicts.