[libcode-tidyall-perl] 50/374: add quiet

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:25:47 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 5803d878c80eceb21d85b13e04c60241b5030e56
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Tue Jun 26 06:28:10 2012 -0700

    add quiet
---
 bin/tidyall                 |    3 +++
 lib/Code/TidyAll.pm         |    7 +++++--
 lib/Code/TidyAll/t/Basic.pm |   28 ++++++++++++++++++++++++++++
 3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/bin/tidyall b/bin/tidyall
index 41d2cf6..0e2fa17 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -27,6 +27,7 @@ GetOptions(
     'root-dir=s'   => \$params{root_dir},
     'a|all'        => \$all,
     'h|help'       => \$help,
+    'q|quiet'      => \$params{quiet},
     'v|verbose'    => \$params{verbose},
 ) or usage();
 
@@ -92,6 +93,8 @@ tidyall - Your all-in-one code tidier and validator
 
  -a, --all        Process all files in the project
  -h, --help       Print help message
+ -q, --quiet      Suppress output except for errors
+ -v, --verbose    Show extra output
  --backup-ttl     When backup files can be purged. Defaults to "1h"
  --class          Code::TidyAll subclass to use. Defaults to "Code::TidyAll"
  --conf-file      Specify conf file explicitly; usually inferred from specified files or cwd
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index 889c54c..a2074a6 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -23,6 +23,7 @@ sub valid_params {
       no_cache
       plugins
       root_dir
+      quiet
       verbose
     );
 }
@@ -144,7 +145,7 @@ sub _process_file {
     my @plugins = @{ $self->matched_files->{$file} || [] };
     my $small_path = $self->_small_path($file);
     if ( !@plugins ) {
-        $self->msg( "[no plugins apply] %s", $small_path );
+        $self->msg( "[no plugins apply] %s", $small_path ) unless $self->quiet;
         return;
     }
 
@@ -170,7 +171,7 @@ sub _process_file {
     my $status       = $was_tidied ? "[tidied]  " : "[checked] ";
     my $plugin_names =
       $self->verbose ? sprintf( " (%s)", join( ", ", map { $_->name } @plugins ) ) : "";
-    $self->msg( "%s%s%s", $status, $small_path, $plugin_names );
+    $self->msg( "%s%s%s", $status, $small_path, $plugin_names ) unless $self->quiet;
     $self->_backup_file( $file, $orig_contents ) if $was_tidied;
 
     if ($error) {
@@ -392,6 +393,8 @@ equivalent to what would be parsed out of the sections in C<tidyall.ini>.
 
 =item root_dir
 
+=item quiet
+
 =item verbose
 
 These options are the same as the equivalent C<tidyall> command-line options,
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index 799f813..914115f 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -91,6 +91,34 @@ sub test_basic : Tests {
     );
 }
 
+sub test_quiet_and_verbose : Tests {
+    my $self = shift;
+
+    foreach my $mode ( 'normal', 'quiet', 'verbose' ) {
+        foreach my $error ( 0, 1 ) {
+            my $root_dir = $self->create_dir( { "foo.txt" => ( $error ? "123" : "abc" ) } );
+            my $output = capture_stdout {
+                my $ct = Code::TidyAll->new(
+                    plugins  => {%UpperText},
+                    root_dir => $root_dir,
+                    ( $mode eq 'normal' ? () : ( $mode => 1 ) )
+                );
+                $ct->process_files("$root_dir/foo.txt");
+            };
+            if ($error) {
+                like( $output, qr/non-alpha content found/ );
+            }
+            else {
+                is( $output, "[tidied]  foo.txt\n" ) if $mode eq 'normal';
+                is( $output, "" ) if $mode eq 'quiet';
+                like( $output,
+                    qr/constructing Code::TidyAll with these params.*purging old backups.*\[tidied\]  foo\.txt \(\+Code::TidyAll::Test::Plugin::UpperText\)/s
+                ) if $mode eq 'verbose';
+            }
+        }
+    }
+}
+
 sub test_caching_and_backups : Tests {
     my $self = shift;
 

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