Permalink
Browse files

Build of 9eb775c

  • Loading branch information...
1 parent 911d2b0 commit aaf11e87810f19f7de159ce51d0f9b6656ce8bd0 @kentfredric committed Jul 17, 2009
Showing with 76 additions and 14 deletions.
  1. +1 −1 Changes
  2. +26 −0 README
  3. +49 −13 lib/Test/Whitespace.pm
View
@@ -1,4 +1,4 @@
Revision history for Test-Whitespace
-0.0100 2009-07-17 11:49:30 UTC
+0.0100 2009-07-17 12:25:17 UTC
First Version.
View
@@ -5,6 +5,7 @@ VERSION
version 0.0100
SYNOPSIS
+ Declarative
use Test::Whitespace (
scan_for => [
'eol', 'tab' , 'extra' => [
@@ -16,6 +17,31 @@ SYNOPSIS
types => sub { $_->perlmodule },
);
+ Automatically scans for \s+$ , \t and other extra regexen in all perl
+ modules in /path/to/dir.
+
+ Objective
+ use Test::More plan => 5;
+ # Import 2 Symbols for you.
+ use Test::Whitespace;
+
+ my $rs = WhitespaceRuleSet
+ ->new
+ ->tailing
+ ->tabs
+ ->add_rule( qr/\x504/, '\x504 {{err}}' )
+ ->add_rule( qr/){/, 'Untidyness {{err}}' );
+
+ my @files = ( ... );
+ for ( @files ){
+ my $stat = $rs->test_file( $_ );
+ ok( $stat->[0] , "Test for $_ whitespace");
+ diag( $stat->[1] ) unless $stat->[0] ;
+ }
+
+ Works more or less the same, but with more control and doing it the hard
+ way.
+
PRIMARY AUDIENCE
This Module is intended for Author Testing and Release testing.
@@ -7,17 +7,20 @@ our $VERSION = '0.0100';
use strict;
use warnings;
-use Sub::Install ();
-use Test::Builder ();
-use File::Find::Rule ();
-use File::Find::Rule::Perl ();
-use Carp ();
+use Test::Builder ();
+use Carp ();
-# Aliases
+# Aliases, with a little difference.
+# Modules aliases need to work wont be loaded till somebody
+# calls the alias :)
+
sub FFR() {
+ require File::Find::Rule;
+ require File::Find::Rule::Perl;
+
'File::Find::Rule';
}
@@ -35,6 +38,7 @@ sub WhitespaceRuleSet {
sub import_subs {
my $caller = shift;
+ require Sub::Install;
Sub::Install::install_sub( { code => \&WhitespaceRule, into => $caller, as => 'WhitespaceRule', } );
Sub::Install::install_sub( { code => \&WhitespaceRuleSet, into => $caller, as => 'WhitespaceRuleSet', } );
return;
@@ -59,11 +63,8 @@ sub import_autotest {
for ( @{ $args->{'files'} } ) {
my $result = $rs->test_file($_);
- if ( $result->[0] == 1 ) {
- $tb->ok( 1, "Test::Whitespace for $_" );
- }
- else {
- $tb->ok( 0, "Test::Whitespace for $_" );
+ $tb->ok( $result->[0], "Test::Whitespace for $_" );
+ unless ( $result->[0] == 1 ) {
for ( @{ $result->[1] } ) {
$tb->diag($_);
}
@@ -82,7 +83,7 @@ sub find_files {
$f = $types->();
}
- @files = $f->in( @{ $in } );
+ @files = $f->in( @{$in} );
return \@files;
}
@@ -94,9 +95,17 @@ sub find_files {
my $scan_for = {
'eol' => sub { $_[1]->tailing; },
'tab' => sub { $_[1]->tabs; },
- 'extra' => sub { $_[1]->add_rule( @{$_} ) for @{ ( shift @{ $_[0] } ) } },
+ 'extra' => sub { scan_for_extra( $_[1], scalar shift @{ $_[0] } ) },
};
+ sub scan_for_extra {
+ my ( $rs, $extra ) = @_;
+ for ( @{$extra} ) {
+ $rs->add_rule( @{$_} );
+ }
+ return $rs;
+ }
+
sub inject_rules {
my ( $rs, $args ) = @_;
@@ -146,6 +155,8 @@ version 0.0100
=head1 SYNOPSIS
+=head2 Declarative
+
use Test::Whitespace (
scan_for => [
'eol', 'tab' , 'extra' => [
@@ -157,6 +168,31 @@ version 0.0100
types => sub { $_->perlmodule },
);
+Automatically scans for \s+$ , \t and other extra regexen in all
+ perl modules in /path/to/dir.
+
+=head2 Objective
+
+ use Test::More plan => 5;
+ # Import 2 Symbols for you.
+ use Test::Whitespace;
+
+ my $rs = WhitespaceRuleSet
+ ->new
+ ->tailing
+ ->tabs
+ ->add_rule( qr/\x504/, '\x504 {{err}}' )
+ ->add_rule( qr/){/, 'Untidyness {{err}}' );
+
+ my @files = ( ... );
+ for ( @files ){
+ my $stat = $rs->test_file( $_ );
+ ok( $stat->[0] , "Test for $_ whitespace");
+ diag( $stat->[1] ) unless $stat->[0] ;
+ }
+
+Works more or less the same, but with more control and doing it the hard way.
+
=head1 PRIMARY AUDIENCE
This Module is intended for Author Testing and Release testing.

0 comments on commit aaf11e8

Please sign in to comment.