Skip to content

Commit

Permalink
Item13897: Bugfixes and more tests are passing.
Browse files Browse the repository at this point in the history
Tests are passing up to including FormDefTests.

- Converted Foswiki::Form::* classes cluster.

- Fixed an annoying bug in Foswiki::Form::getFields() caused by recursive
Form load when a field default value is using %SEARCH which is referring
back to the same form. SEARCH expansion then tries to refer to non-existing
yet fields attribute.

- Finished conversion of testing engine.
  • Loading branch information
vrurg committed Feb 14, 2016
1 parent 63ebdfa commit 613f64d
Show file tree
Hide file tree
Showing 22 changed files with 606 additions and 641 deletions.
9 changes: 8 additions & 1 deletion UnitTestContrib/lib/Unit/TestCase.pm
@@ -1,5 +1,6 @@
# See bottom of file for license and copyright
package Unit::TestCase;
use v5.14;

=begin TML
Expand All @@ -16,6 +17,7 @@ use Carp;
use Unit::HTMLDiffer;
use Unit::TestRunner();
use Foswiki::Exception ();
use Text::Diff ();
require File::Temp;

use Moo;
Expand Down Expand Up @@ -78,6 +80,11 @@ has _tempDir => (
},
handles => { tempDir => 'dirname', },
);
has verify_permutations => (
is => 'rw',
lazy => 1,
default => sub { {} },
);

=begin TML
Expand Down Expand Up @@ -240,7 +247,7 @@ SUB

