Skip to content

Commit

Permalink
Build of 9eb775c
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed Jul 17, 2009
1 parent 911d2b0 commit aaf11e8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -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.
26 changes: 26 additions & 0 deletions README
Expand Up @@ -5,6 +5,7 @@ VERSION
version 0.0100

SYNOPSIS
Declarative
use Test::Whitespace (
scan_for => [
'eol', 'tab' , 'extra' => [
Expand All @@ -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.

Expand Down
62 changes: 49 additions & 13 deletions lib/Test/Whitespace.pm
Expand Up @@ -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';
}

Expand All @@ -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;
Expand All @@ -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($_);
}
Expand All @@ -82,7 +83,7 @@ sub find_files {
$f = $types->();
}

@files = $f->in( @{ $in } );
@files = $f->in( @{$in} );
return \@files;
}

Expand All @@ -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 ) = @_;
Expand Down Expand Up @@ -146,6 +155,8 @@ version 0.0100
=head1 SYNOPSIS
=head2 Declarative
use Test::Whitespace (
scan_for => [
'eol', 'tab' , 'extra' => [
Expand All @@ -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.
Expand Down

0 comments on commit aaf11e8

Please sign in to comment.