diff options
-rw-r--r-- | Capture.xs | 28 | ||||
-rw-r--r-- | t/00use.t | 4 | ||||
-rw-r--r-- | t/01argv.t | 22 | ||||
-rw-r--r-- | t/02prog.t | 29 | ||||
-rw-r--r-- | t/03timeout.t | 14 | ||||
-rw-r--r-- | t/04init.t | 16 | ||||
-rw-r--r-- | t/05simple.t (renamed from t/01simple.t) | 1 | ||||
-rw-r--r-- | t/06lines.t (renamed from t/02lines.t) | 2 | ||||
-rw-r--r-- | t/07two.t (renamed from t/03two.t) | 1 |
9 files changed, 110 insertions, 7 deletions
@@ -85,18 +85,30 @@ capture_set_argv_ref(cp, argv) void capture_set_program(cp, prog) POSIX::Run::Capture cp; - char *prog; - CODE: + char *prog = NO_INIT; + PPCODE: if (cp->program != &PL_sv_undef) SvREFCNT_dec(cp->program); cp->program = ST(1); if (cp->program != &PL_sv_undef) { SvREFCNT_inc(cp->program); - cp->rc.rc_program = prog; + cp->rc.rc_program = SvPV_nolen(cp->program); cp->flags |= RCF_PROGRAM; } else cp->flags &= ~RCF_PROGRAM; - + +void +capture_set_timeout(cp, timeout) + POSIX::Run::Capture cp; + unsigned timeout; + CODE: + if (timeout) { + cp->rc.rc_timeout = timeout; + cp->flags |= RCF_TIMEOUT; + } else { + cp->flags &= ~RCF_TIMEOUT; + } + ARGV capture_argv(cp) POSIX::Run::Capture cp; @@ -116,6 +128,14 @@ capture_program(cp) ST(0) = cp->program; XSRETURN(1); +unsigned +capture_timeout(cp) + POSIX::Run::Capture cp; + CODE: + RETVAL = (cp->flags & RCF_TIMEOUT) ? cp->rc.rc_timeout : 0; + OUTPUT: + RETVAL + int capture_run(cp) POSIX::Run::Capture cp; @@ -1,6 +1,4 @@ -# Before 'make install' is performed this script should be runnable with -# 'make test'. After 'make install' it should work as 'perl POSIX-Run-Capture.t' - +# -*- perl -*- ######################### use strict; diff --git a/t/01argv.t b/t/01argv.t new file mode 100644 index 0000000..9dffd04 --- /dev/null +++ b/t/01argv.t @@ -0,0 +1,22 @@ +# -*- perl -*- + +use lib 't'; + +use strict; +use warnings; +use Test::More tests => 4; +use POSIX::Run::Capture; + +my $obj = new POSIX::Run::Capture; + +# Initial ARGV is empty +is(0+@{$obj->argv}, 0); + +# Set argv +$obj->set_argv('cat', 'file1', 'file2'); +is(0+@{$obj->argv}, 3); +is_deeply($obj->argv, [ 'cat', 'file1', 'file2' ]); + +# Unset argv +$obj->set_argv(); +is(0+@{$obj->argv}, 0); diff --git a/t/02prog.t b/t/02prog.t new file mode 100644 index 0000000..9cef1e4 --- /dev/null +++ b/t/02prog.t @@ -0,0 +1,29 @@ +# -*- perl -*- +use lib 't'; + +use strict; +use warnings; +use Test::More tests => 6; +use POSIX::Run::Capture; + +my $obj = new POSIX::Run::Capture; + +# Initial prog is undefined +is($obj->program, undef); + +# Set program +$obj->set_program('ls'); +is($obj->program, 'ls'); + +# Unset program +$obj->set_program(undef); +is($obj->program, undef); + +# Set argv array. Now, program is argv[0]. +$obj->set_argv('dir'); +is($obj->program, 'dir'); + +# Set it explicitly +$obj->set_program('ls'); +is($obj->program, 'ls'); +is($obj->argv->[0], 'dir'); diff --git a/t/03timeout.t b/t/03timeout.t new file mode 100644 index 0000000..d7a4043 --- /dev/null +++ b/t/03timeout.t @@ -0,0 +1,14 @@ +# -*- perl -*- +use lib 't'; + +use strict; +use warnings; +use Test::More tests => 2; +use POSIX::Run::Capture; + +my $obj = new POSIX::Run::Capture; + +is($obj->timeout, 0); + +$obj->set_timeout(60); +is($obj->timeout, 60); diff --git a/t/04init.t b/t/04init.t new file mode 100644 index 0000000..aaed382 --- /dev/null +++ b/t/04init.t @@ -0,0 +1,16 @@ +# -*- perl -*- + +use lib 't'; + +use strict; +use warnings; +use Test::More tests => 3; +use POSIX::Run::Capture; + +my $obj = new POSIX::Run::Capture(argv => [qw(dir /tmp)], + program => '/bin/ls', + timeout => 15); + +is_deeply($obj->argv, [qw(dir /tmp)]); +is($obj->program, '/bin/ls'); +is($obj->timeout, 15); diff --git a/t/01simple.t b/t/05simple.t index 36b4221..c982477 100644 --- a/t/01simple.t +++ b/t/05simple.t @@ -1,3 +1,4 @@ +# -*- perl -*- use lib 't'; use strict; diff --git a/t/02lines.t b/t/06lines.t index 917921e..2e9b303 100644 --- a/t/02lines.t +++ b/t/06lines.t @@ -1,3 +1,5 @@ +# -*- perl -*- + use lib 't'; use strict; @@ -1,3 +1,4 @@ +# -*- perl -*- use lib 't'; use strict; |