-
Notifications
You must be signed in to change notification settings - Fork 0
polymorphism: test mocking #12
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
Open
daixtrose
wants to merge
13
commits into
main
Choose a base branch
from
add-mocking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3caf553
reorganize test code, add mocking
daixtrose 97adcdc
refine test
daixtrose 98d23c6
fix typo in polymorphism/test/include/test_polymorphism/mocking.hpp
daixtrose a9b012f
Merge branch 'add-mocking' of https://github.com/daixtrose/cplusplus-…
daixtrose a66fd93
terse decision on return value
daixtrose 90f3cad
add commenst and reorder include directories
daixtrose 55d18a2
make the counter update thread-safe
daixtrose 2db7dd8
add docstrings and check empty string argument
daixtrose 21aa9e0
simplify source code paths
daixtrose cd5ebf7
refine comments on counter variable
daixtrose f85e5b5
add comments to method
daixtrose a3e0818
align comments
daixtrose 944493b
fix typo in include guard
daixtrose File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef POLYMORPHISM_MOCKING_HPP | ||
#define POLYMORPHISM_MOCKING_HPP | ||
|
||
#include <atomic> | ||
#include <cstddef> | ||
#include <list> | ||
#include <string> | ||
|
||
namespace mocking { | ||
|
||
struct Mock { | ||
std::list<std::string> collectedSetArguments; | ||
mutable std::atomic<std::size_t> numberOfCallsToCoolFeature { 0 }; | ||
daixtrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @brief Returns the last set value or a default value if none exists. | ||
* @note Thread-safe. Multiple concurrent calls are safe. | ||
* @return The last set string or "<default value>" if no strings were set | ||
*/ | ||
std::string coolFeature() const | ||
{ | ||
++numberOfCallsToCoolFeature; | ||
|
||
return collectedSetArguments.empty() | ||
? "<default value>" | ||
: collectedSetArguments.back(); | ||
} | ||
daixtrose marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @brief Stores a string value for later retrieval by coolFeature | ||
* @param s The string to store (must not be empty) | ||
* @throws std::invalid_argument if the string is empty | ||
*/ | ||
void set(std::string s) | ||
{ | ||
if (s.empty()) { | ||
throw std::invalid_argument("Empty strings are not allowed"); | ||
} | ||
collectedSetArguments.emplace_back(std::move(s)); | ||
} | ||
}; | ||
|
||
} // namespace mocking | ||
|
||
#endif // POLYMORPHISM_MOCKING_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <consume_class_that_adheres_to_concept.ipp> | ||
#include <test_polymorphism/mocking.hpp> | ||
|
||
#include <string> | ||
|
||
// explicit instantiation of consume() for Mock | ||
template std::string modern::consume<mocking::Mock>(mocking::Mock&); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Misspelled header guard found in
has_super_cool_features.hpp
The header guard spelling correction should be applied consistently across the codebase. Found remaining instances of "POYMORPHISM" in:
polymorphism/include/polymorphism/has_super_cool_features.hpp
#ifndef POYMORPHISM_HAS_SUPER_COOL_FEATURES_HPP
#define POYMORPHISM_HAS_SUPER_COOL_FEATURES_HPP
#endif // POYMORPHISM_HAS_SUPER_COOL_FEATURES_HPP
🔗 Analysis chain
Fixed header guard spelling.
The header guard spelling has been corrected from "POYMORPHISM" to "POLYMORPHISM", which improves code clarity and maintainability.
Let's verify there are no remaining instances of the misspelled header guard in the codebase:
Also applies to: 15-15
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 359