r43088 - in /branches/upstream/libtest-perltidy-perl: ./ current/ current/lib/ current/lib/Test/ current/t/

jawnsy-guest at users.alioth.debian.org jawnsy-guest at users.alioth.debian.org
Fri Aug 28 02:16:55 UTC 2009


Author: jawnsy-guest
Date: Fri Aug 28 02:16:48 2009
New Revision: 43088

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=43088
Log:
[svn-inject] Installing original source of libtest-perltidy-perl

Added:
    branches/upstream/libtest-perltidy-perl/
    branches/upstream/libtest-perltidy-perl/current/
    branches/upstream/libtest-perltidy-perl/current/MANIFEST
    branches/upstream/libtest-perltidy-perl/current/META.yml
    branches/upstream/libtest-perltidy-perl/current/Makefile.PL
    branches/upstream/libtest-perltidy-perl/current/README
    branches/upstream/libtest-perltidy-perl/current/lib/
    branches/upstream/libtest-perltidy-perl/current/lib/Test/
    branches/upstream/libtest-perltidy-perl/current/lib/Test/PerlTidy.pm
    branches/upstream/libtest-perltidy-perl/current/t/
    branches/upstream/libtest-perltidy-perl/current/t/is_file_tidy.t
    branches/upstream/libtest-perltidy-perl/current/t/list_files.t
    branches/upstream/libtest-perltidy-perl/current/t/messy_file
    branches/upstream/libtest-perltidy-perl/current/t/perltidy.t
    branches/upstream/libtest-perltidy-perl/current/t/tidy_file

Added: branches/upstream/libtest-perltidy-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/MANIFEST?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/MANIFEST (added)
+++ branches/upstream/libtest-perltidy-perl/current/MANIFEST Fri Aug 28 02:16:48 2009
@@ -1,0 +1,10 @@
+lib/Test/PerlTidy.pm
+Makefile.PL
+MANIFEST			This list of files
+README
+t/is_file_tidy.t
+t/list_files.t
+t/messy_file
+t/perltidy.t
+t/tidy_file
+META.yml                                 Module meta-data (added by MakeMaker)

Added: branches/upstream/libtest-perltidy-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/META.yml?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/META.yml (added)
+++ branches/upstream/libtest-perltidy-perl/current/META.yml Fri Aug 28 02:16:48 2009
@@ -1,0 +1,17 @@
+--- #YAML:1.0
+name:                Test-PerlTidy
+version:             20070911
+abstract:            ~
+license:             ~
+generated_by:        ExtUtils::MakeMaker version 6.32
+distribution_type:   module
+requires:     
+    File::Finder:                  0
+    File::Slurp:                   0
+    Perl::Tidy:                    20031021
+    Test::Builder:                 0
+    Test::More:                    0
+    Text::Diff:                    0
+meta-spec:
+    url:     http://module-build.sourceforge.net/META-spec-v1.2.html
+    version: 1.2

Added: branches/upstream/libtest-perltidy-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/Makefile.PL?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/Makefile.PL (added)
+++ branches/upstream/libtest-perltidy-perl/current/Makefile.PL Fri Aug 28 02:16:48 2009
@@ -1,0 +1,14 @@
+# Note: this file was auto-generated by Module::Build::Compat version 0.03
+use ExtUtils::MakeMaker;
+WriteMakefile(
+    'NAME'         => 'Test::PerlTidy',
+    'VERSION_FROM' => 'lib/Test/PerlTidy.pm',
+    'PREREQ_PM'    => {
+        'File::Finder'  => '0',
+        'File::Slurp'   => '0',
+        'Perl::Tidy'    => '20031021',
+        'Test::Builder' => '0',
+        'Test::More'    => '0',
+        'Text::Diff'    => '0'
+    },
+);

Added: branches/upstream/libtest-perltidy-perl/current/README
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/README?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/README (added)
+++ branches/upstream/libtest-perltidy-perl/current/README Fri Aug 28 02:16:48 2009
@@ -1,0 +1,16 @@
+Test::PerlTidy
+
+To install please follow the following steps:
+
+  perl Build.PL
+  ./Build
+  ./Build test
+  ./Build install
+
+During the tests the code checks that all the perl files included with
+the distribution are tidy. If you make any changes please remember to
+tidy them.
+
+Any problems let me know: evdb at ecclestoad.co.uk
+
+

