feat: add rename() override and autovivify for directory mocks (#135)#222
Open
Koan-Bot wants to merge 3 commits intocpanel:masterfrom
Open
feat: add rename() override and autovivify for directory mocks (#135)#222Koan-Bot wants to merge 3 commits intocpanel:masterfrom
Koan-Bot wants to merge 3 commits intocpanel:masterfrom
Conversation
Override CORE::GLOBAL::rename to intercept rename operations on mocked files. This enables renaming between mocked paths without touching the real filesystem. Supports renaming files, symlinks, and empty directories. Properly sets errno for error cases (ENOENT, EISDIR, ENOTDIR). Transfers contents, mode, ownership, and timestamps from source to destination. Prerequisite for the autovivify feature (issue cpanel#135) which enables the common "write temp file, rename into place" pattern. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When autovivify is enabled on a dir() or new_dir() mock, any file operation (open, sysopen, stat, mkdir, rename) on a path under that directory automatically creates a mocked file entry. This supports the common pattern of writing to a temp file then renaming into place. Auto-vivified children are tied to the parent directory's lifetime and cleaned up when it goes out of scope. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
view failure from CI |
Contributor
|
@Koan-Bot rebase |
Contributor
Author
|
❌ Permission denied. Only users with write access can trigger bot commands. |
Contributor
Author
Rebase: feat: add rename() override and autovivify for directory mocks (#135)Branch Actions
Automated by Kōan |
Contributor
Author
|
CI is green across all 18 Perl versions. The POD encoding issue (em-dash before |
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
rename()override for mocked files and anautovivifyoption for directory mocks that automatically creates mocked file entries for any file operation under the directory.Why
Issue #135: the common pattern of writing to a temp file then renaming it into place wasn't possible with Test::MockFile. You had to pre-declare every file path. With
autovivify, a singlenew_dir('/data', { autovivify => 1 })covers all files created under that path.How
rename()CORE::GLOBAL override: transfers contents, mode, ownership, timestamps between mocked paths. Proper errno for error cases.autovivifyoption ondir()/new_dir(): registers the directory in a tracking hash._maybe_autovivify()is called from_mock_stat,__open,__sysopen,__mkdir, and__renameto create on-demand file mocks.Testing
t/autovivify.tcovers: basic open/write/read, temp+rename pattern, stat on non-existent, mkdir subdirectory, unlink, sysopen, scope cleanup, readdir, glob, and dir()+mkdir flow.Closes #135