[FR]: Make default mock behavior an option
- Dominant language
- C++
- Stars
- 39.5k
- Forks
- 10.9k
- Avg merge
- 6d 13h
- Merged PRs (30d)
- 1
Description
### Does the feature exist in the most recent commit?
No.
### Why do we need this feature?
I would like to have a default `NiceMock` behavior of the mock classes.
The default mock behavior that is set in `gmock.cc` is currently hard-coded, so it can only be changed by modifying the source. A comment in `gmock-nice-strict.h` states that "we will soon switch the default behavior of mocks to be nice". However, that comment is more than 13 years old, so I assume 'soon' will be 'never'. And I doubt that such a change would be accepted, because the default is a user preference.
### Describe the proposal.
My proposal is to make the default mock behavior a CMake option, so every user can choose the behavior without modifying the original source code.
Simple example to get an idea:
`CMakeLists.txt`:
```
set(DEFAULT_MOCK_BEHAVIOR "1" CACHE STRING "Default mock behavior.")
target_compile_definitions(gmock PUBLIC DEFAULT_MOCK_BEHAVIOR=${DEFAULT_MOCK_BEHAVIOR})
```
`gmock.cc`:
```
GMOCK_DEFINE_int32_(default_mock_behavior, DEFAULT_MOCK_BEHAVIOR,
```
### Is the feature specific to an operating system, compiler, or build system version?
No.
Contributor guide
Research direction
Start by inspecting CMakeLists.txt and gmock.cc, then read the default-behavior context in gmock-nice-strict.h. Trace how the current hard-coded default is passed into the mock configuration. Done means users can select the default mock behavior through a CMake option without modifying the source.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system, testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100