Skip to content

bug: open(<&, $fh) dup fails on mocked filehandles #425

Description

@toddr-bot

open(my $dup, "<&", $fh) (and >&, <&=, >&=) fails with "Bad file descriptor" when $fh is a mocked filehandle.

Reproduce

use Test::MockFile ();
my $mock = Test::MockFile->file("/tmp/test", "hello\n");
open(my $fh, "<", "/tmp/test") or die;
open(my $dup, "<&", $fh) or die "dup: $!";  # Dies: Bad file descriptor

Cause

The <& mode is not in __open's supported mode list (> < >> +< +> +>>), so it falls through to CORE::open. Since mocked handles have synthetic filenos (FILENO dies), the kernel-level dup fails.

Fix

PR #424 detects dup modes early in __open and creates a new tied handle sharing the same mock data when the source handle is mocked.

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