8 # Script to test auto flush on fork/exec/system/qx. The idea is to
9 # print "Pe" to a file from a parent process and "rl" to the same file
10 # from a child process. If buffers are flushed appropriately, the
11 # file should contain "Perl". We'll see...
16 # This attempts to mirror the #ifdef forest found in perl.h so that we
17 # know when to run these tests. If that forest ever changes, change
18 # it here too or expect test gratuitous test failures.
19 my $useperlio = defined $Config{useperlio} ? $Config{useperlio} eq 'define' ? 1 : 0 : 0;
20 my $fflushNULL = defined $Config{fflushNULL} ? $Config{fflushNULL} eq 'define' ? 1 : 0 : 0;
21 my $d_sfio = defined $Config{d_sfio} ? $Config{d_sfio} eq 'define' ? 1 : 0 : 0;
22 my $fflushall = defined $Config{fflushall} ? $Config{fflushall} eq 'define' ? 1 : 0 : 0;
23 my $d_fork = defined $Config{d_fork} ? $Config{d_fork} eq 'define' ? 1 : 0 : 0;
25 if ($useperlio || $fflushNULL || $d_sfio) {
31 print "1..0 # Skip: fflush(NULL) or equivalent not available\n";
36 my $runperl = qq{$^X "-I../lib"};
41 unlink $_ or warn "unlink $_: $!";
49 open IN, $f or die "open $f: $!";
50 chomp(my $line = <IN>);
53 print "# got $line\n";
54 print "# expected $val\n";
58 # This script will be used as the command to execute from
60 open PROG, "> ff-prog" or die "open ff-prog: $!";
64 open OUT, ">> $f" or die "open $f: $!";
69 close PROG or die "close ff-prog: $!";;
70 push @delete, "ff-prog";
72 $| = 0; # we want buffered output
74 # Test flush on fork/exec
76 print "ok 1 # skipped: no fork\n";
79 open OUT, "> $f" or die "open $f: $!";
85 close OUT or die "close $f: $!";
86 } elsif (defined $pid) {
89 my $command = qq{$runperl "ff-prog" "$f" "l"};
91 exec $command or die $!;
98 print file_eq($f, "Perl") ? "ok 1\n" : "not ok 1\n";
102 # Test flush on system/qx/pipe open
114 open PIPE, "$c|" or die "$c: $!";
119 for (qw(system qx popen)) {
120 my $code = $subs{$_};
122 my $command = qq{$runperl "ff-prog" "$f" "rl"};
123 open OUT, "> $f" or die "open $f: $!";
125 close OUT or die "close $f: $!";;
126 print "# $command\n";
128 print file_eq($f, "Perl") ? "ok $t\n" : "not ok $t\n";