From: Steve Hancock Date: Thu, 5 Sep 2019 15:26:01 +0000 (-0700) Subject: added --assert-untidy X-Git-Tag: 20190915~3 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=574bb3e9e353e9804d9cb1f0bc5932e01fd5a2ab;p=perltidy.git added --assert-untidy --- diff --git a/CHANGES.md b/CHANGES.md index 346d457e..ee2c2b92 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/bin/perltidy b/bin/perltidy index 1b3b1050..d1580670 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -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 diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm index ffc13658..4cd939c0 100644 --- a/lib/Perl/Tidy.pm +++ b/lib/Perl/Tidy.pm @@ -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