From: Steve Hancock Date: Thu, 15 Aug 2019 00:58:49 +0000 (-0700) Subject: fixes for RT#130297: exit with nonzero exit status if any output to stderr X-Git-Tag: 20190915~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3ee0ca0f13e4ef110d079fb827e745310f1f3dd0;p=perltidy.git fixes for RT#130297: exit with nonzero exit status if any output to stderr --- diff --git a/CHANGES.md b/CHANGES.md index 0941caae..cd170795 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,16 @@ ## 2019 06 01.01 + - fixed issue RT#130297; the perltidy script now exits with a nonzero exit + status if it wrote to the standard error output. Prevously only fatal + run errors produced a non-zero exit flag. Now, even non-fatal messages + requested with the -w flag will cause a non-zero exit flag. The exit + flag now has these values: + + 0 = no errors + 1 = fatal error + 2 = non-fatal error + - added warning message for RT#130008, which warns of conflicting input parameters -iob and -bom or -boc. diff --git a/bin/perltidy b/bin/perltidy index 753da185..c0fdd92b 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -13,7 +13,11 @@ if ( $^O =~ /Mac/ ) { ); } -Perl::Tidy::perltidy( argv => $arg_string ); +# Exit codes returned by perltidy: +# 0 - successful run without errors +# 1 - run terminated with a fatal error +# 2 - successful run but with non-fatal warning messages +exit Perl::Tidy::perltidy( argv => $arg_string ); __END__ diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index 341a18df..adbaeb5d 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -86,6 +86,7 @@ use vars qw{ $missing_file_spec $fh_stderr $rOpts_character_encoding + $Warn_count }; @ISA = qw( Exporter ); @@ -403,7 +404,7 @@ EOM $fh_stderr = *STDERR; } - sub Warn { my $msg = shift; $fh_stderr->print($msg); return } + sub Warn { my $msg = shift; $fh_stderr->print($msg); $Warn_count++; return } sub Exit { my $flag = shift; @@ -1430,8 +1431,25 @@ EOM if $logger_object; } # end of main loop to process all files + # Fix for RT #130297: return a true value if anything was written to the + # standard error output, even non-fatal warning messages, otherwise return + # false. + + # To allow the caller to determine the error severity, these exit codes are + # returned: + # 0 - successful run without errors + # 1 - run terminated with a fatal error + # 2 - successful run but with non-fatal warning messages + + # Note that if perltidy is run with multiple files, any single file with + # errors or warnings will write a line like + # '## Please see file testing.t.ERR' + # to standard output for each file with errors, so the flag will be true, + # even only some of the multiple files may have had errors. + NORMAL_EXIT: - return 0; + my $ret = $Warn_count ? 2 : 0; + return $ret; ERROR_EXIT: return 1;