#!perl
use
5.010001;
our
$VERSION
=
'1.152'
;
Perl::Critic::TestUtils::assert_version(
$VERSION
);
sub
default_maximum_violations_per_document {
return
31; }
my
$p
= PolicyTest->new();
isa_ok(
$p
,
'PolicyTest'
);
local
$EVAL_ERROR
=
undef
;
eval
{
$p
->violates(); 1 };
ok(
$EVAL_ERROR
,
'abstract violates() throws exception'
);
is(
$p
->is_enabled(),
undef
,
'is_enabled() initially returns undef'
,
);
ok( !!
$p
->is_safe(),
'is_safe() returns a true value by default.'
);
is(
$p
->applies_to(),
'PPI::Element'
,
'applies_to()'
);
is(
$p
->default_maximum_violations_per_document(),
undef
,
'default_maximum_violations_per_document()'
,
);
is(
$p
->get_maximum_violations_per_document(),
undef
,
'get_maximum_violations_per_document()'
,
);
$p
->set_maximum_violations_per_document(3);
is(
$p
->default_maximum_violations_per_document(),
undef
,
q<default_maximum_violations_per_document() hasn't changed>
,
);
is(
$p
->get_maximum_violations_per_document(),
3,
q<get_maximum_violations_per_document() returns new value>
,
);
my
$overridden_default
= PolicyTestOverriddenDefaultMaximumViolations->new();
isa_ok(
$overridden_default
,
'PolicyTestOverriddenDefaultMaximumViolations'
);
is(
$overridden_default
->is_enabled(),
undef
,
'is_enabled() initially returns undef'
,
);
is(
$overridden_default
->default_maximum_violations_per_document(),
31,
'default_maximum_violations_per_document() overridden'
,
);
is(
$overridden_default
->get_maximum_violations_per_document(),
31,
'get_maximum_violations_per_document() overridden'
,
);
$overridden_default
->set_maximum_violations_per_document(
undef
);
is(
$overridden_default
->default_maximum_violations_per_document(),
31,
q<default_maximum_violations_per_document() overridden hasn't changed>
,
);
is(
$overridden_default
->get_maximum_violations_per_document(),
undef
,
q<get_maximum_violations_per_document() overridden returns new undefined value>
,
);
is(
$p
->default_severity(), 1,
'default_severity()'
);
is(
$p
->get_severity(), 1,
'get_severity()'
);
$p
->set_severity(3);
is(
$p
->default_severity(), 1,
q<default_severity() hasn't changed.>
);
is(
$p
->get_severity(), 3,
q<get_severity() returns the new value.>
);
is_deeply( [
$p
->default_themes()], [],
'default_themes()'
);
is_deeply( [
$p
->get_themes()], [],
'get_themes()'
);
$p
->set_themes(
qw(c b a)
);
is_deeply( [
$p
->default_themes()], [],
q<default_themes() hasn't changed.>
);
is_deeply(
[
$p
->get_themes()],
[
qw(a b c)
],
'get_themes() returns the new value, sorted.'
,
);
$p
->add_themes(
qw(f e d)
);
is_deeply( [
$p
->default_themes()], [],
q<default_themes() hasn't changed.>
);
is_deeply(
[
$p
->get_themes()],
[
qw(a b c d e f)
],
'get_themes() returns the new value, sorted.'
,
);
is( Perl::Critic::Policy::get_format,
'%p'
,
'Default policy format'
);
my
$new_format
=
'%p %s [%t]'
;
Perl::Critic::Policy::set_format(
$new_format
);
is( Perl::Critic::Policy::get_format,
$new_format
,
'Changed policy format'
);
my
$expected_string
=
'PolicyTest 3 [a b c d e f]'
;
is(
$p
->to_string(),
$expected_string
,
'Stringification by to_string()'
);
is(
"$p"
,
$expected_string
,
'Stringification by overloading'
);