X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;ds=sidebyside;f=dev%2Fi386%2Flibperl-critic-perl%2Flibperl-critic-perl-1.088%2Ft%2F02_policy.t;fp=dev%2Fi386%2Flibperl-critic-perl%2Flibperl-critic-perl-1.088%2Ft%2F02_policy.t;h=9d754f9662c75840d1a3f387e2a4d4e669afd2b3;hb=da95c414033799c3a62606f299c3c00b5c77ca11;hp=0000000000000000000000000000000000000000;hpb=2d38e14bacbb15b98e539843a40b3c52a225f493;p=dh-make-perl diff --git a/dev/i386/libperl-critic-perl/libperl-critic-perl-1.088/t/02_policy.t b/dev/i386/libperl-critic-perl/libperl-critic-perl-1.088/t/02_policy.t new file mode 100644 index 0000000..9d754f9 --- /dev/null +++ b/dev/i386/libperl-critic-perl/libperl-critic-perl-1.088/t/02_policy.t @@ -0,0 +1,164 @@ +#!perl + +############################################################################## +# $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/02_policy.t $ +# $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $ +# $Author: clonezone $ +# $Revision: 2416 $ +############################################################################## + +use 5.006001; +use strict; +use warnings; + +use English qw<-no_match_vars>; + +use Test::More tests => 26; + + +#----------------------------------------------------------------------------- +# Perl::Critic::Policy is an abstract class, so it can't be instantiated +# directly. So we test it by declaring test classes that inherit from it. + +package PolicyTest; +use base 'Perl::Critic::Policy'; + +package PolicyTestOverriddenDefaultMaximumViolations; +use base 'Perl::Critic::Policy'; + +sub default_maximum_violations_per_document { return 31; } + +#----------------------------------------------------------------------------- + +package main; + +my $p = PolicyTest->new(); +isa_ok($p, 'PolicyTest'); + + +eval { $p->violates(); }; +ok($EVAL_ERROR, 'abstract violates() throws exception'); + + +# Test default application... +is($p->applies_to(), 'PPI::Element', 'applies_to()'); + + +# Test default maximum violations per document... +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()', +); + +# Change maximum violations level... +$p->set_maximum_violations_per_document(3); + +# Test maximum violations again... +is( + $p->default_maximum_violations_per_document(), + undef, + q, +); +is( + $p->get_maximum_violations_per_document(), + 3, + q, +); + + +my $overridden_default = PolicyTestOverriddenDefaultMaximumViolations->new(); +isa_ok($overridden_default, 'PolicyTestOverriddenDefaultMaximumViolations'); + +# Test default maximum violations per document... +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', +); + +# Change maximum violations level... +$overridden_default->set_maximum_violations_per_document(undef); + +# Test maximum violations again... +is( + $overridden_default->default_maximum_violations_per_document(), + 31, + q, +); +is( + $overridden_default->get_maximum_violations_per_document(), + undef, + q, +); + + +# Test default severity... +is( $p->default_severity(), 1, 'default_severity()'); +is( $p->get_severity(), 1, 'get_severity()' ); + +# Change severity level... +$p->set_severity(3); + +# Test severity again... +is( $p->default_severity(), 1 ); #Still the same +is( $p->get_severity(), 3 ); #Should have new value + + +# Test default theme... +is_deeply( [$p->default_themes()], [], 'default_themes()'); +is_deeply( [$p->get_themes()], [], 'get_themes()'); + +# Change theme +$p->set_themes( qw(c b a) ); #unsorted + +# Test theme again... +is_deeply( [$p->default_themes()], [] ); #Still the same +is_deeply( [$p->get_themes()], [qw(a b c)] ); #Should have new value, sorted + +# Append theme +$p->add_themes( qw(f e d) ); #unsorted + +# Test theme again... +is_deeply( [$p->default_themes()], [] ); #Still the same +is_deeply( [$p->get_themes()], [ qw(a b c d e f) ] ); #Should have new value, sorted + + +# Test format getter/setters +is( Perl::Critic::Policy::get_format, "%p\n", 'Default policy format'); + +my $new_format = '%p %s [%t]'; +Perl::Critic::Policy::set_format( $new_format ); #Set 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'); + + +#----------------------------------------------------------------------------- + +# ensure we run true if this test is loaded by +# t/02_policy.t_without_optional_dependencies.t +1; + + +############################################################################## +# Local Variables: +# mode: cperl +# cperl-indent-level: 4 +# fill-column: 78 +# indent-tabs-mode: nil +# c-indentation-style: bsd +# End: +# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :