]> git.donarmstrong.com Git - perltidy.git/commitdiff
added --assert-untidy
authorSteve Hancock <perltidy@users.sourceforge.net>
Thu, 5 Sep 2019 15:26:01 +0000 (08:26 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Thu, 5 Sep 2019 15:26:01 +0000 (08:26 -0700)
CHANGES.md
bin/perltidy
lib/Perl/Tidy.pm

index 346d457eaab8f3819fd5f0db808fd60cf970b8e7..ee2c2b92ac1b4df940e944d2bebf71ee3c03b579 100644 (file)
@@ -2,9 +2,10 @@
 
 ## 2019 06 01.01
 
-    - implement issue RT#130425: check mode.  A new flag '--assert-unchanged'
+    - implement issue RT#130425: check mode.  A new flag '--assert-tidy'
       will cause an error message if the output script is not identical to
-      the input script. 
+      the input script. For completeness, the opposite flag '--assert-untidy'
+      has also been added.
 
     - iteration speedup for unchanged code.  Previously, when iterations were
       requested, at least two formatting passes were made. Now just a single pass
index 1b3b10506669cd3eb06a371ed75efe65d09092d7..d158067026048fd9d7024ad2d0fa987fa4d29c02 100755 (executable)
@@ -359,11 +359,22 @@ error messages, perltidy skips files identified by the system as non-text.
 However, valid perl scripts containing binary data may sometimes be identified
 as non-text, and this flag forces perltidy to process them.
 
-=item B<-auc>,   B<--assert-unchanged>      
+=item B<-ast>,   B<--assert-tidy>      
+
+This flag asserts that the input and output code streams are identical, or in
+other words that the input code is already 'tidy' according to the formatting
+parameters.  If this is not the case, an error message noting this is produced.
+The test for this is made by comparing an MD5 hash value for the input and
+output code streams. This flag has no other effect on the functioning of
+perltidy.  This might be useful for certain code maintenance operations.
+
+=item B<-asu>,   B<--assert-untidy>      
+
+This flag asserts that the input and output code streams are different, or in
+other words that the input code is 'untidy' according to the formatting
+parameters.  If this is not the case, an error message noting this is produced.
+This flag has no other effect on the functioning of perltidy.
 
-This flag asserts that the input and output files are identical, and produces
-an error message if they are not.  It has no other effect on the functioning of
-perltidy.  This can be used to identify files which do not need to be updated.  
 
 =back
 
index ffc136584e32538e960cea65ef93fdb22c1d8463..4cd939c0fc0cf4147cf8efc3aa9759bd0f98df34 100644 (file)
@@ -881,7 +881,8 @@ EOM
             $prefilter
             || (   $rOpts_character_encoding
                 && $rOpts_character_encoding eq 'utf8' )
-            || $rOpts->{'assert-unchanged'}
+            || $rOpts->{'assert-tidy'}
+            || $rOpts->{'assert-untidy'}
             || $do_convergence_test
           )
         {
@@ -907,7 +908,7 @@ EOM
             }
 
             # MD5 sum of input file is evaluated before any prefilter
-            if ( $rOpts->{'assert-unchanged'} ) {
+            if ( $rOpts->{'assert-tidy'} || $rOpts->{'assert-untidy'} ) {
                 $digest_input = $md5_hex->($buf);
             }
 
@@ -1020,7 +1021,10 @@ EOM
         $line_separator = "\n" unless defined($line_separator);
 
         my ( $sink_object, $postfilter_buffer );
-        if ( $postfilter || $rOpts->{'assert-unchanged'} ) {
+        if (   $postfilter
+            || $rOpts->{'assert-tidy'}
+            || $rOpts->{'assert-untidy'} )
+        {
             $sink_object =
               Perl::Tidy::LineSink->new( \$postfilter_buffer, $tee_file,
                 $line_separator, $rOpts, $rpending_logfile_message, $binmode );
@@ -1238,7 +1242,10 @@ EOM
         #---------------------------------------------------------------
         # Perform any postfilter operation
         #---------------------------------------------------------------
-        if ( $postfilter || $rOpts->{'assert-unchanged'} ) {
+        if (   $postfilter
+            || $rOpts->{'assert-tidy'}
+            || $rOpts->{'assert-untidy'} )
+        {
             $sink_object->close_output_file();
             $sink_object =
               Perl::Tidy::LineSink->new( $output_file, $tee_file,
@@ -1250,11 +1257,19 @@ EOM
               : $postfilter_buffer;
 
             # Check if file changed if requested, but only after any postfilter
-            if ( $rOpts->{'assert-unchanged'} ) {
+            if ( $rOpts->{'assert-tidy'} ) {
+                my $digest_output = $md5_hex->($buf);
+                if ( $digest_output ne $digest_input ) {
+                    $logger_object->warning(
+"assertion failure: '--assert-tidy' is set but output differs from input\n"
+                    );
+                }
+            }
+            if ( $rOpts->{'assert-untidy'} ) {
                 my $digest_output = $md5_hex->($buf);
                 if ( $digest_output ne $digest_input ) {
                     $logger_object->warning(
-"assertion failure: '--assert-unchanged' is set but output differs from input\n"
+"assertion failure: '--assert-untidy' is set but output equals input\n"
                     );
                 }
             }
@@ -1750,7 +1765,8 @@ sub generate_options {
     $add_option->( 'tabs',                         't',    '!' );
     $add_option->( 'default-tabsize',              'dt',   '=i' );
     $add_option->( 'extended-syntax',              'xs',   '!' );
-    $add_option->( 'assert-unchanged',             'auc',  '!' );
+    $add_option->( 'assert-tidy',                  'ast',  '!' );
+    $add_option->( 'assert-untidy',                'asu',  '!' );
 
     ########################################
     $category = 2;    # Code indentation control