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 $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 skip_all('fflush(NULL) or equivalent not available')
26 unless $useperlio || $fflushNULL || $fflushall;
30 my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
31 $runperl .= qq{ "-I../lib"};
37 open IN, $f or die "open $f: $!";
38 chomp(my $line = <IN>);
41 print "# got $line\n";
42 print "# expected $val\n";
46 # This script will be used as the command to execute from
48 my $ffprog = tempfile();
49 open PROG, "> $ffprog" or die "open $ffprog: $!";
53 open OUT, ">> $f" or die "open $f: $!";
58 close PROG or die "close $ffprog: $!";;
60 $| = 0; # we want buffered output
62 # Test flush on fork/exec
64 print "ok 1 # skipped: no fork\n";
67 open OUT, "> $f" or die "open $f: $!";
73 close OUT or die "close $f: $!";
74 } elsif (defined $pid) {
77 my $command = qq{$runperl "$ffprog" "$f" "l"};
79 exec $command or die $!;
86 print file_eq($f, "Perl") ? "ok 1\n" : "not ok 1\n";
89 # Test flush on system/qx/pipe open
101 open PIPE, "$c|" or die "$c: $!";
106 for (qw(system qx popen)) {
107 my $code = $subs{$_};
109 my $command = qq{$runperl $ffprog "$f" "rl"};
110 open OUT, "> $f" or die "open $f: $!";
112 close OUT or die "close $f: $!";;
113 print "# $command\n";
115 print file_eq($f, "Perl") ? "ok $t\n" : "not ok $t\n";
119 my $cmd = _create_runperl(
122 sprintf('print qq[ok $_] for (%d..%d)', $t, $t+2));
123 print "# cmd = '$cmd'\n";
124 open my $CMD, "$cmd |" or die "Can't open pipe to '$cmd': $!";
126 system("$runperl -e 0");