Skip to content

Commit

Permalink
Item13897: Another huge commit, tests are passing up to and includind…
Browse files Browse the repository at this point in the history
… HoistREsTests

- Mostly borning routine convertion to Moo. Processed Render, UI, and Logger
subsystems and some of Foswiki::* classes.

- Fixed the method of checking for RCS co utility in
FoswikiStoreTestCase.pm. The previous method was unreliable and was causing
STDOUT redirection to /dev/null in my case. Now $PATH is manually traversed
and checked agains co executable. Reccommended for porting back to the
master.

- Getting rid of @_newParameters meta-protocol. Avoiding its use in newly
converted classes.

- Getting rid of finish() method whenever possible. DEMOLISH and
auto-destruction is the target.

- Added methods transmute() and rethrowAs() to Foswiki::Exception.
transmute() coerces any passed object into predefined class. rethrowAs uses
this functionality to always rethrow an execption as a specific class. It
differs from rethrow() in the way that latter attempts to preserve the
original exception it rethrows.

- Bugfixes, of course.
  • Loading branch information
vrurg committed Feb 17, 2016
1 parent 613f64d commit 6af4d5c
Show file tree
Hide file tree
Showing 53 changed files with 2,206 additions and 1,981 deletions.
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/FormattingTests.pm
Expand Up @@ -180,7 +180,7 @@ around BUILDARGS => sub {
my $orig = shift;
my $class = shift;

return $orig->( $class, @_, suite => 'Formatting' );
return $orig->( $class, @_, testSuite => 'Formatting' );
};

