Skip to content

feat: add mock_virtual_filesystem() for declarative file mocking#104

Draft
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/feat-mock-virtual-filesystem
Draft

feat: add mock_virtual_filesystem() for declarative file mocking#104
Koan-Bot wants to merge 1 commit intocpan-authors:mainfrom
Koan-Bot:koan.atoomic/feat-mock-virtual-filesystem

Conversation

@Koan-Bot
Copy link
Copy Markdown
Contributor

@Koan-Bot Koan-Bot commented May 6, 2026

What

Adds mock_virtual_filesystem() — a convenience function that wraps the most common mock_all_from_stat usage pattern into a single declarative call with automatic guard cleanup. Also exports get_basetime().

Why

The dominant usage pattern for mock_all_from_stat is a hash lookup from paths to stat results, wrapped in a cleanup block. Every test file reimplements the same boilerplate: build a hash, write a callback with exists + FALLBACK_TO_REAL_OP, remember to unmock. This function eliminates that repetition.

get_basetime() was defined in XS but not importable — users mocking -M/-C/-A had to use the fully-qualified Overload::FileCheck::get_basetime().

How

mock_virtual_filesystem(%path_to_stat) calls mock_all_from_stat with a generated lookup callback and returns a Guard that unmocks all ops (including stat/lstat) on scope exit. Reuses existing Overload::FileCheck::Guard class.

Testing

  • New test file t/mock-virtual-filesystem.t covers: existence checks, file type checks, size, stacked ops, real filesystem fallback, guard cleanup, guard cancel, nested guards, and stat data verification.
  • get_basetime export verified against $^T.
  • Full test suite passes.

🤖 Generated with Claude Code


Quality Report

Changes: 2 files changed, 171 insertions(+), 1 deletion(-)

Code scan: clean

Tests: passed (0 Tests)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

Wraps the most common mock_all_from_stat usage pattern — a hash lookup
from file paths to stat results — into a single function that returns a
scope guard for automatic cleanup.

Also exports get_basetime() (previously XS-only, not importable) for
users who need to construct timestamps relative to $^T for -M/-C/-A mocks.

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