maint: Introduce ScopedContextChange for tests#4334
Merged
jjerphan merged 4 commits intoJun 24, 2026
Conversation
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
11 tasks
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz>
JohanMabille
approved these changes
Jun 24, 2026
Signed-off-by: Julien Jerphanion <git@jjerphan.xyz> Co-authored-by: Johan Mabille <johan.mabille@gmail.com>
Klaim
reviewed
Jun 24, 2026
Klaim
left a comment
Member
There was a problem hiding this comment.
I'm wondering if replacing all this by explicitly using a non-singleton context in these tests would be superior. I remember adding mambatests.hpp because I didn't have much choice but ideally
|
|
||
| ~ScopedContextChange() | ||
| { | ||
| for (auto it = m_restorers.rbegin(); it != m_restorers.rend(); ++it) |
Member
There was a problem hiding this comment.
Suggested change
| for (auto it = m_restorers.rbegin(); it != m_restorers.rend(); ++it) | |
| for (auto& restorer : [restorers_reversed](std::ranges::reverse_view(m_restorers))) |
| { | ||
| for (auto it = m_restorers.rbegin(); it != m_restorers.rend(); ++it) | ||
| { | ||
| (*it)(); |
Member
There was a problem hiding this comment.
Note that if any exception escape this call, abort will be called (because destructors are implicitly noexcept -> exception escaping calls terminate -> no terminate handler leads to abort())
Did you consider calling safe_invoke instead?
| private: | ||
|
|
||
| template <typename T, typename F> | ||
| void touch(T mamba::Context::* member, F&& mutator) |
Member
There was a problem hiding this comment.
Suggested change
| void touch(T mamba::Context::* member, F&& mutator) | |
| void touch(T& member, F&& mutator) |
Then capture the reference to member, with the field pointer being &member.
| m_restorers.push_back([&field, initial = field]() mutable | ||
| { field = std::move(initial); }); | ||
| } | ||
| mutator(field); |
Member
There was a problem hiding this comment.
Suggested change
| mutator(field); | |
| std::invoke(std::forward<F>(mutator), field); |
11 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Factor the pattern observed with
on_scope_exitunder one abstraction for consistent usages.See #4328 (comment).
Type of Change
Checklist
pre-commit run --alllocally in the source folder and confirmed that there are no linter errors.