summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2017-07-22 10:35:08 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-07-22 10:35:08 (GMT)
commit970d2e1f1c540b94443456bbdf1a8d315401b188 (patch) (side-by-side diff)
tree8a7e352c29d45e0cf84f094388d6875b1c62a877
parent4da9775f1d88787517e54f5c1fe1c43f1e023480 (diff)
downloadposixruncapture-970d2e1f1c540b94443456bbdf1a8d315401b188.tar.gz
posixruncapture-970d2e1f1c540b94443456bbdf1a8d315401b188.tar.bz2
Add more tests
* Capture.xs (capture_set_program): Allow for undef as argument. (capture_timeout): New method.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--Capture.xs28
-rw-r--r--t/00use.t4
-rw-r--r--t/01argv.t22
-rw-r--r--t/02prog.t29
-rw-r--r--t/03timeout.t14
-rw-r--r--t/04init.t16
-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
diff --git a/Capture.xs b/Capture.xs
index d85b74c..e43bf1a 100644
--- a/Capture.xs
+++ b/Capture.xs
@@ -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;
diff --git a/t/00use.t b/t/00use.t
index aefe48e..12621b8 100644
--- a/t/00use.t
+++ b/t/00use.t
@@ -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
--- a/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
--- a/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
--- a/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
--- a/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;
diff --git a/t/03two.t b/t/07two.t
index 9b0ce0f..d3c3f50 100644
--- a/t/03two.t
+++ b/t/07two.t
@@ -1,3 +1,4 @@
+# -*- perl -*-
use lib 't';
use strict;

Return to:

Send suggestions and report system problems to the System administrator.