Skip to content

Commit

Permalink
Item13897: Changed AddressTests to work with static _parse() method.
Browse files Browse the repository at this point in the history
- Experiment: throw Foswiki::Exception::ASSERT exception instead of
Carp::confess upon failed ASSERT().
  • Loading branch information
vrurg committed Jan 16, 2016
1 parent 90965a8 commit 7d66fb5
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
8 changes: 2 additions & 6 deletions UnitTestContrib/test/unit/AddressTests.pm
Expand Up @@ -740,12 +740,10 @@ sub test_timing_hashref_creation {

sub test_timing_reparse_default {
my ($this) = @_;
my $addr =
Foswiki::Address->new( topic => 'Topic', webpath => [qw(Web SubWeb)] );
my $benchmark = timeit(
15000,
sub {
$addr->_parse(
Foswiki::Address::_parse(
'AnotherTopic',
{
isA => 'topic',
Expand All @@ -762,12 +760,10 @@ sub test_timing_reparse_default {

sub test_timing_reparse {
my ($this) = @_;
my $addr =
Foswiki::Address->new( topic => 'Topic', webpath => [qw(Web SubWeb)] );
my $benchmark = timeit(
15000,
sub {
$addr->_parse( 'AnotherWeb/AnotherSubWeb.AnotherTopic',
Foswiki::Address::_parse( 'AnotherWeb/AnotherSubWeb.AnotherTopic',
{ isA => 'topic', } );
}
);
Expand Down
11 changes: 10 additions & 1 deletion core/lib/AssertOn.pm
Expand Up @@ -5,6 +5,7 @@

use strict;
use locale; # so result of lc() is tainted
use Foswiki::Exception;

our $DIRTY = lc('x'); # Used in TAINT
our $soft = 0;
Expand All @@ -27,7 +28,15 @@ sub ASSERT($;$) {
Carp::cluck($msg);
}
else {
Carp::confess($msg);
# SMELL Experimental: generate exception instead of just die.
my ( $pkg, $file, $line ) = caller;
Foswiki::Exception::ASSERT->throw(
text => $msg,
file => $file,
line => $line,
);

#Carp::confess($msg);
}
}
return;
Expand Down
2 changes: 2 additions & 0 deletions core/lib/Foswiki/Address.pm
Expand Up @@ -649,6 +649,8 @@ sub _parse {
existAs => { attachment => 1, topic => 1 }
};
}
ASSERT( defined $opts, "\$opts is not defined" );
ASSERT( ref($opts) eq 'HASH', "\$opts isn't a hashref but '$opts'" );
ASSERT(
( !defined $opts->{rev} || $opts->{rev} =~ m/^[-\+]?\d+$/ ),
"rev: '"
Expand Down
6 changes: 6 additions & 0 deletions core/lib/Foswiki/Exception.pm
Expand Up @@ -85,6 +85,12 @@ sub stringify {
);
}

package Foswiki::Exception::ASSERT;
use Moo;
extends qw(Foswiki::Exception);

# This class is to distinguish ASSERT-generated exceptions only.

package Foswiki::Exception::Engine;
use Moo;
use namespace::clean;
Expand Down

0 comments on commit 7d66fb5

Please sign in to comment.