App-psst
view release on metacpan or search on metacpan
t/00-sane.t view on Meta::CPAN
# see that &bash_interactive works
is(bash_interactive("echo \$PPID\n", PS1 => '>'),
qq{>echo \$PPID\n$$\n>exit\n}, "PPID check");
my $quick_alarm = 0.75; # too quick will cause false fail; slow is tedious
diag("alarm test - short delay");
my $t0 = [gettimeofday()];
my $ans = eval { bash_interactive("sleep 7", maxt => $quick_alarm) } || $@;
my $wallclock = tv_interval($t0);
like($ans, qr{Timeout.*waiting for}, "alarm fired (total $wallclock sec)");
cmp_ok($wallclock, '>', $quick_alarm * 0.7, ' and that alarm waited');
cmp_ok($wallclock, '<', $quick_alarm * 5.0, ' but did not wait too long');
local @ENV{qw{ G1 G2 G3 }} =
('ABCD goldfish', 'MA goldfish', 'SAR CDBDIs');
like(bash_interactive(qq{echo \$G1; echo \$G2\necho \$G3\n}),
qr{ABCD.*MA.*SAR}s, "command sequence");
}
t/tlib/BashRunner.pm view on Meta::CPAN
or die "Can't dup STDERR into STDOUT: $!";
open STDIN, '<&', \*$read_fh
or die "Can't dup STDIN from pipe: $!";
exec @cmd or die "exec(@cmd) failed: $!";
}
close $write_fh;
close $read_fh;
local $SIG{ALRM} = sub {
kill 'HUP', $rd_pid; # kick the shell on our way out
die "Timeout(${maxt}s) waiting for @cmd";
};
some_alarm($maxt);
my $out = join '', <$shout_fh>;
close $shout_fh;
$out .= sprintf("\nRETCODE:0x%02x\n", $?) if $?;
some_alarm(0);
# wait on writer, for tidiness
( run in 0.239 second using v1.01-cache-2.11-cpan-4d50c553e7e )