[libcode-tidyall-perl] 195/374: add per-plugin tests
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:26:18 UTC 2013
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository libcode-tidyall-perl.
commit 16aed61796efb84c20c839aacc354c28502e187c
Author: Jonathan Swartz <swartz at pobox.com>
Date: Thu Sep 6 15:32:41 2012 -0700
add per-plugin tests
---
lib/Code/TidyAll/t/Plugin.pm | 52 ++++++++++++++++++++++
lib/Code/TidyAll/t/Plugin/PerlCritic.pm | 30 +++++++++++++
lib/Code/TidyAll/t/Plugin/PerlTidy.pm | 27 ++++++++++++
lib/Code/TidyAll/t/Plugin/PodTidy.pm | 71 +++++++++++++++++++++++++++++++
xt/author/Plugin-PerlCritic.t | 3 ++
xt/author/Plugin-PerlTidy.t | 3 ++
xt/author/Plugin-PodTidy.t | 3 ++
7 files changed, 189 insertions(+)
diff --git a/lib/Code/TidyAll/t/Plugin.pm b/lib/Code/TidyAll/t/Plugin.pm
new file mode 100644
index 0000000..2c44aab
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin.pm
@@ -0,0 +1,52 @@
+package Code::TidyAll::t::Plugin;
+use Capture::Tiny qw(capture_merged);
+use Code::TidyAll::Util qw(tempdir_simple);
+use Code::TidyAll;
+use Test::Class::Most parent => 'Code::TidyAll::Test::Class';
+
+__PACKAGE__->SKIP_CLASS("Virtual base class");
+
+my $Test = Test::Builder->new;
+
+sub startup : Tests(startup => no_plan) {
+ my $self = shift;
+ $self->{root_dir} = tempdir_simple();
+}
+
+sub plugin_class {
+ my ($self) = @_;
+
+ return ( split( '::', ref($self) ) )[-1];
+}
+
+sub tidyall {
+ my ( $self, %p ) = @_;
+
+ my $source = $p{source} || die "source required";
+ my $plugin_class = $self->plugin_class;
+ my %plugin_conf = ( $plugin_class => { select => '*', %{ $p{conf} || {} } } );
+ my $ct = Code::TidyAll->new( quiet => 1, root_dir => $self->{root_dir}, plugins => \%plugin_conf );
+
+ $source =~ s/\\n/\n/g;
+ my $result;
+ my $output = capture_merged { $result = $ct->process_source( $source, 'foo.txt' ) };
+ $Test->diag($output) if $ENV{TEST_VERBOSE};
+
+ if ( my $expect_tidy = $p{expect_tidy} ) {
+ $expect_tidy =~ s/\\n/\n/g;
+ is( $result->state, 'tidied', 'state=tidied' );
+ is( $result->new_contents, $expect_tidy, 'new contents' );
+ }
+ elsif ( my $expect_ok = $p{expect_ok} ) {
+ is( $result->state, 'checked', 'state=checked' );
+ if ( $result->new_contents ) {
+ is( $result->new_contents, $source, 'same contents' );
+ }
+ }
+ elsif ( my $expect_error = $p{expect_error} ) {
+ is( $result->state, 'error', 'state=error' );
+ like( $result->error, $expect_error, 'error message' );
+ }
+}
+
+1;
diff --git a/lib/Code/TidyAll/t/Plugin/PerlCritic.pm b/lib/Code/TidyAll/t/Plugin/PerlCritic.pm
new file mode 100644
index 0000000..4884478
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin/PerlCritic.pm
@@ -0,0 +1,30 @@
+package Code::TidyAll::t::Plugin::PerlCritic;
+use Code::TidyAll::Util qw(write_file);
+use Test::Class::Most parent => 'Code::TidyAll::t::Plugin';
+
+sub test_main : Tests {
+ my $self = shift;
+
+ my $rc_file = $self->{root_dir} . "/perlcriticrc";
+
+ write_file( $rc_file, "only = 1\nseverity = 1\n[TestingAndDebugging::RequireUseStrict]\n" );
+ $self->tidyall(
+ source => 'my $foo = 5\n',
+ conf => { argv => "--profile $rc_file" },
+ expect_error => qr/Code before strictures/,
+ );
+ $self->tidyall(
+ source => 'use strict;\nuse warnings;\nmy $foo = 5\n',
+ conf => { argv => "--profile $rc_file" },
+ expect_ok => 1,
+ );
+ write_file( $rc_file,
+ "only = 1\nseverity = 1\n[CodeLayout::ProhibitHardTabs]\n" );
+ $self->tidyall(
+ source => 'my $foo = 5\n',
+ conf => { argv => "--profile $rc_file" },
+ expect_ok => 1,
+ );
+}
+
+1;
diff --git a/lib/Code/TidyAll/t/Plugin/PerlTidy.pm b/lib/Code/TidyAll/t/Plugin/PerlTidy.pm
new file mode 100644
index 0000000..f8a656c
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin/PerlTidy.pm
@@ -0,0 +1,27 @@
+package Code::TidyAll::t::Plugin::PerlTidy;
+use Test::Class::Most parent => 'Code::TidyAll::t::Plugin';
+
+sub test_main : Tests {
+ my $self = shift;
+
+ my $source = 'if ( $foo) {\nmy $bar = $baz;\n}\n';
+ $self->tidyall(
+ source => $source,
+ expect_tidy => 'if ($foo) {\n my $bar = $baz;\n}'
+ );
+ $self->tidyall(
+ conf => { argv => '-bl' },
+ source => $source,
+ expect_tidy => 'if ($foo)\n{\n my $bar = $baz;\n}'
+ );
+ $self->tidyall(
+ source => 'if ($foo) {\n my $bar = $baz;\n}\n',
+ expect_ok => 1
+ );
+ $self->tidyall(
+ source => 'if ($foo) {\n my $bar = $baz;\n',
+ expect_error => qr/Final nesting depth/
+ );
+}
+
+1;
diff --git a/lib/Code/TidyAll/t/Plugin/PodTidy.pm b/lib/Code/TidyAll/t/Plugin/PodTidy.pm
new file mode 100644
index 0000000..32ca4d1
--- /dev/null
+++ b/lib/Code/TidyAll/t/Plugin/PodTidy.pm
@@ -0,0 +1,71 @@
+package Code::TidyAll::t::Plugin::PodTidy;
+use Test::Class::Most parent => 'Code::TidyAll::t::Plugin';
+
+sub test_main : Tests {
+ my $self = shift;
+
+ my $source = '=head1 DESCRIPTION
+
+There are a lot of great code tidiers and validators out there. C<tidyall> makes them available from a single unified interface.
+
+You can run C<tidyall> on a single file or on an entire project hierarchy, and configure which tidiers/validators are applied to which files. C<tidyall> will back up files beforehand, and for efficiency will only consider files that have changed since they were last processed.
+
+';
+ $self->tidyall(
+ source => $source,
+ expect_tidy => '=head1 DESCRIPTION
+
+There are a lot of great code tidiers and validators out there. C<tidyall>
+makes them available from a single unified interface.
+
+You can run C<tidyall> on a single file or on an entire project hierarchy, and
+configure which tidiers/validators are applied to which files. C<tidyall> will
+back up files beforehand, and for efficiency will only consider files that have
+changed since they were last processed.
+
+'
+ );
+
+ $self->tidyall(
+ source => '=head1 DESCRIPTION
+
+There are a lot of great code tidiers and validators out there. C<tidyall>
+makes them available from a single unified interface.
+
+You can run C<tidyall> on a single file or on an entire project hierarchy, and
+configure which tidiers/validators are applied to which files. C<tidyall> will
+back up files beforehand, and for efficiency will only consider files that have
+changed since they were last processed.
+
+',
+ expect_ok => 1,
+ );
+
+ $self->tidyall(
+ source => $source,
+ conf => { columns => 30 },
+ expect_tidy => '=head1 DESCRIPTION
+
+There are a lot of great code
+tidiers and validators out
+there. C<tidyall> makes them
+available from a single
+unified interface.
+
+You can run C<tidyall> on a
+single file or on an entire
+project hierarchy, and
+configure which
+tidiers/validators are
+applied to which files.
+C<tidyall> will back up files
+beforehand, and for
+efficiency will only consider
+files that have changed since
+they were last processed.
+
+'
+ );
+}
+
+1;
diff --git a/xt/author/Plugin-PerlCritic.t b/xt/author/Plugin-PerlCritic.t
new file mode 100644
index 0000000..778617d
--- /dev/null
+++ b/xt/author/Plugin-PerlCritic.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Plugin::PerlCritic;
+Code::TidyAll::t::Plugin::PerlCritic->runtests;
diff --git a/xt/author/Plugin-PerlTidy.t b/xt/author/Plugin-PerlTidy.t
new file mode 100644
index 0000000..ad0e6ac
--- /dev/null
+++ b/xt/author/Plugin-PerlTidy.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Plugin::PerlTidy;
+Code::TidyAll::t::Plugin::PerlTidy->runtests;
diff --git a/xt/author/Plugin-PodTidy.t b/xt/author/Plugin-PodTidy.t
new file mode 100644
index 0000000..7f48881
--- /dev/null
+++ b/xt/author/Plugin-PodTidy.t
@@ -0,0 +1,3 @@
+#!/usr/bin/perl
+use Code::TidyAll::t::Plugin::PodTidy;
+Code::TidyAll::t::Plugin::PodTidy->runtests;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git
More information about the Pkg-perl-cvs-commits
mailing list