Added: branches/upstream/libtest-perltidy-perl/current/lib/Test/PerlTidy.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/lib/Test/PerlTidy.pm?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/lib/Test/PerlTidy.pm (added)
+++ branches/upstream/libtest-perltidy-perl/current/lib/Test/PerlTidy.pm Fri Aug 28 02:16:48 2009
@@ -1,0 +1,188 @@
+package Test::PerlTidy;
+
+use strict;
+use warnings;
+
+use File::Finder;
+use File::Slurp;
+use Perl::Tidy;
+use Text::Diff;
+
+use Test::Builder;
+require Exporter;
+use vars qw( @ISA @EXPORT );
+ at ISA    = qw( Exporter );
+ at EXPORT = qw( run_tests );
+
+our $VERSION;
+$VERSION = '20070911';
+
+my $Test = Test::Builder->new;
+our $MUTE = 0;
+
+sub run_tests {
+
+    # Get the values and setup defaults if needed.
+    my %args = @_;
+
+    # Skip all tests if instructed to.
+    $Test->skip_all("All tests skipped.") if $args{skip_all};
+
+    # Get files to work with and set the plan.
+    my @files = list_files('.');
+    $Test->plan( tests => scalar @files );
+
+    # Check ech file in turn.
+    foreach my $file (@files) {
+
+        # $Test->diag("About to test '$file'\n");
+        $Test->ok( is_file_tidy($file), "'$file'" );
+    }
+}
+
+sub is_file_tidy {
+    my $file_to_tidy = shift;
+    my $code_to_tidy = load_file($file_to_tidy);
+
+    my $tidied_code = '';
+    my $stderr      = '';
+    my $logfile     = '';
+    my $errorfile   = '';
+
+    Perl::Tidy::perltidy(
+        source      => \$code_to_tidy,
+        destination => \$tidied_code,
+        stderr      => \$stderr,
+        logfile     => \$logfile,
+        errorfile   => \$errorfile,
+    );
+
+    # If there were perltidy errors report them and return.
+    if ($stderr) {
+        $Test->diag("perltidy reported the following errors:\n") unless $MUTE;
+        $Test->diag($stderr)                                     unless $MUTE;
+        return 0;
+    }
+
+    # Compare the pre and post tidy code and return result.
+    unless ( $code_to_tidy eq $tidied_code ) {
+        unless ($MUTE) {
+            $Test->diag("The file '$file_to_tidy' is not tidy\n");
+            $Test->diag(
+                diff( \$code_to_tidy, \$tidied_code, { STYLE => 'Table' } ) );
+        }
+
+        return 0;
+    }
+    else {
+        return 1;
+    }
+}
+
+sub list_files {
+    my $path = shift;
+    die "You need to specify which directory to scan"
+      unless defined $path && length $path;
+
+    my @files = ();
+
+    # Die if we got a bad dir.
+    die "The directory '$path' does not exist" unless -d $path;
+
+    # Find files using File::Finder.
+    @files = File::Finder->type('f')->in($path);
+
+    return
+
+      # Sort the output so that it is repeatable
+      sort
+
+      # Filter out only the files that end in .pl, .pm, .PL or .t
+      grep { m/\.(pl|pm|PL|t)$/; }
+
+      # Filter out blib
+      grep { !m|^\./blib/|; } @files;
+}
+
+sub load_file {
+    my $filename = shift;
+
+    # If the file is not regular then return undef.
+    return undef unless -f $filename;
+
+    # Slurp the file.
+    my $content = read_file($filename);
+    return $content;
+}
+
+=head1 NAME
+ 
+Test::PerlTidy - check that all your files are tidy.
+ 
+=head1 SYNOPSIS
+ 
+    # In a file like 't/perltidy.t'
+    use Test::PerlTidy;
+    run_tests();
+
+=head1 DESCRIPTION
+ 
+This rather unflattering comment was made in a piece by Ken Arnold:
+
+    "Perl is a vast swamp of lexical and syntactic swill and nobody
+    knows how to format even their own code well, but it's the only
+    major language I can think of (with the possible exception of the
+    recent, yet very Java-like C#) that doesn't have at least one
+    style that's good enough."
+              http://www.artima.com/weblogs/viewpost.jsp?thread=74230
+
+Hmmm... He is sort of right in a way. Then again the piece he wrote
+was related to Python which is somewhat strict about formatting
+itself.
+
+Fear not though - now you too can have your very own formatting
+gestapo in the form of Test::PerlTidy! Simply add a test file as
+suggested above and any file ending in .pl, .pm, .t or .PL will cause
+a test fail unless it is exactly as perltidy would like it to be.
+
+=head1 REASONS TO DO THIS
+
+If the style is mandated in tests then it will be adhered to.
+
+If perltidy decides what is a good style then there should be no
+quibbling.
+
+If the style never changes then cvs diffs stop catching changes that
+are not really there.
+
+Readability might even improve.
+
+=head1 HINTS
+
+If you want to change the default style then muck around with
+'.perltidyrc';
+
+To quickly make a file work then try 'perltidy -b the_messy_file.pl'.
+
+=head1 SEE ALSO
+
+L<Perl::Tidy>
+
+=head1 AUTHOR
+ 
+evdb at ecclestoad.co.uk Edmund von der Burg
+
+=head1 SUGGESTIONS
+
+Please let me know if you have any comments or suggestions.
+
+L<http://ecclestoad.co.uk/>
+ 
+=head1 LICENSE
+ 
+This library is free software . You can redistribute it and/or modify
+it under the same terms as perl itself.
+ 
+=cut
+
+1;

Added: branches/upstream/libtest-perltidy-perl/current/t/is_file_tidy.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/t/is_file_tidy.t?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/t/is_file_tidy.t (added)
+++ branches/upstream/libtest-perltidy-perl/current/t/is_file_tidy.t Fri Aug 28 02:16:48 2009
@@ -1,0 +1,12 @@
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+
+use Test::PerlTidy;
+
+{
+    local ${Test::PerlTidy::MUTE} = 1;
+    ok Test::PerlTidy::is_file_tidy('t/tidy_file'), 't/tidy_file';
+    ok !Test::PerlTidy::is_file_tidy('t/messy_file'), 't/messy_file';
+}

Added: branches/upstream/libtest-perltidy-perl/current/t/list_files.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/t/list_files.t?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/t/list_files.t (added)
+++ branches/upstream/libtest-perltidy-perl/current/t/list_files.t Fri Aug 28 02:16:48 2009
@@ -1,0 +1,19 @@
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+use Test::PerlTidy;
+
+my @wanted_files = sort    #
+  (
+    './Makefile.PL',             #
+    './lib/Test/PerlTidy.pm',    #
+    './t/list_files.t',          #
+    './t/perltidy.t',            #
+    './t/is_file_tidy.t',        #
+  );
+
+my @found_files = Test::PerlTidy::list_files('.');
+
+is_deeply( \@wanted_files, \@found_files );

Added: branches/upstream/libtest-perltidy-perl/current/t/messy_file
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/t/messy_file?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/t/messy_file (added)
+++ branches/upstream/libtest-perltidy-perl/current/t/messy_file Fri Aug 28 02:16:48 2009
@@ -1,0 +1,4 @@
+$a=8;$G{int(++$a/9).$a%9+1}=$_ for split//,<>;@A=1..9;sub c{int(($_[0]-1
+)/3)*3}sub G{for$y(@A){for$x(@A){$t=$G{my$c=$y.$x}&&next;$t.=$G{$_.$x}.
+$G{$y.$_}for at A;for$f(1..3){$t.=$G{c($y)+$f.c($x)+$_}for 1..3}G($G{$c}=$_
+)for grep$t!~m/$_/, at A;return$G{$c}=0}}die map{$G{$_}||"\n"}9..100}G

