Bug
Two-arg open() with whitespace between the mode prefix and filename fails to match mocked files.
my $mock = Test::MockFile->file('/tmp/file', 'hello');
# Works:
open(my $fh1, '</tmp/file');
# Fails with ENOENT — Perl strips the space, MockFile doesn't:
open(my $fh2, '< /tmp/file');
Real Perl strips leading and trailing whitespace from the filename portion after extracting the mode prefix (<, >, >>, +<, +>, +>>). This is a common Perl idiom (open(my $fh, "> $path") with a space for readability).
MockFile's regex captures the whitespace literally, producing a path like /tmp/file that doesn't match the mock registered at /tmp/file.
Affected modes
All two-arg modes: <, >, >>, +<, +>, +>>, and bare filenames (no mode prefix).
Not affected
- Three-arg
open(FH, '<', $path) — filename comes from a separate argument, no mode parsing
- Pipe modes (
|-, -|) — fall through to CORE::open
🤖 Created by Kōan
Bug
Two-arg
open()with whitespace between the mode prefix and filename fails to match mocked files.Real Perl strips leading and trailing whitespace from the filename portion after extracting the mode prefix (
<,>,>>,+<,+>,+>>). This is a common Perl idiom (open(my $fh, "> $path")with a space for readability).MockFile's regex captures the whitespace literally, producing a path like
/tmp/filethat doesn't match the mock registered at/tmp/file.Affected modes
All two-arg modes:
<,>,>>,+<,+>,+>>, and bare filenames (no mode prefix).Not affected
open(FH, '<', $path)— filename comes from a separate argument, no mode parsing|-,-|) — fall through toCORE::open🤖 Created by Kōan