fix: add strict mode guard to mock_all()#72
Draft
Koan-Bot wants to merge 3 commits intogeofffranks:masterfrom
Draft
fix: add strict mode guard to mock_all()#72Koan-Bot wants to merge 3 commits intogeofffranks:masterfrom
Koan-Bot wants to merge 3 commits intogeofffranks:masterfrom
Conversation
Addresses GH geofffranks#30. mock_all() mocks every subroutine in the target package (except import) with a handler that dies on call, making it easy to catch unexpected calls during testing. Supports noop=>1 for silent no-ops and handler=>\&coderef for custom behavior. Already-mocked subs are skipped. Returns $self for chaining. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
noop() was passing 1 to _mock(), which created sub { 1 } — a sub
that returns 1. This was inconsistent with mock_all(noop => 1) which
installs sub {} — a true no-op returning undef.
A no-op sub should return nothing. Align noop() to use sub {} by
passing undef to _mock(), matching mock_all(noop => 1) behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mock_all() was calling _mock() directly, bypassing the _strict_mode() check that mock() and noop() both enforce. This allowed mock_all() to silently work in strict mode, defeating its purpose. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Add
_strict_mode()check tomock_all()so it croaks in strict mode, consistent withmock()andnoop().Why
mock_all()calls_mock()directly, bypassing the strict mode guard thatmock()andnoop()both enforce. This creates a safety hole where users in strict mode can accidentally usemock_all()without getting the expected error.How
One-line croak guard at the top of
mock_all(), matching the pattern used bymock()andnoop(). Test added tot/mock_strict.t.Testing
mock_all()croaks with appropriate message in strict mode🤖 Generated with Claude Code