Skip to content

feat: add mock_file_check_guard() for scope-based cleanup#96

Merged
atoomic merged 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/add-mock-file-check-guard
Apr 26, 2026
Merged

feat: add mock_file_check_guard() for scope-based cleanup#96
atoomic merged 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/add-mock-file-check-guard

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

What

Adds mock_file_check_guard($check, \&sub) — like mock_file_check but returns a guard object that auto-unmocks on scope exit.

Why

Tests using mock_file_check must manually call unmock_file_check in cleanup, which is error-prone — especially when tests die. The guard pattern ensures cleanup even on early exit, improving test isolation.

How

  • Inline Overload::FileCheck::Guard package with DESTROY-based cleanup
  • cancel() method to opt out of auto-unmock
  • Guard handles double-destroy safely (no-op on second call)
  • eval in DESTROY to never propagate exceptions

Testing

  • 14 new tests in t/guard.t covering: basic scope cleanup, cancel, double-destroy, die-in-eval, dash-less check names, FALLBACK_TO_REAL_OP
  • Full suite passes after rebase onto main

Rebased from atoomic#3 (was targeting master on the old repo)

🤖 Generated with Claude Code

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>
Comment thread lib/Overload/FileCheck.pm
@atoomic atoomic marked this pull request as ready for review April 26, 2026 07:18
@atoomic atoomic merged commit f320fd5 into cpan-authors:main Apr 26, 2026
21 checks passed
@Koan-Bot Koan-Bot deleted the koan.atoomic/add-mock-file-check-guard branch April 27, 2026 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants