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 skip_all('fflush(NULL) or equivalent not available')
27 unless $useperlio || $fflushNULL || $d_sfio || $fflushall;
31 my $runperl = $^X =~ m/\s/ ? qq{"$^X"} : $^X;
32 $runperl .= qq{ "-I../lib"};
38 open IN, $f or die "open $f: $!";
39 chomp(my $line = <IN>);
42 print "# got $line\n";
43 print "# expected $val\n";
47 # This script will be used as the command to execute from
49 my $ffprog = tempfile();
50 open PROG, "> $ffprog" or die "open $ffprog: $!";
54 open OUT, ">> $f" or die "open $f: $!";
59 close PROG or die "close $ffprog: $!";;
61 $| = 0; # we want buffered output
63 # Test flush on fork/exec
65 print "ok 1 # skipped: no fork\n";
68 open OUT, "> $f" or die "open $f: $!";
74 close OUT or die "close $f: $!";
75 } elsif (defined $pid) {
78 my $command = qq{$runperl "$ffprog" "$f" "l"};
80 exec $command or die $!;
87 print file_eq($f, "Perl") ? "ok 1\n" : "not ok 1\n";
90 # Test flush on system/qx/pipe open
102 open PIPE, "$c|" or die "$c: $!";
107 for (qw(system qx popen)) {
108 my $code = $subs{$_};
110 my $command = qq{$runperl $ffprog "$f" "rl"};
111 open OUT, "> $f" or die "open $f: $!";
113 close OUT or die "close $f: $!";;
114 print "# $command\n";
116 print file_eq($f, "Perl") ? "ok $t\n" : "not ok $t\n";
120 my $cmd = _create_runperl(
123 sprintf('print qq[ok $_] for (%d..%d)', $t, $t+2));
124 print "# cmd = '$cmd'\n";
125 open my $CMD, "$cmd |" or die "Can't open pipe to '$cmd': $!";
127 system("$runperl -e 0");