feat: add symlink() and link() overrides for mocked files (#16)#206
Open
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Open
feat: add symlink() and link() overrides for mocked files (#16)#206Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Koan-Bot wants to merge 2 commits intocpanel:masterfrom
Conversation
0ef25dc to
6c06202
Compare
Override CORE::GLOBAL::symlink and CORE::GLOBAL::link so that calling the builtins on mocked paths works within the mock filesystem. symlink($target, $link_path): - Converts a non-existent mock into a symlink pointing to $target - Fails with EEXIST if destination already exists - Passes through to CORE::symlink for unmocked paths link($source, $dest): - Copies contents and metadata from source mock to destination mock - Follows symlinks on source (matching Perl's link() behavior) - Fails with EPERM for directories, EEXIST if dest exists - Documented limitation: writes to one don't propagate to the other Both functions are registered in file_arg_position_for_command for strict mode support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6c06202 to
c91f566
Compare
S_IFLNK (0120000) and S_IFREG (0100000) share bit 0100000, so a bare `$mode & S_IFLNK` test matches regular files too. This caused contents() to return undef for all file mocks, breaking 23 test files. Use `($mode & S_IFMT) == S_IFLNK` — the same pattern is_dir() and is_file() already use correctly. 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.
Summary
Adds
CORE::GLOBAL::symlinkandCORE::GLOBAL::linkoverrides so that calling the Perl builtins on mocked paths operates within the mock filesystem instead of touching disk.Closes #16
symlink($target, $link_path)
$targetEEXISTif the destination already exists (file, dir, or symlink)CORE::symlinkfor unmocked pathslink($source, $dest)
nlinkon both source and destinationlink()semantics)EPERMfor directory sources,EEXISTif dest exists,EXDEVif dest is unmockedLimitations
Changes
lib/Test/MockFile.pm:__symlink(),__link(), BEGIN block registration,file_arg_position_for_commandentries, SYNOPSIS examples, CAVEATS documentationt/symlink_link.t: 22 test cases covering success paths, error conditions, symlink following, parent directory updatesTest plan
symlink()builtin converts non-existent mock to symlinklink()builtin copies file contents between mocks🤖 Generated with Claude Code