Skip to content

Commit

Permalink
Not using IPC::Open3 here
Browse files Browse the repository at this point in the history
  • Loading branch information
briandfoy committed Jun 19, 2023
1 parent 9a5ab73 commit 50a749a
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions t/bc/ipc-open3.t
Expand Up @@ -4,15 +4,14 @@ use warnings;
use lib qw(./t/lib);

use Test::More;
use IPC::Open3 ();
use Symbol ();
use FileHandle;
use Time::HiRes qw(usleep);
use IO::Select;

my $program = 'bin/bc';

foreach my $table ( operator_table(), precedence_table(), special_expr_table(), statement_table() ) {
foreach my $table ( special_expr_table() ) {# operator_table(), precedence_table(), special_expr_table(), statement_table() ) {
my $label = shift @$table;
subtest $label => sub {
foreach my $tuple ( @$table ) {
Expand All @@ -26,47 +25,23 @@ sub run_bc {
# https://www.perlmonks.org/?node_id=419919
my( $input ) = @_;

my $child_in = Symbol::gensym();
# https://github.com/perl/perl5/issues/14533
if ($^O eq 'MSWin32') {
no strict 'subs';
require Win32API::File;
Win32API::File->import( qw(:Func :HANDLE_FLAG_) );
my $wh = FdGetOsFHandle(fileno $child_in);
SetHandleInformation($wh, HANDLE_FLAG_INHERIT(), 0);
die "Can't turn off HANDLE_FLAG_INHERIT: $@";
}

my $pid = IPC::Open3::open3(
$child_in,
my $child_out,
my $child_err = Symbol::gensym(),
$^X, $program, '-'
);

my $select_out = IO::Select->new($child_out);
my $select_err = IO::Select->new($child_err);
my $class = require './bin/bc';
print "Class is <$class>\n";

my %hash;
foreach my $line ( split /\n/, $input ) {
print {$child_in} $line, "\n";
chomp($input); $input .= "\n";

# give the child process a chance to work, otherwise we
# will check its filehandles too soon.
select(undef,undef,undef,0.4);
my %hash = ( input => $input );
print STDERR Dumper(\%hash); use Data::Dumper;
open $PerlPowerTools::bc::INPUT_FH, '>', \ $hash{info};
open $PerlPowerTools::bc::ERROR_FH, '>', \ $hash{error};
open $PerlPowerTools::bc::DEBUG_FH, '>', \ $hash{debug};
open $PerlPowerTools::bc::VALUE_FH, '>', \ $hash{value};

if( $select_err->can_read(0.1) ) {
sysread $child_err, my $error, 4096;
$hash{error} .= $error;
}
if( $select_out->can_read(0.1) ) {
sysread $child_out, my $output, 4096;
$hash{output} .= $output;
}
}
print "About to run\n";
eval { $class->run('-d', '-') };
print "Already ran\n";

close $child_in;
waitpid $pid, 1;
print STDERR Dumper(\%hash); use Data::Dumper;

return \%hash;
}
Expand Down

0 comments on commit 50a749a

Please sign in to comment.