Skip to content

fix: add strict mode guard to mock_all()#72

Draft
Koan-Bot wants to merge 3 commits intogeofffranks:masterfrom
atoomic:koan.atoomic/strict-guard-mock-all
Draft

fix: add strict mode guard to mock_all()#72
Koan-Bot wants to merge 3 commits intogeofffranks:masterfrom
atoomic:koan.atoomic/strict-guard-mock-all

Conversation

@Koan-Bot
Copy link

@Koan-Bot Koan-Bot commented Mar 7, 2026

What

Add _strict_mode() check to mock_all() so it croaks in strict mode, consistent with mock() and noop().

Why

mock_all() calls _mock() directly, bypassing the strict mode guard that mock() and noop() both enforce. This creates a safety hole where users in strict mode can accidentally use mock_all() without getting the expected error.

How

One-line croak guard at the top of mock_all(), matching the pattern used by mock() and noop(). Test added to t/mock_strict.t.

Testing

  • All 124 tests pass
  • New test verifies mock_all() croaks with appropriate message in strict mode

Note: This builds on the mock_all() feature from #71.

🤖 Generated with Claude Code

Koan-Bot and others added 3 commits March 7, 2026 10:17
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>
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.

1 participant