# NOTE vrurg Check where it's been used and replace with
# attribute notation.
$this->{verify_permutations}{$fn} = $suite . '::' . $verify;
$this->verify_permutations->{$fn} = $suite . '::' . $verify;
}
}
pop( @{$setups} );
Expand Down
87 changes: 47 additions & 40 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -50,6 +50,8 @@ has verify_permutations => (
);
has failures => (
is => 'rw',
lazy => 1,
clearer => 1,
default => sub { return []; },
);
has number_of_asserts => (
Expand Down Expand Up @@ -80,6 +82,12 @@ has annotations => (
is => 'rw',
default => sub { return {}; },
);
has initialINC => (
is => 'rw',
lazy => 1,
clearer => 1,
default => sub { [@INC] },
);

# Print without risking a "wide char in print" error
sub safe_print {
Expand All @@ -89,8 +97,8 @@ sub safe_print {
sub start {
my $this = shift;
my @files = @_;
@{ $this->{failures} } = ();
@{ $this->{initialINC} } = @INC;
$this->clear_failures;
$this->clear_initialINC;
my $passes = 0;

my ($start_cwd) = Cwd->cwd() =~ m/^(.*)$/;
Expand Down Expand Up @@ -170,7 +178,7 @@ sub start {
next if @found;
}
print "*** Failed to use $suite: $useError";
$this->{failed_suites}{$suite} = $useError;
$this->failed_suites->{$suite} = $useError;
next;
}
print "Running $suite\n";
Expand Down Expand Up @@ -226,59 +234,59 @@ sub start {
my $actual_incorrect;
my $total;

if ( my $failed = scalar @{ $this->{failures} } ) {
if ( my $failed = scalar @{ $this->failures } ) {

print "\n$failed failure" . ( $failed > 1 ? 's' : '' ) . ":\n";
safe_print
join( "\n---------------------------\n", @{ $this->{failures} } ),
join( "\n---------------------------\n", @{ $this->failures } ),
"\n";
$actual_incorrect_failures = $failed;
}
if ( my $failed = scalar @{ $this->{unexpected_passes} } ) {
if ( my $failed = scalar @{ $this->unexpected_passes } ) {

# Redundant displaying this in addition to the module failure summary.
#print "\n$failed unexpected pass" . ( $failed > 1 ? 'es' : '' ) . ":\n\t";
#print join( "\n\t", @{ $this->{unexpected_passes} } );
$actual_incorrect_passes = $failed;
}
if ( my $skipped_tests =
scalar( map { keys %{$_} } values %{ $this->{skipped_tests} } ) )
scalar( map { keys %{$_} } values %{ $this->skipped_tests } ) )
{
print "\n$skipped_tests skipped:\n";
while ( my ( $suite, $tests ) = each %{ $this->{skipped_tests} } ) {
while ( my ( $suite, $tests ) = each %{ $this->skipped_tests } ) {
my $ntests = scalar( keys %{$tests} );

print
"$suite skipped $ntests (of $this->{tests_per_module}{$suite}):\n";
print "$suite skipped $ntests (of ",
$this->tests_per_module->{$suite}, "):\n";
while ( my ( $test, $reason ) = each %{$tests} ) {
safe_print " * $test - $reason\n";
}
}
$skipped_tests_total = $skipped_tests;
}
if ( my $skipped_suites = scalar( keys %{ $this->{skipped_suites} } ) ) {
if ( my $skipped_suites = scalar( keys %{ $this->skipped_suites } ) ) {
print "\n$skipped_suites skipped suite"
. ( $skipped_suites > 1 ? 's' : '' ) . ":\n";
while ( my ( $suite, $detail ) = each %{ $this->{skipped_suites} } ) {
while ( my ( $suite, $detail ) = each %{ $this->skipped_suites } ) {
safe_print " * $suite ($detail->{tests}) - $detail->{reason}\n";
$skipped_tests_total += $detail->{tests};
}
}
if ( my $failed_suites = scalar( keys %{ $this->{failed_suites} } ) ) {
while ( my ( $suite, $detail ) = each %{ $this->{failed_suites} } ) {
if ( my $failed_suites = scalar( keys %{ $this->failed_suites } ) ) {
while ( my ( $suite, $detail ) = each %{ $this->failed_suites } ) {
$actual_incorrect_failures += 1;
}
}
if ( my $failed =
scalar( map { keys %{$_} } values %{ $this->{expected_failures} } ) )
scalar( map { keys %{$_} } values %{ $this->expected_failures } ) )
{
print "\n$failed expected failure" . ( $failed > 1 ? 's' : '' ) . ":\n";
while ( my ( $suite, $tests ) = each %{ $this->{expected_failures} } ) {
while ( my ( $suite, $tests ) = each %{ $this->expected_failures } ) {
my $ntests = scalar( keys %{$tests} );

print "$suite has $ntests expected failure"
. ( $ntests > 1 ? 's' : '' )
. " (of $this->{tests_per_module}{$suite}):\n";
. " (of ", $this->tests_per_module->{$suite}, "):\n";
while ( my ( $test, $reason ) = each %{$tests} ) {
my @annotations = $this->get_annotations($test);

Expand Down Expand Up @@ -310,36 +318,35 @@ sub start {
----------------------------
---++ Module Failure summary
HERE
if ( my $failed_suites = scalar( keys %{ $this->{failed_suites} } ) ) {
if ( my $failed_suites = scalar( keys %{ $this->failed_suites } ) ) {
print "\n$failed_suites suite"
. ( $failed_suites > 1 ? 's' : '' )
. " FAILED to compile at all:\n";
while ( my ( $suite, $detail ) = each %{ $this->{failed_suites} } )
{
while ( my ( $suite, $detail ) = each %{ $this->failed_suites } ) {
$detail = substr( $detail, 0, 50 ) . '...';
safe_print " * F: $suite - $detail\n";
}
}
foreach my $module (
sort {
$this->{unexpected_result}->{$a}
<=> $this->{unexpected_result}->{$b}
} keys( %{ $this->{unexpected_result} } )
$this->unexpected_result->{$a}
<=> $this->unexpected_result->{$b}
} keys( %{ $this->unexpected_result } )
)
{
print "$module has "
. $this->{unexpected_result}{$module}
. $this->unexpected_result->{$module}
. " unexpected results (of "
. $this->{tests_per_module}{$module} . "):\n";
foreach my $test ( sort( @{ $this->{unexpected_passes} } ) ) {
. $this->tests_per_module->{$module} . "):\n";
foreach my $test ( sort( @{ $this->unexpected_passes } ) ) {

# SMELL: we should really re-arrange data structures to
# avoid guessing which module the test belongs to...
if ( $test =~ /^$module\b/ ) {
$this->_print_unexpected_test( $test, 'P' );
}
}
foreach my $test ( sort( @{ $this->{failures} } ) ) {
foreach my $test ( sort( @{ $this->failures } ) ) {
($test) = split( /\n/, $test );

# SMELL: we should really re-arrange data structures to
Expand Down Expand Up @@ -397,10 +404,10 @@ sub runOneInNewProcess {
# Assume all new paths were either unshifted or pushed onto @INC
my @pushedOntoINC = @INC;
my @unshiftedOntoINC = ();
while ( $this->{initialINC}->[0] ne $pushedOntoINC[0] ) {
while ( $this->initialINC->[0] ne $pushedOntoINC[0] ) {
push @unshiftedOntoINC, shift @pushedOntoINC;
}
for my $oneINC ( @{ $this->{initialINC} } ) {
for my $oneINC ( @{ $this->initialINC } ) {
shift @pushedOntoINC if $pushedOntoINC[0] eq $oneINC;
}

Expand Down Expand Up @@ -428,7 +435,7 @@ sub runOneInNewProcess {
unlink $tempfilename;
print "*** Could not spawn new process for $suite: $error\n";
return
'push( @{ $this->{failures} }, "'
'push( @{ $this->failures }, "'
. $suite . '\n'
. quotemeta($error) . '" );';
}
Expand All @@ -438,7 +445,7 @@ sub runOneInNewProcess {
print "*** Error trying to run $suite\n";
unlink $tempfilename;
return
'push( @{ $this->{failures} }, "Process for '
'push( @{ $this->failures }, "Process for '
. $suite
. ' returned '
. $returnCode . '" );';
Expand Down Expand Up @@ -585,17 +592,17 @@ sub runOne {
my $ntests = scalar(@tests);
print "*** Skipping suite $suite ($ntests) - $skip_reason\n";
$action .=
"\$this->{skipped_suites}{'$suite'} = {tests => $ntests, reason => \""
"\$this->skipped_suites->{'$suite'} = {tests => $ntests, reason => \""
. quotemeta($skip_reason) . "\"};";
}
else {
foreach my $test (@tests) {
my $skip = $tester->can('skip') ? $tester->skip($test) : undef;

if ( defined $skip ) {
$action .= "\$this->{skipped_tests}{'$suite'}{'$test'} = \""
$action .= "\$this->skipped_tests->{'$suite'}{'$test'} = \""
. quotemeta($skip) . '";';
$action .= '$this->{tests_per_module}->{\'' . $suite . '\'}++;';
$action .= '$this->tests_per_module->{\'' . $suite . '\'}++;';
print "SKIP\t$test - $skip\n";
}
else {
Expand All @@ -618,16 +625,16 @@ sub runOne {
if DEBUG;
$tester->set_up($test);
$action .=
'$this->{tests_per_module}->{\'' . $suite . '\'}++;';
'$this->tests_per_module->{\'' . $suite . '\'}++;';
$tester->$test();
_finish_singletons() if CHECKLEAK;
$action .= '$passes++;';

if ( $tester->expecting_failure ) {
print "*** Unexpected pass\n";
$action .=
'$this->{unexpected_result}->{\'' . $suite . '\'}++;';
$action .= 'push( @{ $this->{unexpected_passes} }, "'
'$this->unexpected_result->{\'' . $suite . '\'}++;';
$action .= 'push( @{ $this->unexpected_passes }, "'
. quotemeta($test) . '");';
}
}
Expand All @@ -639,13 +646,13 @@ sub runOne {
safe_print "*** ", $exceptionMessage, "\n";
if ( $tester->expecting_failure ) {
$action .=
"\$this->{expected_failures}{'$suite'}{'$test'} = \""
"\$this->expected_failures->{'$suite'}{'$test'} = \""
. quotemeta($exceptionMessage) . '";';
}
else {
$action .=
'$this->{unexpected_result}->{\'' . $suite . '\'}++;';
$action .= 'push( @{ $this->{failures} }, "';
'$this->unexpected_result->{\'' . $suite . '\'}++;';
$action .= 'push( @{ $this->failures }, "';
$action .=
quotemeta($test) . '\\n'
. quotemeta($exceptionMessage) . '" );';
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -43,7 +43,7 @@ around BUILDARGS => sub {
# This test is run in a separate process to be able to reclaim that memory
# after the test is complete.
sub run_in_new_process {
return 0;
return 1;
}

our $AElig;
Expand Down
30 changes: 16 additions & 14 deletions UnitTestContrib/test/unit/Fn_SECTION.pm
@@ -1,20 +1,20 @@
# tests for the correct expansion of SECTION

package Fn_SECTION;
use strict;
use warnings;

use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );
use v5.14;

use Foswiki;
use Error qw( :try );
use Try::Tiny;
use Benchmark qw(:hireswallclock); # test_manysections

sub new {
my $self = shift()->SUPER::new( 'SECTION', @_ );
return $self;
}
use Moo;
use namespace::clean;
extends qw( FoswikiFnTestCase );

around BUILDARGS => sub {
my $orig = shift;
return $orig->( @_, testSuite => 'SECTION' );
};

sub dumpsec {
my $sec = shift;
Expand Down Expand Up @@ -192,8 +192,9 @@ sub test_sections10S {
# For test_manysections, Item10316
sub _manysections_inc {
my ( $this, $section ) = @_;
my ( $test_web, $test_topic ) = ( $this->test_web, $this->test_topic );
my $text = Foswiki::Func::expandCommonVariables(<<"HERE");
%INCLUDE{"$this->{test_web}.$this->{test_topic}" section="$section"}%
%INCLUDE{"$test_web.$test_topic" section="$section"}%
HERE

chomp($text);
Expand Down Expand Up @@ -225,7 +226,7 @@ $junk%${end}INCLUDE% Post-INCLUDEable
%STARTSECTION{"3"}% 3 content %STARTSECTION{"224"}% 2.2.4f continue yet again even more continued content $junk%${end}SECTION{"224"}%$junk%${end}SECTION{"3"}%
HERE
my ($topicObj) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
Foswiki::Func::readTopic( $this->test_web, $this->test_topic );
$topicObj->text($text);
my $c1 = ' 1 content ' . $junk;
my $c21 = ' 2.1 content ' . $junk;
Expand Down Expand Up @@ -303,12 +304,13 @@ sub test_manysections_timing {
my %sections = $this->_manysections_setup('STOP');
my $numsections = scalar( keys %sections );
my $numcycles = 50;
my $benchmark = timeit(
my ( $test_web, $test_topic ) = ( $this->test_web, $this->test_topic );
my $benchmark = timeit(
$numcycles,
sub {
foreach my $section ( keys %sections ) {
Foswiki::Func::expandCommonVariables(<<"HERE");
%INCLUDE{"$this->{test_web}.$this->{test_topic}" section="$section"}%
%INCLUDE{"$test_web.$test_topic" section="$section"}%
HERE
}
}
Expand Down
19 changes: 9 additions & 10 deletions UnitTestContrib/test/unit/Fn_SEP.pm
Expand Up @@ -4,21 +4,20 @@ use strict;

package Fn_SEP;

use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );

use Foswiki;
use Error qw( :try );

sub new {
my $self = shift()->SUPER::new( 'SEP', @_ );
return $self;
}
use Moo;
extends qw( FoswikiFnTestCase );

around BUILDARGS => sub {
my $orig = shift;
return $orig->( @_, testSuite => 'SEP' );
};

sub test_SEP {
my $this = shift;
my $a = $this->{test_topicObject}->expandMacros("%TMPL:P{sep}%");
my $b = $this->{test_topicObject}->expandMacros("%SEP%");
my $a = $this->test_topicObject->expandMacros("%TMPL:P{sep}%");
my $b = $this->test_topicObject->expandMacros("%SEP%");
$this->assert_str_equals( $a, $b );
}

Expand Down

0 comments on commit 613f64d

Please sign in to comment.