perl
view release on metacpan or search on metacpan
dist/Devel-PPPort/soak view on Meta::CPAN
#!/usr/bin/perl -w
################################################################################
#
# soak -- Test Perl modules with multiple Perl releases.
#
# Original Author: Paul Marquess
#
################################################################################
#
# Version 3.x, Copyright (C) 2004-2013, Marcus Holland-Moritz.
# Version 2.x, Copyright (C) 2001, Paul Marquess.
# Version 1.x, Copyright (C) 1999, Kenneth Albanowski.
#
# This program is free software; you can redistribute it and/or
# modify it under the same terms as Perl itself.
#
################################################################################
require 5.006001;
use strict;
use warnings;
use ExtUtils::MakeMaker;
use Getopt::Long;
use Pod::Usage;
use File::Find;
use List::Util qw(max);
use Config;
my $VERSION = '3.36';
$| = 1;
my %OPT = (
verbose => 0,
make => $Config{make} || 'make',
min => '5.000',
color => 1,
);
GetOptions(\%OPT, qw(verbose make=s min=s mmargs=s@ color!)) or pod2usage(2);
$OPT{mmargs} = [''] unless exists $OPT{mmargs};
$OPT{min} = parse_version($OPT{min}) - 1e-10;
sub cs($;$$) { my $x = shift; my($s, $p) = @_ ? @_ : ('', 's'); ($x, $x == 1 ? $s : $p) }
my @GoodPerls = map { $_->[0] }
sort { $a->[1] <=> $b->[1] or $a->[0] cmp $b->[0] }
grep { $_->[1] >= $OPT{min} }
map { [$_ => perl_version($_)] }
@ARGV ? SearchPerls(@ARGV) : FindPerls();
unless (@GoodPerls) {
print "Sorry, got no Perl binaries for testing.\n\n";
exit 0;
}
my $maxlen = max(map length, @GoodPerls) + 3;
my $mmalen = max(map length, @{$OPT{mmargs}});
$maxlen += $mmalen+3 if $mmalen > 0;
my $rep = Soak::Reporter->new( verbose => $OPT{verbose}
, color => $OPT{color}
, width => $maxlen
);
$SIG{__WARN__} = sub { $rep->warn(@_) };
$SIG{__DIE__} = sub { $rep->die(@_) };
# prime the pump, so the first "make realclean" will work.
runit("$^X Makefile.PL") && runit("$OPT{make} realclean")
or $rep->die("Cannot run $^X Makefile.PL && $OPT{make} realclean\n");
my $tot = @GoodPerls*@{$OPT{mmargs}};
$rep->set(tests => $tot);
$rep->status(sprintf("Testing %d version%s / %d configuration%s (%d combination%s)...\n",
cs(@GoodPerls), cs(@{$OPT{mmargs}}), cs($tot)));
for my $perl (@GoodPerls) {
for my $mm (@{$OPT{mmargs}}) {
$rep->set(perl => $perl, config => $mm);
$rep->test;
my @warn_mfpl;
my @warn_make;
my @warn_test;
my $ok = runit("$perl Makefile.PL $mm", \@warn_mfpl) &&
runit("$OPT{make}", \@warn_make) &&
runit("$OPT{make} test", \@warn_test);
$rep->warnings(['Makefile.PL' => \@warn_mfpl],
['make' => \@warn_make],
['make test' => \@warn_test]);
if ($ok) {
$rep->passed;
}
else {
$rep->failed;
}
dist/Devel-PPPort/soak view on Meta::CPAN
my @args = @_;
my @perls;
for my $arg (@args) {
if (-d $arg) {
my @found;
print "Searching for Perl binaries in '$arg'...\n";
find({ wanted => sub {
$File::Find::name =~ m!perl5[\w._]+$!
and -f $File::Find::name
and -x $File::Find::name
and perl_version($File::Find::name)
and push @found, $File::Find::name;
}, follow => 1 }, $arg);
printf "Found %d Perl binar%s in '%s'.\n\n", cs(@found, 'y', 'ies'), $arg;
push @perls, @found;
}
else {
push @perls, $arg;
}
}
return @perls;
}
sub perl_version
{
my $perl = shift;
my $ver = `$perl -e 'print \$]' 2>&1`;
return $? == 0 && $ver =~ /^\d+\.\d+/ && $ver >= 5 ? $ver : 0;
}
sub parse_version
{
my $ver = shift;
if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) {
return $1 + 1e-3*$2 + 1e-6*$3;
}
elsif ($ver =~ /^\d+\.[\d_]+$/) {
$ver =~ s/_//g;
return $ver;
}
die "cannot parse version '$ver'\n";
}
package NoSTDOUT;
use Tie::Handle;
our @ISA = qw(Tie::Handle);
sub TIEHANDLE { bless \(my $s = ''), shift }
sub PRINT {}
sub WRITE {}
package Soak::Reporter;
use strict;
sub cs($;$$) { my $x = shift; my($s, $p) = @_ ? @_ : ('', 's'); ($x, $x == 1 ? $s : $p) }
sub new
{
my $class = shift;
bless {
tests => undef,
color => 1,
verbose => 0,
@_,
_cur => 0,
_atbol => 1,
_total => 0,
_good => [],
_bad => [],
}, $class;
}
sub colored
{
my $self = shift;
if ($self->{color}) {
my $c = eval {
require Term::ANSIColor;
Term::ANSIColor::colored(@_);
};
if ($@) {
$self->{color} = 0;
}
else {
return $c;
}
}
return $_[0];
}
sub _config
{
my $self = shift;
return $self->{config} =~ /\S+/ ? " ($self->{config})" : '';
}
sub _progress
{
my $self = shift;
return '' unless defined $self->{tests};
my $tlen = length $self->{tests};
my $text = sprintf "[%${tlen}d/%${tlen}d] ", $self->{_cur}, $self->{tests};
return $self->colored($text, 'bold');
}
sub _test
{
my $self = shift;
return $self->_progress . "Testing "
. $self->colored($self->{perl}, 'blue')
. $self->colored($self->_config, 'green');
}
( run in 0.692 second using v1.01-cache-2.11-cpan-54e63673c56 )