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 = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
37 $runperl .= qq{ "-I../lib"};
43 unlink $_ or warn "unlink $_: $!";
51 open IN, $f or die "open $f: $!";
52 chomp(my $line = <IN>);
55 print "# got $line\n";
56 print "# expected $val\n";
60 # This script will be used as the command to execute from
62 open PROG, "> ff-prog" or die "open ff-prog: $!";
66 open OUT, ">> $f" or die "open $f: $!";
71 close PROG or die "close ff-prog: $!";;
72 push @delete, "ff-prog";
74 $| = 0; # we want buffered output
76 # Test flush on fork/exec
78 print "ok 1 # skipped: no fork\n";
81 open OUT, "> $f" or die "open $f: $!";
87 close OUT or die "close $f: $!";
88 } elsif (defined $pid) {
91 my $command = qq{$runperl "ff-prog" "$f" "l"};
93 exec $command or die $!;
100 print file_eq($f, "Perl") ? "ok 1\n" : "not ok 1\n";
104 # Test flush on system/qx/pipe open
116 open PIPE, "$c|" or die "$c: $!";
121 for (qw(system qx popen)) {
122 my $code = $subs{$_};
124 my $command = qq{$runperl "ff-prog" "$f" "rl"};
125 open OUT, "> $f" or die "open $f: $!";
127 close OUT or die "close $f: $!";;
128 print "# $command\n";
130 print file_eq($f, "Perl") ? "ok $t\n" : "not ok $t\n";
135 my $cmd = qq[$runperl -e "print qq[ok \$_\\n] for ($t..$t+2)"];
136 open my $CMD, "$cmd |" or die "Can't open pipe to '$cmd': $!";
138 system("$runperl -e 0");