Skip to content

Commit

Permalink
Item14237: Merge commit '28294f2aef8171f625a535ffd874906da4b0ad82' in…
Browse files Browse the repository at this point in the history
…to Item14237

* commit '28294f2aef8171f625a535ffd874906da4b0ad82':
  Item14152: Added MAT_dump.pl tool to dump content of .pmat files.
  Item14152: Extension deregistration implemented.
  Item14152: Fixed role applying without FOSWIKI_ASSERTS=on
  Item14152: Fixed a problem with applying roles to a failed to compile class.
  Item13897: Additional support for Unit::Leak::Object.
  • Loading branch information
vrurg committed May 20, 2017
2 parents 319e7b6 + 28294f2 commit 7d6d754
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 111 deletions.
16 changes: 8 additions & 8 deletions EmptyExtension/lib/Foswiki/Extension/Empty.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extends qw(Foswiki::Extension);
---++ The Ecosystem
Extensions exists as a list of objects managed by =Foswiki::App= =extensions=
attribute which is actually an object of =Foswiki::Extensions= class. The latter
attribute which is actually an object of =Foswiki::ExtManager= class. The latter
provides API for extension manipulation routines like loading and registering an
extension; registering extension's components like overriding methods or
classes; find an extenion object by name; etc.
Expand All @@ -46,7 +46,7 @@ is a registered =Sample= extension then whenever we a ask for the extension's
object then we can be sure that there is no more than signle active one exists.
This is an important rule for some of [[#ExportedSubs][exported subroutines]].
=Foswiki::Extensions= module has its own =$VERSION= global var. It represents
=Foswiki::ExtManager= module has its own =$VERSION= global var. It represents
%WIKITOOLNAME% API version and is used to check an extension compatibility.
---++ Extensions loading
Expand All @@ -71,7 +71,7 @@ use version 0.77; our $VERSION = version->declare(0.0.1);
our $API_VERSION = version->declare("2.99.0");
</verbatim>
=$API_VERSION= declares the minimal version of =Foswiki::Extensions= module
=$API_VERSION= declares the minimal version of =Foswiki::ExtManager= module
required.
=cut
Expand All @@ -93,7 +93,7 @@ functionality. As such, their use is similar to =CPAN:Moo=
---+++ Extension dependencies
An extension can claim to be located before or after another one in the list of
extension objects (=extensions= attribute of =Foswiki::Extensions= class). This defines
extension objects (=extensions= attribute of =Foswiki::ExtManager= class). This defines
inheritance and callback execution order. I.e., if =Ext2= goes after =Ext1= and
both register a callback handler for =Foswiki::App::postConfig= then =Ext1= handler
will be called first.
Expand All @@ -109,7 +109,7 @@ The following subs implement this functionality:
What these do is define a directed graph of extensions. When all extensions are
loaded and registered the graph gets sorted using topoligical sort. The resulting
order is stored in =Foswiki::Extensions= =orderedList= attribute.
order is stored in =Foswiki::ExtManager= =orderedList= attribute.
The final order of extensions is not guaranteed. For example, =Ext2= could
require to be placed before =Ext1= but it doesn't mean that it will directly
Expand Down Expand Up @@ -167,7 +167,7 @@ tagHandler MYMACRO => 'Foswiki::Extension::Macro::MYMACRO';
it is expected that the class would does =Foswiki::Macro= role. An object of
this class will be created on demand by =Foswiki::Macros=. It won't get any
reference to the extension object. Would the object be needed to expand the
macro then =Foswiki::Extensions= =extObject()= method *must* be used to obtain
macro then =Foswiki::ExtManager= =extObject()= method *must* be used to obtain
the reference.
=cut
Expand Down Expand Up @@ -283,7 +283,7 @@ will be explained later in this documentation.
When a pluggable method is called the extensions framework first executes all
_before_ methods; then _around_ ones; then _after_. Within each group methods
are called using the order defined by =Foswiki::Extensions= =orderedList=
are called using the order defined by =Foswiki::ExtManager= =orderedList=
attribute (see the [[#ExtDeps][dependecies section]]).
__NOTE:__ It is commonplace for _after_ methods to be called in reverse order.
Expand Down Expand Up @@ -419,7 +419,7 @@ suite.
---++ SEE ALSO
=Foswiki::Extensions=, =Foswiki::Extension=, =Foswiki::Class=, and
=Foswiki::ExtManager=, =Foswiki::Extension=, =Foswiki::Class=, and
=ExtensionsTests= test suite.
Check out [[Foswiki:Development.OONewPluginModel][Foswiki topic]] where all this
Expand Down
13 changes: 2 additions & 11 deletions UnitTestContrib/lib/Unit/FoswikiTestRole.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ use File::Spec;
use Scalar::Util qw(blessed);
use Foswiki::Exception;

BEGIN {
if (Unit::TestRunner::CHECKLEAK) {
eval "use Devel::Leak::Object qw{ GLOBAL_bless };";
die $@ if $@;
$Devel::Leak::Object::TRACKSOURCELINES = 1;
$Devel::Leak::Object::TRACKSTACK = 1;
}
}

# Use variable to let it be easily incorporated into a regex.
our $TEST_WEB_PREFIX = 'Temporary';

Expand Down Expand Up @@ -782,7 +773,7 @@ sub leakDetectCheckpoint {

say STDERR "<<< LEAK CHECKPOINT FOR TEST ", $dumpName;

return Devel::Leak::Object::checkpoint();
return $Unit::TestRunner::checkpointSub->();
}

=begin TML
Expand Down Expand Up @@ -812,7 +803,7 @@ sub leakDetectDump {

$dumpName =~ tr/:/_/;
say STDERR ">>> LEAK DUMP FOR TEST ", $dumpName;
Devel::Leak::Object::status();
$Unit::TestRunner::statusSub->();
eval {
require Devel::MAT::Dumper;
my $pmatFile = File::Spec->catfile( $this->app->cfg->data->{Log}{Dir},
Expand Down
25 changes: 20 additions & 5 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,27 @@ extends qw(Foswiki::Object);

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

our ( $leakClass, $checkpointSub, $statusSub );

BEGIN {
if (CHECKLEAK) {
eval "use Devel::Leak::Object qw{ GLOBAL_bless };";
die $@ if $@;
$Devel::Leak::Object::TRACKSOURCELINES = 1;
$Devel::Leak::Object::TRACKSTACK = 1;
my $succeed = 0;
foreach $leakClass (qw(Unit::Leak::Object Devel::Leak::Object)) {
eval "use $leakClass qw{ GLOBAL_bless };";
if ($@) {
say STDERR "!!! Failed to load $leakClass\n", $@;
}
else {
eval "
\$${leakClass}::TRACKSOURCELINES = 1;
\$${leakClass}::TRACKSTACK = 1;";
$checkpointSub = $leakClass->can('checkpoint');
$statusSub = $leakClass->can('status');
$succeed = 1;
last;
}
}
die "Cannot load a leak-check module" unless $succeed;
}
}

Expand Down Expand Up @@ -608,7 +623,7 @@ sub runOne {
print "SKIP\t$test - $skip\n";
}
else {
Devel::Leak::Object::checkpoint() if CHECKLEAK;
$checkpointSub->() if CHECKLEAK;
print "\t$test\n";
$action .= "\n# $test\n ";

Expand Down
57 changes: 27 additions & 30 deletions UnitTestContrib/test/unit/ExtensionsTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extends qw(Foswiki::Extension);
use version 0.77; our \$VERSION = version->declare(0.0.1);
our \$API_VERSION = version->declare("2.99.0");
Foswiki::Extensions::registerExtModule('$extName');
Foswiki::ExtManager::registerExtModule('$extName');
$code
Expand All @@ -123,15 +123,15 @@ sub _setExtDependencies {

foreach my $extName ( keys %deps ) {
my $dep = $deps{$extName};
Foswiki::Extensions::registerDeps( $extName,
Foswiki::ExtManager::registerDeps( $extName,
ref($dep) ? @{$dep} : $dep );
}
}

sub _disableAllCurrentExtensions {
my $this = shift;
$this->app->env->{FOSWIKI_DISABLED_EXTENSIONS} =
[@Foswiki::Extensions::extModules];
[@Foswiki::ExtManager::extModules];
}

sub test_orderedList {
Expand All @@ -152,7 +152,7 @@ sub test_orderedList {

$this->assert_deep_equals(
$expected,
$this->app->extensions->orderedList,
$this->app->extMgr->orderedList,
"Wrong order of extensions"
);
}
Expand All @@ -169,14 +169,14 @@ sub test_manual_disable {
$this->reCreateFoswikiApp;

$this->assert_not_null(
$this->app->extensions->extensions->{ $ext[0] },
$this->app->extMgr->extensions->{ $ext[0] },
"First extension is expected to be initialized"
);
$this->assert( !$this->app->extensions->extEnabled( $ext[1] ),
$this->assert( !$this->app->extMgr->extEnabled( $ext[1] ),
"Second extensions is expected to be disabled but it is not" );
$this->assert_str_equals(
"Disabled by FOSWIKI_DISABLED_EXTENSIONS environment variable.",
$this->app->extensions->disabledExtensions->{ $ext[1] }
$this->app->extMgr->disabledExtensions->{ $ext[1] }
);
}

Expand All @@ -196,27 +196,25 @@ sub test_depend_on_manual_disable {
$this->reCreateFoswikiApp;

$this->assert_not_null(
$this->app->extensions->extensions->{ $ext[0] },
$this->app->extMgr->extensions->{ $ext[0] },
"First extension is expected to be initialized"
);
$this->assert( !$this->app->extensions->extEnabled( $ext[1] ),
"Second extensions is expected to be disabled but it is not" );
$this->assert( !$this->app->extMgr->extEnabled( $ext[1] ),
"Second extension is expected to be disabled but it is not" );
$this->assert_str_equals(
"Disabled by FOSWIKI_DISABLED_EXTENSIONS environment variable.",
$this->app->extensions->disabledExtensions->{ $ext[1] }
);
$this->assert(
!$this->app->extensions->extEnabled( $ext[2] ),
"Third extensions is expected to be disabled but it is not"
$this->app->extMgr->disabledExtensions->{ $ext[1] }
);
$this->assert( !$this->app->extensions->extEnabled( $ext[3] ),
"Fourth extensions is expected to be disabled but it is not" );
$this->assert( !$this->app->extMgr->extEnabled( $ext[2] ),
"Third extension is expected to be disabled but it is not" );
$this->assert( !$this->app->extMgr->extEnabled( $ext[3] ),
"Fourth extension is expected to be disabled but it is not" );

$this->assert_str_contains( "Disabled extension",
$this->app->extensions->disabledExtensions->{ $ext[2] } );
$this->app->extMgr->disabledExtensions->{ $ext[2] } );

$this->assert_str_contains( "Disabled extension",
$this->app->extensions->disabledExtensions->{ $ext[3] } );
$this->app->extMgr->disabledExtensions->{ $ext[3] } );
}

sub test_circular_deps {
Expand All @@ -236,15 +234,15 @@ sub test_circular_deps {

$this->assert_deep_equals(
$expected,
$this->app->extensions->orderedList,
$this->app->extMgr->orderedList,
"Wrong order of extensions"
);

$this->assert_str_contains( "Circular dependecy found for ",
$this->app->extensions->disabledExtensions->{ $ext[1] } );
$this->app->extMgr->disabledExtensions->{ $ext[1] } );

$this->assert_str_contains( "Circular dependecy found for ",
$this->app->extensions->disabledExtensions->{ $ext[3] } );
$this->app->extMgr->disabledExtensions->{ $ext[3] } );
}

sub test_pluggable_methods {
Expand Down Expand Up @@ -332,7 +330,7 @@ EXT3
my $testClass = 'Foswiki::ExtensionsTests::SampleClass';
my $testMethod = 'testPluggableMethod';
$this->assert(
defined $Foswiki::Extensions::pluggables{$testClass}{$testMethod},
defined $Foswiki::ExtManager::pluggables{$testClass}{$testMethod},
"Method "
. $testMethod
. " of class "
Expand Down Expand Up @@ -392,14 +390,14 @@ sub test_API_VERSION {
$this->reCreateFoswikiApp;

ASSERT(
!$this->app->extensions->extEnabled( $ext[0] ),
!$this->app->extMgr->extEnabled( $ext[0] ),
"Extension with API version "
. Foswiki::fetchGlobal("\$$ext[0]::API_VERSION")
. " must have been disabled but it's not"
);

ASSERT(
$this->app->extensions->extEnabled( $ext[1] ),
$this->app->extMgr->extEnabled( $ext[1] ),
"Extension with API version "
. Foswiki::fetchGlobal("\$$ext[1]::API_VERSION")
. " must have been enabled but it's not"
Expand Down Expand Up @@ -483,7 +481,7 @@ EXT8

$this->reCreateFoswikiApp;

my $exts = $this->app->extensions;
my $exts = $this->app->extMgr;

foreach my $i ( 0 .. 7 ) {
my $expect = defined( $expect[$i] ) ? "disabled" : "enabled";
Expand Down Expand Up @@ -597,7 +595,7 @@ package Foswiki::Macros::TEST_CLASS_MACRO;
sub expand {
my \$this = shift;
my \$myExt = \$this->app->extensions->extObject('$ext');
my \$myExt = \$this->app->extMgr->extObject('$ext');
return "TEST_CLASS_MACRO_" . \$myExt->counter;
}
Expand Down Expand Up @@ -634,8 +632,7 @@ SNEXT

$this->reCreateFoswikiApp;

$this->assert_str_equals( 'AutoGenExt',
$this->app->extensions->extName($ext) );
$this->assert_str_equals( 'AutoGenExt', $this->app->extMgr->extName($ext) );
}

sub test_callbacks {
Expand Down Expand Up @@ -764,7 +761,7 @@ EXT3
$this->assert_null( $rc->{cbReturn},
"The callback call must have returned undef" );

$this->app->extensions->extObject( $ext[1] )->beTheHighlander(1);
$this->app->extMgr->extObject( $ext[1] )->beTheHighlander(1);

$rc = $cbObj->sampleCBChain;

Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/FeatureSetTests.pm
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ sub _registerStandardCORE {
EXTENSIONS_3 => [
str2ver( 2.99, undef, undef ),
-desc => "New and powerful OO extensions",
-doc => 'Foswiki::Extensions'
-doc => 'Foswiki::ExtManager'
],
;
}
Expand Down
1 change: 1 addition & 0 deletions core/lib/Foswiki.pm
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ sub load_package {
${ $pkgNS->{$flagSym} } = 1; # Mark package as loaded.
}
catch {
#say STDERR "! Load failed for $fullname: $_";
my $e = Foswiki::Exception->transmute( $_, 0 );
$e->rethrow;
};
Expand Down
Loading

0 comments on commit 7d6d754

Please sign in to comment.