sub BUILD {
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/FoswikiFnTestCase.pm
Expand Up @@ -253,7 +253,7 @@ sub registerUser {
$this->assert( 0, $e->stringify );
}
elsif ( $e->isa('Foswiki::Exception') ) {
$this->assert( 0, $e->stringify() );
$this->assert( 0, $e->stringify );
}
else {
$this->assert( 0, "expected an oops redirect" );
Expand Down
12 changes: 6 additions & 6 deletions UnitTestContrib/test/unit/FoswikiPmFunctionsTests.pm
@@ -1,16 +1,16 @@
# NOTE: this is a VERY limited subset of subroutines in Foswiki.pm (um, ok, one - moved from ManageDotPmTests..)
package FoswikiPmFunctionsTests;
use v5.14;

use strict;
use warnings;
use diagnostics;

use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );
use diagnostics -verbose;
use Foswiki();
use Foswiki::UI::Manage();
use Foswiki::UI::Save();

use Moo;
use namespace::clean;
extends qw( FoswikiFnTestCase );

sub TRACE { return 0; }

sub test_isValidTopicName_WebHome {
Expand Down
136 changes: 77 additions & 59 deletions UnitTestContrib/test/unit/FoswikiStoreTestCase.pm
@@ -1,61 +1,80 @@
package FoswikiStoreTestCase;
use strict;
use warnings;
use v5.14;

use utf8;

# Specialisation of FoswikiFnTestCase used to perform tests over all
# viable store implementations.
#
# Subclasses are expected to implement set_up_for_verify()
#
use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );
use File::Spec();

# Determine if RCS is installed. used in tests for RCS functionality.
our $rcs_installed;

sub rcs_is_installed {
if ( !defined($rcs_installed) ) {
use Moo;
use namespace::clean;
extends qw( FoswikiFnTestCase );

has t_web => ( is => 'rw', );
has t_web2 => ( is => 'rw', );
has t_topic => ( is => 'rw', );
has t_data => ( is => 'rw', );
has t_data2 => ( is => 'rw', );
has t_datafile => ( is => 'rw', );
has t_datafile2 => ( is => 'rw', );
has t_datapath => ( is => 'rw', );
has t_datapath2 => ( is => 'rw', );
has rcs_installed => (
is => 'rw',
predicate => 1,
lazy => 1,
default => sub {

# Determine if RCS is installed. used in tests for RCS functionality.
my $this = shift;
my $installed = 0;
$ENV{PATH} =~ m/^(.*)$/ms;
local $ENV{PATH} = $1; # untaint
if ( eval { `co --version`; 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";
my @PATH = File::Spec->path;
my $command = 'co';
foreach my $dir (@PATH) {
my $fullName = File::Spec->catfile( $dir, $command );
if ( -x $fullName ) {
my $out = `$fullName --version`;
if ( $out =~ /\bRCS\b/ ) {
return 1;
}
}
}
}
return $rcs_installed;
}
print STDERR "*** CANNOT RUN RcsWrap TESTS - NO COMPATIBLE co\n";
return 0;
},
);

sub set_up {
around set_up => sub {
my $orig = shift;
my $this = shift;
$this->SUPER::set_up();
$orig->( $this, @_ );
$Foswiki::cfg{EnableHierarchicalWebs} = 1;

# Data for attachments
$this->{t_data} = join( '', map( chr($_), ( 0 .. 255 ) ) );
$this->{t_data2} = join( '', map( chr( 255 - $_ ), ( 0 .. 255 ) ) );
return;
}
$this->t_data( join( '', map( chr($_), ( 0 .. 255 ) ) ) );
$this->t_data2( join( '', map( chr( 255 - $_ ), ( 0 .. 255 ) ) ) );
};

sub tear_down {
around tear_down => sub {
my $orig = shift;
my $this = shift;

unlink( $this->{t_datapath} ) if $this->{t_datapath};
unlink( $this->{t_datapath2} ) if $this->{t_datapath2};
$this->removeWeb( $this->{t_web} )
if ( $this->{t_web}
&& $this->{session}->{store}->webExists( $this->{t_web} ) );
$this->removeWeb( $this->{t_web2} )
if ( $this->{t_web2}
&& $this->{session}->{store}->webExists( $this->{t_web2} ) );
$this->SUPER::tear_down();
}
unlink( $this->t_datapath ) if $this->t_datapath;
unlink( $this->t_datapath2 ) if $this->t_datapath2;
$this->removeWeb( $this->t_web )
if ( $this->t_web
&& $this->session->store->webExists( $this->t_web ) );
$this->removeWeb( $this->t_web2 )
if ( $this->t_web2
&& $this->session->store->webExists( $this->t_web2 ) );
$orig->($this);
};

sub set_up_for_verify {
die "ABSTRACT BASE CLASS";
Expand All @@ -75,10 +94,9 @@ sub fixture_groups {
{
foreach my $alg ( readdir $D ) {
next unless $alg =~ s/^(.*)\.pm$/$1/;
next if $alg =~ m/RcsWrap/ && !rcs_is_installed();
next if $alg =~ m/RcsWrap/ && !$this->rcs_installed;
($alg) = $alg =~ m/^(.*)$/ms; # untaint
eval "require Foswiki::Store::$alg;";
$this->assert( !$@, $@ );
Foswiki::load_package("Foswiki::Store::$alg");
my $algname = $alg;
next if defined &{$algname};
no strict 'refs';
Expand Down Expand Up @@ -116,23 +134,23 @@ sub _make_data {
my $FILE;
my $enc = $Foswiki::cfg{Store}{Encoding} || 'utf-8';

$this->{t_datapath} = "$Foswiki::cfg{TempfileDir}/TestAttachData";
$this->{t_datapath2} = "$Foswiki::cfg{TempfileDir}/TestAttachData2";
$this->t_datapath("$Foswiki::cfg{TempfileDir}/TestAttachData");
$this->t_datapath2("$Foswiki::cfg{TempfileDir}/TestAttachData2");

open( $FILE, ">", $this->{t_datapath} );
print $FILE $this->{t_data};
open( $FILE, ">", $this->t_datapath );
print $FILE $this->t_data;
close($FILE);

open( $FILE, ">", $this->{t_datapath2} );
print $FILE $this->{t_data2};
open( $FILE, ">", $this->t_datapath2 );
print $FILE $this->t_data2;
close($FILE);
}

sub open_data {
my ( $this, $k ) = @_;

my $fh;
open( $fh, '<', $this->{$k} );
open( $fh, '<', $this->$k );
return $fh;
}

Expand All @@ -141,13 +159,13 @@ sub utf8 {
$Foswiki::cfg{Site}{Locale} = 'en_US.utf-8';
$Foswiki::cfg{UseLocale} = 1;
undef $Foswiki::cfg{Store}{Encoding};
$this->{t_web} = 'Temporary普通话Web1';
$this->{t_web2} = 'Temporary国语Web2';
$this->{t_topic} = 'Testру́сскийTopic';
$this->{t_datafile} = "Šňá徊ťěř.gif";
$this->{t_datapath} = "$Foswiki::cfg{TempfileDir}/$this->{t_datafile}";
$this->{t_datafile2} = "پښتانهټبرونه.gif";
$this->{t_datapath2} = "$Foswiki::cfg{TempfileDir}/$this->{t_datafile2}";
$this->t_web('Temporary普通话Web1');
$this->t_web2('Temporary国语Web2');
$this->t_topic('Testру́сскийTopic');
$this->t_datafile("Šňá徊ťěř.gif");
$this->t_datapath( "$Foswiki::cfg{TempfileDir}/" . $this->t_datafile );
$this->t_datafile2("پښتانهټبرونه.gif");
$this->t_datapath2( "$Foswiki::cfg{TempfileDir}/" . $this->t_datafile2 );
$this->_make_data();
}

Expand All @@ -162,11 +180,11 @@ sub iso8859 {
join( '', map( chr($_), ( 160 .. 255 ) ) ) );
my $n = $s;
$n =~ s/$Foswiki::cfg{NameFilter}//g;
$this->{t_web} = "Temporary${n}Web1";
$this->{t_web2} = "Temporary${n}Web2";
$this->{t_topic} = "Test${n}Topic";
$this->{t_datafile} = "${n}1.gif";
$this->{t_datafile2} = "${n}2.gif";
$this->t_web("Temporary${n}Web1");
$this->t_web2("Temporary${n}Web2");
$this->t_topic("Test${n}Topic");
$this->t_datafile("${n}1.gif");
$this->t_datafile2("${n}2.gif");
$this->_make_data();
}

Expand Down
9 changes: 5 additions & 4 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -170,11 +170,12 @@ sub skip_test_if {
if ( $this->check_conditions_met( %{ $item->{condition} } ) ) {
my $verify_name = $this->verify_permutations->{$test};

if ( defined $item->tests->{$test} ) {
$skip_reason = $item->tests->{$test};
if ( defined $item->{tests}->{$test} ) {
$skip_reason = $item->{tests}->{$test};
}
elsif ( $verify_name && defined $item->tests->{$verify_name} ) {
$skip_reason = $item->tests->{$verify_name};
elsif ( $verify_name && defined $item->{tests}->{$verify_name} )
{
$skip_reason = $item->{tests}->{$verify_name};
}
}
elsif (TRACE) {
Expand Down

0 comments on commit 6af4d5c

Please sign in to comment.