This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Two more delays added to test suite to help *-solaris-thread.
[perl5.git] / t / lib / io_pipe.t
CommitLineData
61f2b451
PP
1#!./perl
2
3BEGIN {
7a4c00b4
PP
4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
6 @INC = '../lib' if -d '../lib';
7 }
8}
9
10use Config;
11
12BEGIN {
13 if(-d "lib" && -f "TEST") {
774d564b
PP
14 if (! $Config{'d_fork'} ||
15 ($Config{'extensions'} !~ /\bIO\b/ && $^O ne 'VMS'))
16 {
7a4c00b4
PP
17 print "1..0\n";
18 exit 0;
19 }
61f2b451
PP
20 }
21}
22
23use IO::Pipe;
24
774d564b
PP
25my $perl = './perl';
26
61f2b451 27$| = 1;
774d564b
PP
28print "1..10\n";
29
30$pipe = new IO::Pipe->reader($perl, '-e', 'print "not ok 1\n"');
31while (<$pipe>) {
32 s/^not //;
33 print;
34}
35$pipe->close or print "# \$!=$!\nnot ";
36print "ok 2\n";
37
38$cmd = 'BEGIN{$SIG{ALRM} = sub {print "not ok 4\n"; exit}; alarm 10} s/not //';
39$pipe = new IO::Pipe->writer($perl, '-pe', $cmd);
40print $pipe "not ok 3\n" ;
41$pipe->close or print "# \$!=$!\nnot ";
42print "ok 4\n";
61f2b451
PP
43
44$pipe = new IO::Pipe;
45
46$pid = fork();
47
48if($pid)
49 {
50 $pipe->writer;
774d564b
PP
51 print $pipe "Xk 5\n";
52 print $pipe "oY 6\n";
61f2b451
PP
53 $pipe->close;
54 wait;
55 }
56elsif(defined $pid)
57 {
58 $pipe->reader;
59 $stdin = bless \*STDIN, "IO::Handle";
60 $stdin->fdopen($pipe,"r");
61 exec 'tr', 'YX', 'ko';
62 }
63else
64 {
774d564b 65 die "# error = $!";
61f2b451
PP
66 }
67
68$pipe = new IO::Pipe;
69$pid = fork();
70
71if($pid)
72 {
73 $pipe->reader;
74 while(<$pipe>) {
75 s/^not //;
76 print;
77 }
78 $pipe->close;
79 wait;
80 }
81elsif(defined $pid)
82 {
83 $pipe->writer;
84
85 $stdout = bless \*STDOUT, "IO::Handle";
86 $stdout->fdopen($pipe,"w");
774d564b
PP
87 print STDOUT "not ok 7\n";
88 exec 'echo', 'not ok 8';
61f2b451
PP
89 }
90else
91 {
92 die;
93 }
94
95$pipe = new IO::Pipe;
96$pipe->writer;
97
98$SIG{'PIPE'} = 'broken_pipe';
99
100sub broken_pipe {
774d564b 101 print "ok 9\n";
61f2b451
PP
102}
103
774d564b 104print $pipe "not ok 9\n";
61f2b451
PP
105$pipe->close;
106
3d57aefb 107sleep 1;
61f2b451 108
774d564b 109print "ok 10\n";
61f2b451 110