feat: add mock_file_check_guard() for scope-based cleanup#96
Merged
atoomic merged 1 commit intocpan-authors:mainfrom Apr 26, 2026
Merged
Conversation
Returns a guard object whose DESTROY calls unmock_file_check, enabling automatic mock cleanup on scope exit. Improves test isolation without changing the existing API. The guard also supports cancel() to keep the mock active beyond the scope, and handles double-destroy gracefully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
atoomic
reviewed
Apr 24, 2026
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.
What
Adds
mock_file_check_guard($check, \&sub)— likemock_file_checkbut returns a guard object that auto-unmocks on scope exit.Why
Tests using
mock_file_checkmust manually callunmock_file_checkin cleanup, which is error-prone — especially when tests die. The guard pattern ensures cleanup even on early exit, improving test isolation.How
Overload::FileCheck::Guardpackage with DESTROY-based cleanupcancel()method to opt out of auto-unmockevalin DESTROY to never propagate exceptionsTesting
t/guard.tcovering: basic scope cleanup, cancel, double-destroy, die-in-eval, dash-less check names, FALLBACK_TO_REAL_OP🤖 Generated with Claude Code