Skip to content

Commit

Permalink
Item13897: All basic tests are passing...
Browse files Browse the repository at this point in the history
... except for SeleniumConfigTests.

- Unified TOC macro calling syntax to match all other macros and make it
callable through execMacro().

- execMacro() can now accept additional arguments to pass them over to the
macro being called.

- Incorporated a fix to Request from the master.
  • Loading branch information
vrurg committed Jun 30, 2016
1 parent 69fe715 commit a6db13d
Show file tree
Hide file tree
Showing 25 changed files with 397 additions and 218 deletions.
41 changes: 23 additions & 18 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -11,11 +11,12 @@ script that runs testcases.
=cut

use Devel::Symdump();
use File::Spec();
use Try::Tiny;
use Unit::TestCase;
use Foswiki::Exception ();
use Unit::Eavesdrop ();
use Devel::Symdump ();
use File::Spec ();

use Moo;
use namespace::clean;
Expand All @@ -24,7 +25,7 @@ extends 'Foswiki::Object';

use Assert;

sub CHECKLEAK { 0 }
sub CHECKLEAK { 0 || $ENV{FOSWIKI_CHECKLEAK} }

BEGIN {
if (CHECKLEAK) {
Expand Down Expand Up @@ -424,7 +425,7 @@ sub runOneInNewProcess {
"-worker", $suite,, $testToRun, $tempfilename
);
my $command = join( ' ', @command );
print "Running: $command\n";
print "RUNNING AS PROCESS: $command\n";

$ENV{PATH} =~ /(.*)/;
$ENV{PATH} = $1; # untaint
Expand Down Expand Up @@ -498,13 +499,12 @@ DIE
$tempfilename = $1;

my $suite = $testSuiteModule;
eval "use $suite";
die $@ if $@;

Foswiki::load_package($suite);

my $tester = $suite->new( testSuite => $suite );

my $log = "stdout.$$.log";
require Unit::Eavesdrop;
open( my $logfh, ">", $log ) || die $!;
print STDERR "Logging to $log\n";
my $stdout = new Unit::Eavesdrop('STDOUT');
Expand All @@ -518,17 +518,22 @@ DIE
my $action = __PACKAGE__->runOne( $tester, $suite, $testToRun );

{
local $SIG{__WARN__} = sub { die $_[0]; };
eval { close $logfh; };
if ($@) {
if ( $@ =~ /Bad file descriptor/ and $suite eq 'EngineTests' ) {

# This is expected - ignore it
}
else {

# propagate the error
die $@;
local $SIG{__WARN__} = sub {
my $e = shift;
Foswiki::Exception::Fatal->rethrow($e);
};
try {
close $logfh;
}
catch {
my $e = Foswiki::Exception::Fatal->transmute( $_, 0 );
my $errmsg = $e->stringify;
unless ($errmsg =~ /Bad file descriptor/
and $suite eq 'EngineTests' )
{

# Expected for EngineTests - ignore it. Otherwise – rethrow.
$e->rethrow;
}
}
}
Expand Down
26 changes: 16 additions & 10 deletions UnitTestContrib/test/unit/Fn_SEARCH.pm
Expand Up @@ -51,6 +51,9 @@ our $AElig;
around set_up => sub {
my $orig = shift;
my ($this) = shift;

$this->app->cfg->data->{DisableAllPlugins} = 1;

$orig->( $this, @_ );

my $timestamp = time();
Expand Down Expand Up @@ -1482,7 +1485,6 @@ sub test_nofinalnewline {

sub test_formatted_search_summary_with_exclamation_marks {
my $this = shift;
my $app = $this->app;

$this->set_up_for_formatted_search();
my $actual, my $expected;
Expand Down Expand Up @@ -1510,7 +1512,6 @@ sub test_formatted_search_summary_with_exclamation_marks {
# Item8718
sub test_formatted_search_with_exclamation_marks_inside_bracket_link {
my $this = shift;
my $app = $this->app;

$this->set_up_for_formatted_search();
my $actual, my $expected;
Expand Down Expand Up @@ -1589,7 +1590,6 @@ sub test_format_displayed_value {

sub test_METASEARCH {
my $this = shift;
my $app = $this->app;

$this->set_up_for_formatted_search();
my $actual, my $expected;
Expand Down Expand Up @@ -2755,7 +2755,6 @@ sub verify_getTopicList {

sub verify_casesensitivesetting {
my $this = shift;
my $app = $this->app;

my $actual, my $expected;

Expand Down Expand Up @@ -4088,16 +4087,22 @@ Number of topics: 4
CRUD

# Now we create the WikiGuest user topic, to test both outputs
my $app = $this->app;
if ( !$app->store->topicExists( 'TemporarySEARCHUsersWeb', 'WikiGuest' ) ) {
if (
!$this->app->store->topicExists(
'TemporarySEARCHUsersWeb', 'WikiGuest'
)
)
{
my ($userTopic) =
Foswiki::Func::readTopic( 'TemporarySEARCHUsersWeb', 'WikiGuest' );
$userTopic->text('Just this poor old WikiGuest');
$userTopic->save();
undef $userTopic;
}
$this->assert(
$app->store->topicExists( 'TemporarySEARCHUsersWeb', 'WikiGuest' ),
$this->app->store->topicExists(
'TemporarySEARCHUsersWeb', 'WikiGuest'
),
'Failed to create user topic in TemporarySEACHUsersWeb'
);

Expand Down Expand Up @@ -6813,10 +6818,11 @@ HERE
$this->createNewFoswikiApp(
requestParams => { initializer => '', },
engineParams => {
initialAttributes =>
{ path_info => "/$test_web/" . $this->test_topic, },
initialAttributes => {
path_info => "/$test_web/" . $this->test_topic,
user => $this->app->cfg->data->{AdminUserLogin},
},
},
user => $this->app->cfg->data->{AdminUserLogin},
);
$this->assert_str_equals( $this->test_web, $this->app->request->web );
while ( my ( $fwaddress, $metatext ) = each %topics ) {
Expand Down
2 changes: 2 additions & 0 deletions UnitTestContrib/test/unit/Fn_TOPICLIST.pm
Expand Up @@ -23,6 +23,8 @@ around set_up => sub {
my $orig = shift;
my $this = shift;

$this->app->cfg->data->{DisableAllPlugins} = 1;

$orig->( $this, @_ );
$Foswiki::cfg{EnableHierarchicalWebs} = 1;
my $webObject = $this->populateNewWeb( $this->test_web . "/SubWeb" );
Expand Down
9 changes: 7 additions & 2 deletions UnitTestContrib/test/unit/Fn_USERINFO.pm
Expand Up @@ -108,7 +108,8 @@ sub test_antispam {
$Foswiki::cfg{AntiSpam}{HideUserDetails} = 1;

# ScumBag should only see his own information
$this->createNewFoswikiApp( user => "ScumBag" );
$this->createNewFoswikiApp(
engineParams => { initialAttributes => { user => "ScumBag" }, }, );
my $ui = $this->test_topicObject->expandMacros(<<"HERE");
%USERINFO{"ScumBag" format="$testformat"}%
HERE
Expand Down Expand Up @@ -139,7 +140,11 @@ HERE

# Admin user should see everything
$this->createNewFoswikiApp(
user => $this->app->cfg->data->{AdminUserLogin} );
engineParams => {
initialAttributes =>
{ user => $this->app->cfg->data->{AdminUserLogin}, },
},
);
$ui = $this->test_topicObject->expandMacros(<<"HERE");
%USERINFO{"ScumBag" format="$testformat"}%
HERE
Expand Down
15 changes: 14 additions & 1 deletion UnitTestContrib/test/unit/FormDefTests.pm
Expand Up @@ -13,6 +13,15 @@ extends qw( FoswikiFnTestCase );

use Assert;

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

$this->app->cfg->data->{DisableAllPlugins} = 1;

$orig->( $this, @_ );
};

sub test_minimalForm {
my $this = shift;

Expand Down Expand Up @@ -338,7 +347,11 @@ sub test_Item10987_formObjClass {
my ($this) = @_;

$this->createNewFoswikiApp(
user => $this->app->cfg->data->{AdminUserWikiName} );
engineParams => {
initialAttributes =>
{ user => $this->app->cfg->data->{AdminUserWikiName}, },
},
);
my $formObj =
Foswiki::Form->loadCached( $this->app, $Foswiki::cfg{SystemWebName},
'UserForm' );
Expand Down
9 changes: 6 additions & 3 deletions UnitTestContrib/test/unit/FormattingTests.pm
Expand Up @@ -225,8 +225,7 @@ around set_up => sub {
my $orig = shift;
my $this = shift;

$| = 1;

$this->app->cfg->data->{DisableAllPlugins} = 1;
$orig->( $this, @_ );
$this->sup( $this->app->cfg->getScriptUrl( 0, 'view' ) );
my ($topicObject) = Foswiki::Func::readTopic( $this->test_web, 'H_' );
Expand Down Expand Up @@ -1909,7 +1908,11 @@ sub _create_link_test_fixtures {
$this->_create_topic( $this->test_web, 'Aa' );
$this->_create_topic( $this->test_web, 'AA' );
$this->createNewFoswikiApp(
user => $this->app->cfg->data->{AdminUserLogin} );
engineParams => {
initialAttributes =>
{ user => $this->app->cfg->data->{AdminUserLogin}, },
},
);
Foswiki::Func::createWeb('Aa');
$this->_create_topic( 'Aa', 'Bb' );
Foswiki::Func::createWeb('AA');
Expand Down
17 changes: 13 additions & 4 deletions UnitTestContrib/test/unit/FoswikiStoreTestCase.pm
Expand Up @@ -8,6 +8,7 @@ use utf8;
#
# Subclasses are expected to implement set_up_for_verify()
#
use Foswiki::Exception ();
use File::Spec();
use Try::Tiny;

Expand Down Expand Up @@ -55,7 +56,7 @@ around set_up => sub {
my $orig = shift;
my $this = shift;
$orig->( $this, @_ );
$Foswiki::cfg{EnableHierarchicalWebs} = 1;
$this->app->cfg->data->{EnableHierarchicalWebs} = 1;

# Data for attachments
$this->t_data( join( '', map( chr($_), ( 0 .. 255 ) ) ) );
Expand Down Expand Up @@ -97,14 +98,22 @@ sub fixture_groups {
next unless $alg =~ s/^(.*)\.pm$/$1/;
next if $alg =~ m/RcsWrap/ && !$this->rcs_installed;
($alg) = $alg =~ m/^(.*)$/ms; # untaint
Foswiki::load_package("Foswiki::Store::$alg");
my $module = "Foswiki::Store::$alg";
try {
Foswiki::load_package($module);
}
catch {
my $errmsg = Foswiki::Exception::errorStr(
Foswiki::Exception::Fatal->transmute( $_, 0 ) );
say STDERR "Skipping ", $module,
" because of the error: ", $errmsg;
};
my $algname = $alg;
next if defined &{$algname};
no strict 'refs';
*{$algname} = sub {
my $self = shift;
$Foswiki::cfg{Store}{Implementation} =
'Foswiki::Store::' . $alg;
$Foswiki::cfg{Store}{Implementation} = $module;
$self->set_up_for_verify();
};
use strict 'refs';
Expand Down
33 changes: 21 additions & 12 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -783,18 +783,19 @@ s/((\$Foswiki::cfg\{.*?\})\s*=.*?;)(?:\n|$)/push(@moreConfig, $1) unless (eval "
# Force completion of %Foswiki::cfg
# This must be done before moving the logging.
$cfgData->{Store}{Implementation} = 'Foswiki::Store::PlainFile';
$this->pushApp;
my $tmp = Unit::TestApp->new(
user => undef,
env => $this->app->cloneEnv,
cfg => $this->app->cfg->clone,
);
ASSERT( $tmp->cfg->app == $tmp,
"Object app attr doesn't point to the new app" );
ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS;
undef $tmp; # finish() will be called automatically.
ASSERT( !defined $Foswiki::app ) if SINGLE_SINGLETONS;
$this->popApp;

#$this->pushApp;
#my $tmp = Unit::TestApp->new(
# user => undef,
# env => $this->app->cloneEnv,
# cfg => $this->app->cfg->clone,
#);
#ASSERT( $tmp->cfg->app == $tmp,
# "Object app attr doesn't point to the new app" );
#ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS;
#undef $tmp; # finish() will be called automatically.
#ASSERT( !defined $Foswiki::app ) if SINGLE_SINGLETONS;
#$this->popApp;

# Note this does not do much, except for some tests that use it directly.
# The first call to File::Temp caches the temp directory name, so
Expand Down Expand Up @@ -1107,6 +1108,12 @@ sub createNewFoswikiApp {
$this->app($app);
$this->_fixupAppObjects;

# WorkDir is set to _tempDir but _tempDir might be cleaned up before $app
# gets completely shutdown. This draws some app frameworks to fail upon
# cleanup as they rely upon WorkDir. By storing the _tempDir object on app's
# heap we let them shutdown cleanly.
$app->heap->{TestCase_TempDir} = $this->_tempDir;

ASSERT( defined $Foswiki::app ) if SINGLE_SINGLETONS;

if ( $this->test_web && $this->test_topic ) {
Expand Down Expand Up @@ -1255,6 +1262,7 @@ sub _fixupAppObjects {

sub pushApp {
my $this = shift;
my %params;

my $holderObj = $this->localize(@_);

Expand All @@ -1270,6 +1278,7 @@ sub popApp {
pop @{ $this->_holderStack };

$Foswiki::app = $this->app;

$this->app->cfg->_setupGLOBs;
$this->_fixupAppObjects;
}
Expand Down

0 comments on commit a6db13d

Please sign in to comment.