Added: branches/upstream/libtest-perltidy-perl/current/t/perltidy.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/t/perltidy.t?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/t/perltidy.t (added)
+++ branches/upstream/libtest-perltidy-perl/current/t/perltidy.t Fri Aug 28 02:16:48 2009
@@ -1,0 +1,5 @@
+use strict;
+use warnings;
+
+use Test::PerlTidy;
+run_tests();

Added: branches/upstream/libtest-perltidy-perl/current/t/tidy_file
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libtest-perltidy-perl/current/t/tidy_file?rev=43088&op=file
==============================================================================
--- branches/upstream/libtest-perltidy-perl/current/t/tidy_file (added)
+++ branches/upstream/libtest-perltidy-perl/current/t/tidy_file Fri Aug 28 02:16:48 2009
@@ -1,0 +1,21 @@
+$a = 8;
+$G{ int( ++$a / 9 ) . $a % 9 + 1 } = $_ for split //, <>;
+ at A = 1 .. 9;
+
+sub c {
+    int( ( $_[0] - 1 ) / 3 ) * 3;
+}
+
+sub G {
+    for $y (@A) {
+        for $x (@A) {
+            $t = $G{ my $c = $y . $x } && next;
+            $t .= $G{ $_ . $x } . $G{ $y . $_ } for @A;
+            for $f ( 1 .. 3 ) { $t .= $G{ c($y) + $f . c($x) + $_ } for 1 .. 3 }
+            G( $G{$c} = $_ ) for grep $t !~ m/$_/, @A;
+            return $G{$c} = 0;
+        }
+    }
+    die map { $G{$_} || "\n" } 9 .. 100;
+}
+G




More information about the Pkg-perl-cvs-commits mailing list