9 # Script to test auto flush on fork/exec/system/qx. The idea is to
10 # print "Pe" to a file from a parent process and "rl" to the same file
11 # from a child process. If buffers are flushed appropriately, the
12 # file should contain "Perl". We'll see...
17 # This attempts to mirror the #ifdef forest found in perl.h so that we
18 # know when to run these tests. If that forest ever changes, change
19 # it here too or expect test gratuitous test failures.
20 my $useperlio = defined $Config{useperlio} ? $Config{useperlio} eq 'define' ? 1 : 0 : 0;
21 my $fflushNULL = defined $Config{fflushNULL} ? $Config{fflushNULL} eq 'define' ? 1 : 0 : 0;
22 my $d_sfio = defined $Config{d_sfio} ? $Config{d_sfio} eq 'define' ? 1 : 0 : 0;
23 my $fflushall = defined $Config{fflushall} ? $Config{fflushall} eq 'define' ? 1 : 0 : 0;
24 my $d_fork = defined $Config{d_fork} ? $Config{d_fork} eq 'define' ? 1 : 0 : 0;
26 if ($useperlio || $fflushNULL || $d_sfio) {
32 print "1..0 # Skip: fflush(NULL) or equivalent not available\n";
37 my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
38 $runperl .= qq{ "-I../lib"};
44 open IN, $f or die "open $f: $!";
45 chomp(my $line = <IN>);
48 print "# got $line\n";
49 print "# expected $val\n";
53 # This script will be used as the command to execute from
55 my $ffprog = tempfile();
56 open PROG, "> $ffprog" or die "open $ffprog: $!";
60 open OUT, ">> $f" or die "open $f: $!";
65 close PROG or die "close $ffprog: $!";;
67 $| = 0; # we want buffered output
69 # Test flush on fork/exec
71 print "ok 1 # skipped: no fork\n";
74 open OUT, "> $f" or die "open $f: $!";
80 close OUT or die "close $f: $!";
81 } elsif (defined $pid) {
84 my $command = qq{$runperl "$ffprog" "$f" "l"};
86 exec $command or die $!;
93 print file_eq($f, "Perl") ? "ok 1\n" : "not ok 1\n";
96 # Test flush on system/qx/pipe open
108 open PIPE, "$c|" or die "$c: $!";
113 for (qw(system qx popen)) {
114 my $code = $subs{$_};
116 my $command = qq{$runperl $ffprog "$f" "rl"};
117 open OUT, "> $f" or die "open $f: $!";
119 close OUT or die "close $f: $!";;
120 print "# $command\n";
122 print file_eq($f, "Perl") ? "ok $t\n" : "not ok $t\n";
126 my $cmd = _create_runperl(
129 sprintf('print qq[ok $_] for (%d..%d)', $t, $t+2));
130 print "# cmd = '$cmd'\n";
131 open my $CMD, "$cmd |" or die "Can't open pipe to '$cmd': $!";
133 system("$runperl -e 0");