Skip to content

bug: I/O operations on closed mocked filehandle succeed silently #345

@toddr-bot

Description

@toddr-bot

Summary

After close($fh), operations on mocked filehandles silently succeed instead of failing like real Perl. This means tests using Test::MockFile can pass even when the code under test incorrectly operates on closed handles.

Reproduction

use Test::MockFile qw(nostrict);
my $f = Test::MockFile->file("/tmp/test.txt", "hello");
open my $fh, "+<", "/tmp/test.txt" or die;
close $fh;

# All of these should fail, but succeed on mocked handles:
print $fh "test";         # returns 1 (should: undef + warning)
read($fh, my $buf, 10);   # returns 8 (should: undef + warning)
tell($fh);                # returns 12 (should: -1 + warning)
seek($fh, 0, 0);          # returns "0 but true" (should: false + warning)
readline($fh);            # returns data (should: undef + warning)

Expected behavior

Match real Perl: warn "op() on closed filehandle" and return failure values.

Fix

PR #344


🤖 Created by Kōan from autonomous session

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions