[libcode-tidyall-perl] 13/374: test 'not underneath root dir' error

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:25:40 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 cd1226dbaff2d55af3d9b38471a59bbc855105e7
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Tue Jun 12 12:09:16 2012 -0700

    test 'not underneath root dir' error
---
 lib/Code/TidyAll.pm         |    8 ++++----
 lib/Code/TidyAll/t/Basic.pm |   32 ++++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index 4df2d15..1adb928 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -111,16 +111,16 @@ sub process_path {
 
         ( -f $path ) ? $self->_process_file($path)
       : ( -d $path ) ? $self->_process_dir($path)
-      :                $self->msg( "%s: not a file or directory\n", $path );
+      :                $self->msg( "%s: not a file or directory", $path );
 }
 
 sub _process_dir {
     my ( $self, $dir ) = @_;
     unless ( $self->recursive ) {
-        $self->msg( "%s: skipping dir, not in recursive mode\n", $dir );
-        next;
+        $self->msg( "%s: skipping dir, not in recursive mode", $self->_small_path($dir) );
+        return;
     }
-    next if basename($dir) eq '.tidyall.d';
+    return if basename($dir) eq '.tidyall.d';
     my @files;
     find( { follow => 0, wanted => sub { push @files, $_ if -f }, no_chdir => 1 }, $dir );
     foreach my $file (@files) {
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index 598a26a..41cf851 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -1,5 +1,6 @@
 package Code::TidyAll::t::Basic;
-use Code::TidyAll::Util qw(mkpath read_file tempdir_simple write_file);
+use Cwd qw(realpath);
+use Code::TidyAll::Util qw(dirname mkpath read_file tempdir_simple write_file);
 use Code::TidyAll;
 use Capture::Tiny qw(capture_stdout);
 use File::Find qw(find);
@@ -14,9 +15,11 @@ sub create_dir {
 
     my $root_dir = tempdir_simple();
     while ( my ( $path, $content ) = each(%$files) ) {
-        write_file( "$root_dir/$path", $content );
+        my $full_path = "$root_dir/$path";
+        mkpath( dirname($full_path), 0, 0775 );
+        write_file( $full_path, $content );
     }
-    return $root_dir;
+    return realpath($root_dir);
 }
 
 sub tidy {
@@ -25,10 +28,15 @@ sub tidy {
 
     my $root_dir = $self->create_dir( $params{source} );
 
-    my $ct =
-      Code::TidyAll->new( plugins => $params{plugins}, recursive => 1, root_dir => $root_dir );
+    my $options = $params{options} || {};
+    my $ct = Code::TidyAll->new(
+        plugins   => $params{plugins},
+        recursive => 1,
+        root_dir  => $root_dir,
+        %$options
+    );
 
-    my ($output) = capture_stdout { $ct->process_paths($root_dir) };
+    my $output = capture_stdout { $ct->process_paths($root_dir) };
     if ( $params{errors} ) {
         like( $output, $params{errors}, "$desc - errors" );
     }
@@ -105,6 +113,18 @@ sub test_errors : Tests {
     my $data_dir = tempdir_simple();
     throws_ok { Code::TidyAll->new( data_dir => $data_dir ) } qr/conf_file or plugins required/;
     throws_ok { Code::TidyAll->new( plugins  => {} ) } qr/conf_file or root_dir required/;
+
+    my $root_dir = $self->create_dir( { "foo/bar.txt" => "abc" } );
+    my $ct = Code::TidyAll->new( plugins => { $UpperText => {} }, root_dir => $root_dir );
+    my $output = capture_stdout { $ct->process_paths("$root_dir/foo/bar.txt") };
+    is( $output,                            "foo/bar.txt\n", "filename output" );
+    is( read_file("$root_dir/foo/bar.txt"), "ABC",           "tidied" );
+    $output = capture_stdout { $ct->process_paths("$root_dir/foo") };
+    is( $output, "foo: skipping dir, not in recursive mode\n" );
+    my $other_dir = realpath( tempdir_simple() );
+    write_file( "$other_dir/foo.txt", "ABC" );
+    $output = capture_stdout { $ct->process_paths("$other_dir/foo.txt") };
+    like( $output, qr/foo.txt: skipping, not underneath root dir/ );
 }
 
 1;

-- 
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