feat: add truncate() override for mocked files#223
Merged
toddr merged 2 commits intocpanel:masterfrom Feb 25, 2026
Merged
Conversation
Contributor
Author
Rebase: feat: add truncate() override for mocked filesBranch Actions
Automated by Kōan |
truncate() was not overridden, so calls on mocked files passed through to the real filesystem. Add CORE::GLOBAL::truncate override that: - Shortens contents when length < current size - Pads with null bytes when length > current size - Returns ENOENT for non-existent mocks, EISDIR for directories, EINVAL for negative length - Falls through to CORE::truncate for non-mocked files - Registers in file_arg_position_for_command for strict mode support Note: CORE::truncate does not support goto &CORE::truncate, so the fallthrough uses explicit CORE::truncate() call. Co-Authored-By: Claude Opus 4.6 <[email protected]>
ce89825 to
b9ff5ce
Compare
A `<<<<<<< HEAD` conflict marker was left behind during the rebase, causing compilation failure in CI. Co-Authored-By: Claude Opus 4.6 <[email protected]>
toddr
approved these changes
Feb 25, 2026
This was referenced Feb 25, 2026
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
Override
truncate()for mocked files so it operates on mock contents instead of passing through to the real filesystem.Why
truncate()was the last major file operation not overridden by Test::MockFile. Calls totruncate($fh, $len)ortruncate($path, $len)on mocked files silently hit the real FS — breaking test isolation. Addresses #221.How
CORE::GLOBAL::truncateoverride via__truncate($$)sub_get_file_object(handles both filehandle and path arguments)$length < current, pads with\0when$length > currentfile_arg_position_for_commandfor strict mode&CORE::truncatecan't be called viagoto, so fallthrough uses directCORE::truncate()callTesting
11 subtests in
t/truncate.tcovering: shorten, extend with nulls, zero-length, no-op same-length, filehandle truncate, sysopen filehandle, ENOENT/EISDIR/EINVAL errors, real file passthrough, and open-then-truncate flow.🤖 Generated with Claude Code