[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.11-132-gcc9a692



The following commit has been merged in the master branch:
commit cc9a69232231be5c1a692ac477bde1fc9760d397
Author: Niels Thykier <niels@thykier.net>
Date:   Tue Jan 29 18:41:43 2013 +0100

    L::C::Simple: Remove OO interface
    
    Remove the L::C:Simple OO interface and some unused functions from it.
    Instead have it export functions (renaming wait to wait_any and kill
    to kill_all).
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/lib/Lintian/Command/Simple.pm b/lib/Lintian/Command/Simple.pm
index b5a598c..fad2f6d 100644
--- a/lib/Lintian/Command/Simple.pm
+++ b/lib/Lintian/Command/Simple.pm
@@ -18,31 +18,25 @@ package Lintian::Command::Simple;
 use strict;
 use warnings;
 
+use Exporter qw(import);
 use POSIX ":sys_wait_h";
 
+our @EXPORT_OK = qw(rundir background background_dir wait_any kill_all);
+
 =head1 NAME
 
 Lintian::Command::Simple - Run commands without pipes
 
 =head1 SYNOPSIS
 
-    use Lintian::Command::Simple;
+    use Lintian::Command::Simple qw(background rundir);
 
-    Lintian::Command::Simple::run("echo", "hello world");
+    Lintian::Command::Simple::rundir ('./some-dir/', 'echo', 'hello world');
 
     # Start a command in the background:
     Lintian::Command::Simple::background("sleep", 10);
     print wait() > 0 ? "success" : "failure";
 
-    # Using the OO interface
-
-    my $cmd = Lintian::Command::Simple->new();
-
-    $cmd->run("echo", "hello world");
-
-    $cmd->background("sleep", 10);
-    print ($cmd->wait())? "success" : "failure";
-
 
 =head1 DESCRIPTION
 
@@ -53,87 +47,31 @@ Pipes are not handled at all, except for those handled internally by
 the shell. See 'perldoc -f exec's note about shell metacharacters.
 If you want to pipe to/from Perl, look at Lintian::Command instead.
 
-A procedural and an Object-Oriented (from now on OO) interfaces are
-provided.
-
-It is possible to reuse an object to run multiple commands, but only
-after reaping the previous command.
-
 =over 4
 
-=item new()
-
-Creates a new Lintian::Command::Simple object and returns a reference
-to it.
-
-=cut
-
-sub new {
-    my ($class, $pkg) = @_;
-    my $self = {};
-    bless($self, $class);
-    return $self;
-}
-
-=item run(command, argument  [, ...])
-
-Executes the given C<command> with the given arguments and returns the
-status code as one would see it from a shell script.
-
-Being fair, the only advantage of this function (or method) over the
-CORE::system() function is the way the return status is reported.
-
-=cut
-
-sub run {
-    my $self;
-
-    if (ref $_[0]) {
-        $self = shift;
-        return -1
-            if defined($self->{'pid'});
-    }
-
-    system(@_);
-
-    $self->{'status'} = $?
-        if defined $self;
-
-    return $? >> 8;
-}
-
 =item rundir(dir, command, argument  [, ...])
 
 Executes the given C<command> with the given arguments and in C<dir>
 returns the status code as one would see it from a shell script.
 
-Being fair, the only advantage of this function (or method) over the
-CORE::system() function is the way the return status is reported.
+Being fair, the only advantage of this function over the
+CORE::system() function is the way the return status is reported
+and the chdir support.
 
 =cut
 
 sub rundir {
-    my $self;
     my $pid;
     my $res;
 
-    if (ref $_[0]) {
-        $self = shift;
-        return -1
-            if defined($self->{'pid'});
-    }
     $pid = fork();
     if (not defined($pid)) {
         # failed
         $res = -1;
     } elsif ($pid > 0) {
         # parent
-        if (defined($self)){
-            $self->{'pid'} = $pid;
-            $res = $self->wait();
-        } else {
-            $res = Lintian::Command::Simple::wait($pid);
-        }
+        waitpid ($pid, 0);
+        $res = $? >> 8;
     } else {
         # child
         my $dir = shift;
@@ -158,16 +96,6 @@ calling wait() to reap the previous command.
 =cut
 
 sub background {
-    my $self;
-
-    if (ref $_[0]) {
-        $self = shift;
-        return -1
-            if (defined($self->{'pid'}));
-
-        $self->{'status'} = undef;
-    }
-
     my $pid = fork();
 
     if (not defined($pid)) {
@@ -175,10 +103,6 @@ sub background {
         return -1;
     } elsif ($pid > 0) {
         # parent
-
-        $self->{'pid'} = $pid
-            if (defined($self));
-
         return $pid;
     } else {
         # child
@@ -201,16 +125,6 @@ calling wait() to reap the previous command.
 =cut
 
 sub background_dir {
-    my $self;
-
-    if (ref $_[0]) {
-        $self = shift;
-        return -1
-            if (defined($self->{'pid'}));
-
-        $self->{'status'} = undef;
-    }
-
     my $pid = fork();
 
     if (not defined($pid)) {
@@ -218,10 +132,6 @@ sub background_dir {
         return -1;
     } elsif ($pid > 0) {
         # parent
-
-        $self->{'pid'} = $pid
-            if (defined($self));
-
         return $pid;
     } else {
         # child
@@ -233,53 +143,31 @@ sub background_dir {
     }
 }
 
-=item wait (pid|hashref[, nohang])
-
-=item wait ([nohang])
-
-When called as a function:
-If C<pid> is specified, it waits until the given process (which must be
-a child of the current process) returns.  If C<nohang> is a truth value,
-then the function will attempt to reap the process without waiting for
-it.
-
-If C<pid> is not specified, the function returns -1 and $! is set to
-EINVAL.
-
-When called as a method:
-It takes one optional argument C<nohang>. It waits for the previously
-background()ed process to return.  If C<nohang> is a truth value, it
-will do a non-blocking attempt to reap the process.  If the process
-is still running it will return immediately with -1 and $! set to 0.
-
-The return value is either -1, probably indicating an error, or the
-return status of the process as it would be seen from a shell script.
-See 'perldoc -f waitpid' for more details about the possible meanings
-of -1.
-
-
-To reap one from many:
+=item wait_any (hashref[, nohang])
 
 When starting multiple processes asynchronously, it is common to wait
 until the first is done. While the CORE::wait() function is usually
 used for that very purpose, it does not provide the desired results
 when the processes were started via the OO interface.
 
-To help with this task, wait() can take a hash ref where the value of
-each entry is an instance of Lintian::Command::Simple. The key of each
-entry is the pid of that command (i.e. $cmd->pid).
-
-Under this mode, wait() waits until any child process is done and if the
-deceased process is one of the set passed via the hash ref it marks it
-as reaped and stores the return status.
-The results and return value are undefined when under this mode wait()
-"accidentally" reaps a process not started by one of the objects passed
-in the hash ref.
-
-The return value in scalar context is the instance of the object that
-started the now deceased process. In list context, the pid and value
-(i.e. the object instance) are returned.
-Whenever CORE::waitpid() would return -1, wait() returns undef or a null
+To help with this task, wait_any() can take a hash ref where the key
+of each entry is the pid of that command.  There are no requirements
+for the value (which can be used for any application specific
+purpose).
+
+Under this mode, wait_any() waits until any child process is done.
+The key (and value) associated the pid of the reaped child will then
+be removed from the hashref.  The exitcode of the child is available
+via C<$?> as usual.
+
+The results and return value are undefined when under this mode
+wait_any() "accidentally" reaps a process not listed in the hashref.
+
+The return value in scalar context is value associated with the pid of
+the reaped processed.  In list context, the pid and value are returned
+as a pair.
+
+Whenever waitpid() would return -1, wait() returns undef or a null
 value so that it is safe to:
 
     while($cmd = Lintian::Command::Simple::wait(\%hash)) { something; }
@@ -287,191 +175,67 @@ value so that it is safe to:
 The same is true whenever the hash reference points to an empty hash.
 
 If C<nohang> is also given, wait will attempt to reap any child
-process in non-blockingly.  If no child can be reaped, it will
+process non-blockingly.  If no child can be reaped, it will
 immediately return (like there were no more processes left) instead of
 waiting.
 
-Passing any other kind of reference or value as arguments has undefined
-results.
-
 =cut
 
-sub wait {
-    my ($self, $pid, $nohang);
-
-    if (ref $_[0] eq 'Lintian::Command::Simple') {
-        ($self, $nohang) = @_;
-        $pid = $self->{'pid'};
-    } else {
-        ($pid, $nohang) = @_;
-    }
+sub wait_any {
+    my ($jobs, $nohang) = @_;
+    my $reaped_pid;
+    my $extra;
 
     $nohang = WNOHANG if $nohang;
     $nohang //= 0;
 
-    if (defined($pid) && !ref $pid) {
-        my $ret = waitpid($pid, $nohang);
-        my $status = $?;
-        my $reaped = 0;
-
-        $reaped = 1 unless $ret == -1 or ($ret == 0 and $nohang);
-
-        if (defined $self) {
-            # Clear the PID field if we reaped the child or the child
-            # no longer exists.
-            $self->{'pid'} = undef
-                if $reaped or ($ret == -1 and $! == POSIX::ECHILD);
-            # Set the status only if we reaped the child
-            $self->{'status'} = $status
-                if $reaped;
-        }
-
-        $! = 0 if $ret == 0 and $nohang;
-
-        return $reaped ? $status >> 8 : -1;
-    } elsif (defined($pid)) {
-        # in this case $pid is a ref (must be a hash ref)
-        # rename it accordingly:
-        my $jobs = $pid;
-        $pid = 0;
-
-        my ($reaped_pid, $reaped_status);
-
-        # count the number of members and reset the internal hash iterator
-        if (scalar keys %$jobs == 0) {
-            return;
-        }
-
-        $reaped_pid = waitpid(-1, $nohang);
-        $reaped_status = $?;
-
-        if ($reaped_pid == -1 or ($nohang and $reaped_pid == 0)) {
-            return;
-        }
-
-        my $cmd = delete $jobs->{$reaped_pid};
-        # Did we reap some other pid?
-        return unless $cmd;
-
-        $cmd->status($reaped_status)
-                or die("internal error: object of pid $reaped_pid " .
-                        "failed to recognise its termination\n");
+    return unless scalar keys %$jobs;
 
-        return ($reaped_pid, $cmd) if wantarray;
-        return $cmd;
+    $reaped_pid = waitpid(-1, $nohang);
 
-    } else {
-        $! = POSIX::EINVAL;
-        return -1;
+    if ($reaped_pid == -1 or ($nohang and $reaped_pid == 0)) {
+        return;
     }
-}
-
-=item kill([pid|hashref])
-
-When called as a function:
-C<pid> must be specified. It sigTERMs the given process.
-Under this mode, it acts as a wrapper around CORE::kill().
-
-When called as a method:
-It takes no argument. It sigTERMsr the previously background()ed
-process and cleans up internal variables.
-
-The return value is that of CORE:kill().
 
+    # Did we reap some other pid?
+    return unless exists $jobs->{$reaped_pid};
 
-Killing multiple processes:
-
-In a similar way to wait(), it is possible to pass a hash reference to
-kill() so that it calls the kill() method of each of the objects and
-reaps them afterwards with wait().
-
-Only the processes that were successfully signaled are reaped.
-Depending on the effects of the signal, it is possible that the call to
-wait() blocks. To reduce the chances of blocking, the processes are
-reaped in the same order they were signaled.
-
-The return value is the number of processes that were successfully
-signaled (and per the above description, reaped.)
-
-=cut
-
-sub kill {
-    my ($self, $pid);
-
-    if (ref $_[0] eq 'Lintian::Command::Simple') {
-        $self = shift;
-        $pid = $self->pid();
-    } elsif (ref $_[0]) {
-        my $jobs = shift;
-        my $count = 0;
-        my @killed_jobs;
-
-        # reset internal iterator
-        keys %$jobs;
-        # send signals
-        while (my ($k, $cmd) = each %$jobs) {
-            if ($cmd->kill()) {
-                $count++;
-                push @killed_jobs, $k;
-            }
-        }
-        # and reap afterwards
-        while (my $k = shift @killed_jobs) {
-            $jobs->{$k}->wait();
-        }
-
-        return $count;
-    } else {
-        $pid = shift;
-    }
-
-    return CORE::kill('TERM', $pid);
+    $extra = delete $jobs->{$reaped_pid};
+    return ($reaped_pid, $extra) if wantarray;
+    return $extra;
 }
 
-=item pid()
+=item kill_all(hashref[, signal])
 
-Only available under the OO interface, it returns the pid of a
-background()ed process.
+In a similar way to wait_any(), it is possible to pass a hash
+reference to kill_all().  It will then kill all of the proceses
+(default signal being "TERM") followed by a reaping of the processes.
+All reaped processes (and their values) will be removed from the set.
 
-After calling wait(), this method always returns undef.
+Any entries remaining in the hashref are processes that did not
+terminate (or did not terminate yet).
 
 =cut
 
-sub pid {
-    my $self = shift;
+sub kill_all {
+    my ($jobs, $signal) = @_;
+    my $count = 0;
+    my @jobs;
 
-    return $self->{'pid'};
-}
-
-=item status()
-
-Only available under the OO interface, it returns the return status of
-the background()ed or run()-ran process.
+    $signal //= 'TERM';
 
-When used on async processes, it is only defined after calling wait().
-
-B<Note>: it is also the method internally used by wait() to set the return
-status in some cases.
-
-=cut
-
-sub status {
-    my $self = shift;
-    my $status = shift;
-
-    # Externally set the return status.
-    # It performs a sanity check by making sure the executed command is
-    # indeed done.
-    if (defined($status)) {
-        my $rstatus = $self->wait();
-
-        return 0 if ($rstatus != -1);
+    foreach my $pid (keys %$jobs) {
+        push @jobs, $pid if kill $signal, $pid;
+    }
 
-        $self->{'status'} = $status;
-        return 1;
+    foreach my $pid (@jobs) {
+        if (waitpid ($pid, 0) == $pid) {
+            $count++;
+            delete $jobs->{$pid};
+        }
     }
 
-    return (defined $self->{'status'})? $self->{'status'} >> 8 : undef;
+    return scalar @jobs;
 }
 
 1;
diff --git a/lib/Lintian/Unpacker.pm b/lib/Lintian/Unpacker.pm
index 130acfc..39507ad 100644
--- a/lib/Lintian/Unpacker.pm
+++ b/lib/Lintian/Unpacker.pm
@@ -23,7 +23,7 @@ use warnings;
 
 use base 'Class::Accessor';
 
-use Lintian::Command::Simple;
+use Lintian::Command::Simple qw(background wait_any kill_all);
 use Lintian::Util qw(fail);
 
 =head1 NAME
@@ -387,7 +387,6 @@ sub process_tasks {
     $hooks //= {};
     my $coll_hook = $hooks->{'coll-hook'};
     my $finish_hook = $hooks->{'finish-hook'};
-    my %job_data = ();
     my %failed = ();
     my %active = map { $_ => 1 } keys %$worklists;
 
@@ -433,8 +432,7 @@ sub process_tasks {
                 # collect info
                 $cmap->select ($coll);
                 $wlist->{'changed'} = 1;
-                my $cmd = Lintian::Command::Simple->new;
-                my $pid = $cmd->background ($cs->script_path, $pkg_name, $pkg_type, $base);
+                my $pid = background ($cs->script_path, $pkg_name, $pkg_type, $base);
                 $coll_hook->($lpkg, 'start', $cs, $pid) if $coll_hook;
                 if ($pid < 0) {
                     # failed - Lets not start any more jobs for this processable
@@ -442,8 +440,7 @@ sub process_tasks {
                     delete $active{$lpkg->identifier};
                     last;
                 }
-                $running_jobs->{$pid} = $cmd;
-                $job_data{$pid} = [$cs, $cmap, $lpkg];
+                $running_jobs->{$pid} = [$cs, $cmap, $lpkg];
                 if ($jobs) {
                     # Have we hit the limit of running jobs?
                     last PROC if scalar keys %$running_jobs >= $jobs;
@@ -453,14 +450,10 @@ sub process_tasks {
         # wait until a job finishes to run its branches, if any, or skip
         # this package if any of the jobs failed.
 
-        while (my ($pid, $cmd) = Lintian::Command::Simple::wait ($running_jobs, $nohang)) {
-            my $jdata = $job_data{$pid};
-            my ($cs, $cmap, $lpkg) = @$jdata;
+        while (my ($pid, $job_data) = wait_any ($running_jobs, $nohang)) {
+            my $status = $?;
+            my ($cs, $cmap, $lpkg) = @$job_data;
             my $res;
-            delete $running_jobs->{$pid};
-            delete $job_data{$pid};
-
-            my $status = $cmd->status;
             my $procid = $lpkg->identifier;
 
             $coll_hook->($lpkg, 'finish', $cs, $pid, $status)
@@ -549,7 +542,7 @@ sub wait_for_jobs {
     my ($self) = @_;
     my $running = $self->{'running-jobs'};
     if (%{ $running }) {
-        while (my ($key, undef) = Lintian::Command::Simple::wait ($running)) {
+        while (my ($key, undef) = wait_any ($running)) {
             delete $running->{$key};
         }
         $self->{'running-jobs'} = {}
@@ -567,7 +560,8 @@ sub kill_jobs {
     my ($self) = @_;
     my $running = $self->{'running-jobs'};
     if (%{ $running }) {
-        Lintian::Command::Simple::kill ($running);
+        kill_all ($running);
+        kill_all ($running, 'KILL') if %$running;
         $self->{'running-jobs'} = {}
     }
 }
diff --git a/t/scripts/Lintian/Command/Simple/01-basic.t b/t/scripts/Lintian/Command/Simple/01-basic.t
index 12dc22b..9df83ff 100644
--- a/t/scripts/Lintian/Command/Simple/01-basic.t
+++ b/t/scripts/Lintian/Command/Simple/01-basic.t
@@ -2,10 +2,8 @@
 
 use strict;
 use warnings;
-use Test::More tests => 4;
+use Test::More tests => 2;
 
-BEGIN { use_ok('Lintian::Command::Simple'); }
+BEGIN { use_ok('Lintian::Command::Simple', 'rundir'); }
 
-is(Lintian::Command::Simple::run('true'), 0, 'Basic run (true)');
-is(Lintian::Command::Simple::run('false'), 1, 'Basic run (false)');
-is(Lintian::Command::Simple::rundir('/bin', './true'), 0, 'Basic run (cd /bin && ./true)');
+is(rundir('/bin', './true'), 0, 'Basic run (cd /bin && ./true)');
diff --git a/t/scripts/Lintian/Command/Simple/02-OO-basic.t b/t/scripts/Lintian/Command/Simple/02-OO-basic.t
deleted file mode 100644
index 40cf423..0000000
--- a/t/scripts/Lintian/Command/Simple/02-OO-basic.t
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 3;
-
-use Lintian::Command::Simple;
-
-my $cmd;
-
-ok(eval { $cmd = Lintian::Command::Simple->new(); }, 'Create');
-
-is($cmd->run("true"), 0, 'Basic run (true)');
-is($cmd->run("false"), 1, 'Basic run (false)');
diff --git a/t/scripts/Lintian/Command/Simple/02-background.t b/t/scripts/Lintian/Command/Simple/02-background.t
new file mode 100644
index 0000000..342bee7
--- /dev/null
+++ b/t/scripts/Lintian/Command/Simple/02-background.t
@@ -0,0 +1,14 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+use Lintian::Command::Simple qw(background);
+
+my $pid = background ('true');
+cmp_ok($pid, '>', 0, 'Basic background (true)');
+
+is(waitpid($pid, 0), $pid, "Waiting for pid");
+is($?, 0, "Return status is 0");
+
diff --git a/t/scripts/Lintian/Command/Simple/03-background.t b/t/scripts/Lintian/Command/Simple/03-background.t
deleted file mode 100644
index f28dea9..0000000
--- a/t/scripts/Lintian/Command/Simple/03-background.t
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 6;
-
-use Lintian::Command::Simple;
-
-my $pid;
-
-$pid = Lintian::Command::Simple::background("true");
-cmp_ok($pid, '>', 0, 'Basic background (true)');
-
-is(waitpid($pid, 0), $pid, "Waiting for pid");
-is($?, 0, "Return status is 0");
-
-# Again but using helper function
-
-$pid = Lintian::Command::Simple::background("true");
-cmp_ok($pid, '>', 0, 'Basic background (true), take two');
-
-is(Lintian::Command::Simple::wait($pid), 0, "Waiting and checking return status");
-is(waitpid($pid, 0), -1, "Process was really reaped");
diff --git a/t/scripts/Lintian/Command/Simple/03-multiple-jobs.t b/t/scripts/Lintian/Command/Simple/03-multiple-jobs.t
new file mode 100644
index 0000000..0cefb02
--- /dev/null
+++ b/t/scripts/Lintian/Command/Simple/03-multiple-jobs.t
@@ -0,0 +1,55 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 22;
+
+use Lintian::Command::Simple qw(background wait_any);
+
+my $cmd;
+my $c = 4;
+my %jobs;
+
+while ($c) {
+    my $pid = background ('sleep', 1);
+    $jobs{$pid} = 'value';
+    $c--;
+}
+
+while ( my $value = wait_any (\%jobs)) {
+    is ($?, 0, 'One job terminated successfully');
+    is ($value, 'value', 'wait_any returned the value');
+    $c++;
+}
+
+is($c, 4, "4 jobs were started, 4 reaped");
+
+# again, but in list context
+
+while ($c) {
+    my $pid = background ('sleep', 1);
+    $jobs{$pid} = "value $pid";
+    $c--;
+}
+
+while ( my ($pid, $value) = wait_any (\%jobs)) {
+    is ($?, 0, "Pid $pid terminated successfully");
+    is ($value, "value $pid", 'wait_any returned the right value');
+    $c++;
+}
+
+is($c, 4, "4 more jobs were started, 4 reaped");
+
+# Make sure the case of an empty hash is handled properly
+# (i.e. undef is returned and no process is reaped)
+
+%jobs = ();
+my $pid = background("true");
+is (wait_any (\%jobs), undef, 'With an empty hash ref, wait() returns undef');
+
+is (my @list = wait_any (\%jobs), 0,
+   'With an empty hash ref, in list context wait() returns null');
+
+is (waitpid ($pid, 0), $pid, 'Reap successful');
+is ($?, 0, 'Child returned successfully');
+
diff --git a/t/scripts/Lintian/Command/Simple/04-OO-background.t b/t/scripts/Lintian/Command/Simple/04-OO-background.t
deleted file mode 100644
index 56c48bd..0000000
--- a/t/scripts/Lintian/Command/Simple/04-OO-background.t
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 6;
-
-use Lintian::Command::Simple;
-
-my ($cmd, $pid);
-
-$cmd = Lintian::Command::Simple->new();
-
-$pid = $cmd->background("true");
-
-cmp_ok($pid, '>', 0, 'Basic background (true)');
-is(waitpid($pid, 0), $pid, "Waiting for pid");
-is($?, 0, "Return status is 0");
-
-# Again but using helper function
-
-$cmd = Lintian::Command::Simple->new();
-$pid = $cmd->background("true");
-
-cmp_ok($pid, '>', 0, 'Basic background (true), take two');
-is($cmd->wait(), 0, "Waiting and checking return status");
-is(waitpid($pid, 0), -1, "Process was really reaped");
diff --git a/t/scripts/Lintian/Command/Simple/04-kill-multiple-jobs.t b/t/scripts/Lintian/Command/Simple/04-kill-multiple-jobs.t
new file mode 100644
index 0000000..a280a8d
--- /dev/null
+++ b/t/scripts/Lintian/Command/Simple/04-kill-multiple-jobs.t
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+use Lintian::Command::Simple qw(background kill_all wait_any);
+
+my $c = 4;
+my %jobs;
+
+while ($c) {
+    my $pid = background ('sleep', 10);
+    $jobs{$pid} = $1;
+    $c--;
+}
+
+is(kill_all (\%jobs), 4, '4 jobs were killed');
+
+is(wait_any (\%jobs), undef, 'kill(hashref) kills and reaps');
diff --git a/t/scripts/Lintian/Command/Simple/05-OO-errors.t b/t/scripts/Lintian/Command/Simple/05-OO-errors.t
deleted file mode 100644
index 4cd5f40..0000000
--- a/t/scripts/Lintian/Command/Simple/05-OO-errors.t
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 17;
-
-use Lintian::Command::Simple;
-
-my ($cmd, $pid);
-
-# Run a command via the procedural interface and make sure calling the
-# OO's interface wait() doesn't reap it (because the OO interface
-# should only deal with any command started with it)
-
-$pid = Lintian::Command::Simple::background("true");
-
-$cmd = Lintian::Command::Simple->new();
-
-is($cmd->wait(), -1, "No job via OO interface, wait() returns -1");
-
-is(Lintian::Command::Simple::wait($pid), 0, "Checking \$? of the started child");
-
-# Run two commands in a row on the same object, without wait()ing
-
-$cmd = Lintian::Command::Simple->new();
-
-cmp_ok($cmd->background("true"), '>', 0, 'Running one job is ok');
-is($cmd->background("false"), -1, 'Running a second job is not');
-
-is($cmd->wait(), 0, "We wait() for the 'true' job");
-is(Lintian::Command::Simple::wait(), -1, "No other job is running");
-
-# Run two commands in a row on the same object, wait()ing
-
-$cmd = Lintian::Command::Simple->new();
-
-cmp_ok($cmd->background("true"), '>', 0, 'Running one job is ok');
-is($cmd->wait(), 0, "We wait() for the 'true' job");
-
-cmp_ok($cmd->background("false"), '>', 0, 'Running a second job is ok after wait()ing');
-is($cmd->wait(), 1, "We wait() for the 'true' job");
-
-# Just like the above cases, but combining a background and an exec
-
-$cmd = Lintian::Command::Simple->new();
-
-cmp_ok($cmd->background("true"), '>', 0, 'Running one job is ok');
-is($cmd->run("false"), -1, 'Running exec() before wait()ing is not');
-
-is($cmd->wait(), 0, "We wait() for the 'true' job");
-
-# It can happen that a pid-less call to wait() reaps a job started by
-# an instance of the object. Make sure this case is handled nicely.
-
-$cmd = Lintian::Command::Simple->new();
-
-$cmd->background("true");
-
-is(wait(), $cmd->pid, 'Another wait() call reaps an OO job');
-
-is($cmd->wait(), -1, "We only know the job is gone, no return status");
-
-# But it was reaped anyway, so make sure it is possible to start
-# another job via the same object.
-
-cmp_ok($cmd->background("true"), '>', 0, 'Running a second job is ok after foreign wait()');
-is($cmd->wait(), 0, "We wait() for the 'true' job");
diff --git a/t/scripts/Lintian/Command/Simple/06-return-status.t b/t/scripts/Lintian/Command/Simple/06-return-status.t
deleted file mode 100644
index 91b00aa..0000000
--- a/t/scripts/Lintian/Command/Simple/06-return-status.t
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 1;
-
-use Lintian::Command::Simple;
-
-my $pid;
-
-$pid = Lintian::Command::Simple::background("false");
-
-is(Lintian::Command::Simple::wait($pid), 1, "Waiting with pid and checking return status");
-
diff --git a/t/scripts/Lintian/Command/Simple/07-OO-other-methods.t b/t/scripts/Lintian/Command/Simple/07-OO-other-methods.t
deleted file mode 100644
index fd563c6..0000000
--- a/t/scripts/Lintian/Command/Simple/07-OO-other-methods.t
+++ /dev/null
@@ -1,51 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 10;
-
-use Lintian::Command::Simple;
-
-my ($cmd, $pid);
-
-$cmd = Lintian::Command::Simple->new();
-
-# pid():
-
-is($cmd->pid(), undef, 'pid() returns undef without background()');
-
-$pid = $cmd->background("true");
-is($cmd->pid(), $pid, 'pid() returns PID after background()');
-
-$cmd->wait();
-
-is($cmd->pid(), undef, 'pid() returns undef after wait()');
-
-# status():
-
-$cmd = Lintian::Command::Simple->new();
-
-is($cmd->status(), undef, 'status() returns undef without background()');
-
-$cmd->background("true");
-is($cmd->status(), undef, 'status() returns undef without wait()');
-
-$cmd->wait();
-
-is($cmd->status(), 0, 'status() is 0 after wait()');
-
-$cmd->background("false");
-is($cmd->status(), undef, 'status() returns undef after another background()');
-
-$cmd->wait();
-
-is($cmd->status(), 1, 'status() is 1 after wait()');
-
-# status() with run()
-
-$cmd = Lintian::Command::Simple->new();
-
-$cmd->run("true");
-is($cmd->status(), 0, "status() returns 0 for run(true)");
-$cmd->run("false");
-is($cmd->status(), 1, "status() returns 1 for run(false)");
diff --git a/t/scripts/Lintian/Command/Simple/08-multiple-jobs.t b/t/scripts/Lintian/Command/Simple/08-multiple-jobs.t
deleted file mode 100644
index 21977b6..0000000
--- a/t/scripts/Lintian/Command/Simple/08-multiple-jobs.t
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 13;
-
-use Lintian::Command::Simple;
-
-my $cmd;
-my $c = 4;
-my %jobs;
-
-while ($c) {
-    $cmd = Lintian::Command::Simple->new();
-    $cmd->background("sleep", 1);
-    $jobs{$cmd->pid} = $cmd;
-    $c--;
-}
-
-while ($cmd = Lintian::Command::Simple::wait(\%jobs)) {
-    is($cmd->status(), 0, "One job terminated successfully");
-    $c++;
-}
-
-is($c, 4, "4 jobs were started, 4 reaped");
-
-# again, but in list context
-
-while ($c) {
-    $cmd = Lintian::Command::Simple->new();
-    $cmd->background("sleep", 1);
-    $jobs{$cmd->pid} = $cmd;
-    $c--;
-}
-
-my $pid;
-while (($pid, $cmd) = Lintian::Command::Simple::wait(\%jobs)) {
-    is($cmd->status(), 0, "Pid $pid terminated successfully");
-    $c++;
-}
-
-is($c, 4, "4 more jobs were started, 4 reaped");
-
-# Make sure the case of an empty hash is handled properly
-# (i.e. undef is returned and no process is reaped)
-
-%jobs = ();
-$pid = Lintian::Command::Simple::background("true");
-is(Lintian::Command::Simple::wait(\%jobs), undef,
-    "With an empty hash ref, wait() returns undef");
-
-is(Lintian::Command::Simple::wait($pid), 0,
-    "With a pid, wait() does reap");
-
-# Again but now in list context
-
-%jobs = ();
-$pid = Lintian::Command::Simple::background("true");
-is(my @list = Lintian::Command::Simple::wait(\%jobs), 0,
-    "With an empty hash ref, in list context wait() returns null");
-
-
diff --git a/t/scripts/Lintian/Command/Simple/09-kill.t b/t/scripts/Lintian/Command/Simple/09-kill.t
deleted file mode 100644
index dc1654c..0000000
--- a/t/scripts/Lintian/Command/Simple/09-kill.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 2;
-
-use Lintian::Command::Simple;
-
-my $pid;
-
-$pid = Lintian::Command::Simple::background("sleep", 10);
-
-is(Lintian::Command::Simple::kill($pid), 1, "One job was killed");
-
-is(Lintian::Command::Simple::wait($pid), 0, "The job was reaped");
diff --git a/t/scripts/Lintian/Command/Simple/10-OO-kill.t b/t/scripts/Lintian/Command/Simple/10-OO-kill.t
deleted file mode 100644
index 9a814f9..0000000
--- a/t/scripts/Lintian/Command/Simple/10-OO-kill.t
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 2;
-
-use Lintian::Command::Simple;
-
-my ($cmd, $pid);
-
-$cmd = Lintian::Command::Simple->new();
-
-$cmd->background("sleep", 10);
-
-is($cmd->kill(), 1, "One process was killed");
-is($cmd->wait(), 0, "One process was reaped");
diff --git a/t/scripts/Lintian/Command/Simple/11-kill-multiple-jobs.t b/t/scripts/Lintian/Command/Simple/11-kill-multiple-jobs.t
deleted file mode 100644
index d11b66b..0000000
--- a/t/scripts/Lintian/Command/Simple/11-kill-multiple-jobs.t
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-use Test::More tests => 2;
-
-use Lintian::Command::Simple;
-
-my $cmd;
-my $c = 4;
-my %jobs;
-
-while ($c) {
-    $cmd = Lintian::Command::Simple->new();
-    $cmd->background("sleep", 10);
-    $jobs{$c} = $cmd;
-    $c--;
-}
-
-is(Lintian::Command::Simple::kill(\%jobs), 4, "4 jobs were killed");
-
-is(Lintian::Command::Simple::wait(\%jobs), undef,
-	"kill(hashref) kills and reaps");

-- 
Debian package checker


Reply to: