From d58887d50026778218ddf094e1548f134d9eac89 Mon Sep 17 00:00:00 2001 From: Steffen Schwigon Date: Fri, 7 Sep 2012 14:47:21 +0200 Subject: [PATCH] catch errors and handle gracefully --- lib/Benchmark/Perl/Formance/Plugin/P6STD.pm | 6 +++++- lib/Benchmark/Perl/Formance/Plugin/PerlCritic.pm | 5 ++++- lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm | 5 ++++- lib/Benchmark/Perl/Formance/Plugin/Shootout/knucleotide.pm | 6 +++++- lib/Benchmark/Perl/Formance/Plugin/Shootout/regexdna.pm | 6 +++++- lib/Benchmark/Perl/Formance/Plugin/Shootout/revcomp.pm | 6 +++++- lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm | 3 ++- 7 files changed, 30 insertions(+), 7 deletions(-) diff --git a/lib/Benchmark/Perl/Formance/Plugin/P6STD.pm b/lib/Benchmark/Perl/Formance/Plugin/P6STD.pm index 3674867..b70ed41 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/P6STD.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/P6STD.pm @@ -26,7 +26,9 @@ sub prepare { my $dstdir = tempdir( CLEANUP => 1 ); my $cmd; - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/P6STD"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/P6STD" }; + return if $@; + print STDERR "# Make viv in $dstdir ...\n" if $options->{verbose} >= 3; dircopy($srcdir, $dstdir); @@ -71,6 +73,8 @@ sub main { my $makeviv; my $viv; ($workdir, $makeviv ) = prepare($options); + return { failed => "no Benchmark-Perl-Formance-Cargo" } if not $workdir; + $viv = viv($workdir, $options); return { diff --git a/lib/Benchmark/Perl/Formance/Plugin/PerlCritic.pm b/lib/Benchmark/Perl/Formance/Plugin/PerlCritic.pm index 86e67af..8e63565 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/PerlCritic.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/PerlCritic.pm @@ -25,7 +25,8 @@ sub prepare { my ($options) = @_; my $dstdir = tempdir( CLEANUP => 1 ); - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/PerlCritic"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/PerlCritic" }; + return if $@; print STDERR "# Prepare Perl::Critic sources in $dstdir ...\n" if $options->{verbose} >= 3; dircopy($srcdir, $dstdir); @@ -86,6 +87,8 @@ sub main { $count = $options->{fastmode} ? 1 : 2; my ($dstdir) = prepare($options); + return { failed => "no Benchmark-Perl-Formance-Cargo" } if not $dstdir; + return { upstream => upstream ($options, $dstdir), bundled => bundled ($options, $dstdir), diff --git a/lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm b/lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm index c6a6ced..ad7f207 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/RegexpCommonTS.pm @@ -25,7 +25,8 @@ sub prepare { my ($options) = @_; my $dstdir = tempdir( CLEANUP => 1 ); - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/RegexpCommonTS"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/RegexpCommonTS" }; + return if $@; print STDERR "# Prepare cargo RegexpCommon testsuite in $dstdir ...\n" if $options->{verbose} >= 3; @@ -64,6 +65,8 @@ sub main { $recurse = $options->{fastmode} ? "" : "-r"; my ($dstdir, $prove, $recurse) = prepare($options); + return { failed => "no Benchmark-Perl-Formance-Cargo" } if not $dstdir; + return nonaggregated($dstdir, $prove, $recurse, $options); } diff --git a/lib/Benchmark/Perl/Formance/Plugin/Shootout/knucleotide.pm b/lib/Benchmark/Perl/Formance/Plugin/Shootout/knucleotide.pm index 2b0521e..b5a0649 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/Shootout/knucleotide.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/Shootout/knucleotide.pm @@ -42,7 +42,9 @@ sub run $output = ''; $threads = 2*num_cpus() || 1; - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout" }; + return { failed => "no Benchmark-Perl-Formance-Cargo" } if $@; + my $srcfile = "$srcdir/$infile"; open my $INFILE, "<", $srcfile or die "Cannot read $srcfile"; @@ -114,6 +116,8 @@ sub main my $result; my $t = timeit $count, sub { $result = run($goal) }; + return $result if $result->{failed}; + return { Benchmark => $t, goal => $goal, diff --git a/lib/Benchmark/Perl/Formance/Plugin/Shootout/regexdna.pm b/lib/Benchmark/Perl/Formance/Plugin/Shootout/regexdna.pm index 6131365..af5b622 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/Shootout/regexdna.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/Shootout/regexdna.pm @@ -30,7 +30,9 @@ sub run { my ($infile) = @_; - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout" }; + return { failed => "no Benchmark-Perl-Formance-Cargo" } if $@; + my $srcfile = "$srcdir/$infile"; open my $INFILE, "<", $srcfile or die "Cannot read $srcfile"; @@ -101,6 +103,8 @@ sub main my $result; my $t = timeit $count, sub { $result = run($goal) }; + return $result if $result->{failed}; + return { Benchmark => $t, goal => $goal, diff --git a/lib/Benchmark/Perl/Formance/Plugin/Shootout/revcomp.pm b/lib/Benchmark/Perl/Formance/Plugin/Shootout/revcomp.pm index 3b546ba..9e345cb 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/Shootout/revcomp.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/Shootout/revcomp.pm @@ -38,7 +38,9 @@ sub run my $data; - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/Shootout" }; + return { failed => "no Benchmark-Perl-Formance-Cargo" } if $@; + my $srcfile = "$srcdir/$infile"; open my $INFILE, "<", $srcfile or die "Cannot read $srcfile"; @@ -67,6 +69,8 @@ sub main my $result; my $t = timeit $count, sub { $result = run($goal) }; + return $result if $result->{failed}; + return { Benchmark => $t, goal => $goal, diff --git a/lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm b/lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm index a712882..f00dd2f 100644 --- a/lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm +++ b/lib/Benchmark/Perl/Formance/Plugin/SpamAssassin.pm @@ -28,7 +28,8 @@ sub main { $easy_ham = $options->{fastmode} ? "easy_ham_subset" : "easy_ham"; my $dstdir = tempdir( CLEANUP => 1 ); - my $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/SpamAssassin"; + my $srcdir; eval { $srcdir = dist_dir('Benchmark-Perl-Formance-Cargo')."/SpamAssassin" }; + return { salearn => { failed => "no Benchmark-Perl-Formance-Cargo" } } if $@; print STDERR "# Prepare cargo spam'n'ham files in $dstdir ...\n" if $options->{verbose} >= 3;