Debian Codegraph @

t/tied_stderr.t

raw symbols SCIP
1 #!/usr/bin/perl
2
3 =pod
4
5 =head1 NAME
6
7 tied_stderr.t - Test IPC::Run with tied STDERR that lacks FILENO
8
9 =head1 DESCRIPTION
10
11 Regression test for rt.cpan.org#102824 / GitHub issue #92.
12 When STDERR is tied to a class that doesn't implement FILENO,
13 IPC::Run should still work correctly.
14
15 =cut
16
17 use strictscip-perl cpan IPC-Run 20260402.0 strict/;
18 use warningsscip-perl cpan IPC-Run 20260402.0 warnings/;
19 use Test::Morescip-perl cpan IPC-Run 20260402.0 Test/More/ tests => 2;
20 use IPC::Runscip-perl cpan IPC-Run 20260402.0 IPC/Run/ qw(run timeout);
21
22 {
23 package MySTDERRscip-perl cpan IPC-Run 20260402.0 MySTDERR/;
24 sub TIEHANDLEscip-perl cpan IPC-Run 20260402.0 MySTDERR/TIEHANDLE(). { return blessscip-perl cpan IPC-Run 20260402.0 MySTDERR/bless(). {}, __PACKAGE__scip-perl cpan IPC-Run 20260402.0 MySTDERR/__PACKAGE__(). }
25 sub PRINTscip-perl cpan IPC-Run 20260402.0 MySTDERR/PRINT(). { shiftscip-perl cpan IPC-Run 20260402.0 MySTDERR/shift().; print STDOUT @_scip-perl cpan IPC-Run 20260402.0 MySTDERR/`@_`. }
26 }
27
28 # Tie STDERR to a handle that doesn't implement FILENO
29 tie *STDERR, 'MySTDERR' or diescip-perl cpan IPC-Run 20260402.0 MySTDERR/die(). $!scip-perl cpan IPC-Run 20260402.0 MySTDERR/`$!`.;
30
31 my $out;
32
33 # This should not die with "Can't locate object method "FILENO""
34 # Use $^X instead of 'echo' so the test works on Win32 where echo is
35 # a shell built-in, not a standalone executable (GH#222).
36 eval { run [ $^Xscip-perl cpan IPC-Run 20260402.0 MySTDERR/`$^X`., '-e', 'print qq(hello\n)' ], '>', \$out, timeoutscip-perl cpan IPC-Run 20260402.0 IPC/Run/timeout().(30) };
37 my $err = $@scip-perl cpan IPC-Run 20260402.0 MySTDERR/`$@`.;
38
39 untie *STDERR;
40
41 okscip-perl cpan IPC-Run 20260402.0 MySTDERR/ok().( !$err, "run() succeeds with tied STDERR lacking FILENO" )
42 or diagscip-perl cpan IPC-Run 20260402.0 MySTDERR/diag().("Got error: $err");
43
44 $out = '' unless definedscip-perl cpan IPC-Run 20260402.0 MySTDERR/defined(). $out;
45 $out =~ s/\r?\n$//;
46 isscip-perl cpan IPC-Run 20260402.0 MySTDERR/is().( $out, 'hello', "run() captures output correctly with tied STDERR" );