[libcode-tidyall-perl] 302/374: In -p/--pipe mode, mirror input to output in case of error (Justin Devuyst)
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:26:39 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 649de05f71b3a422804abd563714d059be259024
Author: Jonathan Swartz <swartz at pobox.com>
Date: Wed Oct 3 15:31:09 2012 -0700
In -p/--pipe mode, mirror input to output in case of error (Justin Devuyst)
---
Changes | 3 ++-
bin/tidyall | 15 +++++++--------
lib/Code/TidyAll/t/Basic.pm | 11 ++++++++++-
3 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/Changes b/Changes
index 6360e9c..5361211 100644
--- a/Changes
+++ b/Changes
@@ -6,7 +6,8 @@ Revision history for Code-TidyAll
* Improvements
- Add -r/--recursive flag to process directories recursively
- - Add --version
+ - In -p/--pipe mode, mirror input to output in case of error (Justin Devuyst)
+ - Add --version option
- Make git prereceive hook more modular, so it can be combined with other checks
0.13 Sep 30, 2012
diff --git a/bin/tidyall b/bin/tidyall
index f096c77..41b3a73 100755
--- a/bin/tidyall
+++ b/bin/tidyall
@@ -157,9 +157,11 @@ sub handle_pipe {
print STDERR $output;
if ( my $error = $result->error ) {
+ print $source; # Error already printed above
return 1;
}
elsif ( $result->state eq 'no_match' ) {
+ print $source;
print STDERR "No plugins apply for '$pipe' in config";
return 1;
}
@@ -450,14 +452,11 @@ L</MODES>.
=item -p path, --pipe path
-Read content from STDIN instead of from a file. This option takes a filename
-argument, relative or absolute, which will be used to determine which plugins
-to apply and also where to start looking upwards for the configuration file.
-The file will not actually be read and does need even need to exist.
-
-If an error occurs, it will be output to STDERR and tidyall will exit with
-status 1. Otherwise, the tidied content will be output to STDOUT and tidyall
-will exit with status 0.
+Read content from STDIN and write the resulting content to STDOUT. If
+successful, tidyall exits with status 0. If an error occurs, tidyall outputs
+the error message to STDERR, I<mirrors the input content> to STDOUT with no
+changes, and exits with status 1. The mirroring means that you can safely pipe
+to your destination regardless of whether an error occurs.
When specifying this option you must specify exactly one filename, relative or
absolute, which will be used to determine which plugins to apply and also where
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index 55d68b8..2eb007e 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -353,7 +353,7 @@ sub test_cli : Tests {
is( read_file("$root_dir/subdir/foo.txt"), "BYEBYEBYE", "foo.txt tidied" );
is( read_file("$root_dir/subdir/foo2.txt"), "bye", "foo2.txt not tidied" );
- # Test -p / --pipe
+ # -p / --pipe success
#
my ( $stdout, $stderr ) = capture {
open( my $fh, "|-", "$^X", "bin/tidyall", "-p", "$root_dir/does_not_exist/foo.txt" );
@@ -361,6 +361,15 @@ sub test_cli : Tests {
};
is( $stdout, "ECHOECHOECHO", "pipe: stdin tidied" );
unlike( $stderr, qr/\S/, "pipe: no stderr" );
+
+ # -p / --pipe error
+ #
+ ( $stdout, $stderr ) = capture {
+ open( my $fh, "|-", "$^X", "bin/tidyall", "--pipe", "$root_dir/foo.txt" );
+ print $fh "abc1";
+ };
+ is( $stdout, "abc1", "pipe: stdin mirrored to stdout" );
+ like( $stderr, qr/non-alpha content found/ );
}
}
--
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