From 5b39b20f5f70a6d269029db6cd0dc40b0e85c00a Mon Sep 17 00:00:00 2001 From: PaulHarvey Date: Sat, 16 Jun 2012 13:24:14 +0000 Subject: [PATCH] Item5437: address perlcriticisms which break unicode branch git-svn-id: http://svn.foswiki.org/branches/Release01x01@15003 0b4bb1d4-4e5a-0410-9cc4-b2b747904278 --- .../test/unit/FoswikiStoreTestCase.pm | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm b/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm index 446c56e993..a8a580353b 100644 --- a/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm +++ b/UnitTestContrib/test/unit/FoswikiStoreTestCase.pm @@ -1,12 +1,15 @@ package FoswikiStoreTestCase; +use strict; +use warnings; # Specialisation of FoswikiFnTestCase used to perform tests over all # viable store implementations. # # Subclasses are expected to implement set_up_for_verify() # -use FoswikiFnTestCase; +use FoswikiFnTestCase(); our @ISA = qw( FoswikiFnTestCase ); +use File::Spec(); # Determine if RCS is installed. used in tests for RCS functionality. our $rcs_installed; @@ -14,18 +17,16 @@ our $rcs_installed; sub rcs_is_installed { if ( !defined($rcs_installed) ) { $ENV{PATH} =~ /^(.*)$/ms; - $ENV{PATH} = $1; # untaint - eval { - `co -V`; # Check to see if we have co - }; - if ( $@ || $? ) { + local $ENV{PATH} = $1; # untaint + if ( eval { `co -V`; 1; } ) # Check to see if we have co + { + $rcs_installed = 1; + } + else { $rcs_installed = 0; print STDERR "*** CANNOT RUN RcsWrap TESTS - NO COMPATIBLE co: $@\n"; } - else { - $rcs_installed = 1; - } } return $rcs_installed; } @@ -34,12 +35,16 @@ sub set_up { my $this = shift; $this->SUPER::set_up(); $Foswiki::cfg{EnableHierarchicalWebs} = 1; + + return; } sub tear_down { my $this = shift; $this->SUPER::tear_down(); + + return; } sub set_up_for_verify { @@ -51,27 +56,31 @@ sub fixture_groups { my @groups; foreach my $dir (@INC) { - if ( opendir( D, "$dir/Foswiki/Store" ) ) { - foreach my $alg ( readdir D ) { + my ( $volume, $directories ) = File::Spec->splitpath( $dir, 1 ); + + $directories = File::Spec->catdir( File::Spec->splitdir($directories), + qw(Foswiki Store) ); + if ( + opendir( my $D, File::Spec->catpath( $volume, $directories, '' ) ) ) + { + foreach my $alg ( readdir $D ) { next unless $alg =~ s/^(.*)\.pm$/$1/; next if $alg =~ /RcsWrap/ && !rcs_is_installed(); ($alg) = $alg =~ /^(.*)$/ms; # untaint - eval "require Foswiki::Store::$alg"; - die $@ if $@; + $this->assert( eval "require Foswiki::Store::$alg; 1;" ); my $algname = ref($this) . '_' . $alg; - next if defined &$algname; + next if defined &{$algname}; no strict 'refs'; - *$algname = sub { - my $this = shift; + *{$algname} = sub { + my $self = shift; $Foswiki::cfg{Store}{Implementation} = 'Foswiki::Store::' . $alg; - $this->set_up_for_verify(); + $self->set_up_for_verify(); }; use strict 'refs'; push( @groups, $algname ); - $seen{$alg} = 1; } - closedir(D); + closedir($D); } } # Uncomment below to test one store in isolation