]> git.donarmstrong.com Git - perltidy.git/commitdiff
fixes for RT#130297: exit with nonzero exit status if any output to stderr
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 15 Aug 2019 00:58:49 +0000 (17:58 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 15 Aug 2019 00:58:49 +0000 (17:58 -0700)
CHANGES.md
bin/perltidy
lib/Perl/Tidy.pm

index 0941caae641a78ee43f6b313748013e588e18edc..cd170795d123e6bfa86481cff3c756f540ef3652 100644 (file)
@@ -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.
 
index 753da1856ffb48b1ba1a4ca63641480d17521c16..c0fdd92b76608685cf56eec17cb4d1198754fccf 100755 (executable)
@@ -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__
 
index 341a18dfd1fa28222029bae169df4ee8b216a6f0..adbaeb5dbf44126526647a56a35b8961f91a64dd 100644 (file)
@@ -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;