From c9187d233f5dd6416c5cd9e2ef26e2bd45267c2b Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Fri, 10 Sep 2021 18:07:33 -0700 Subject: [PATCH] added test for -novalign and update manual --- bin/perltidy | 30 ++++-- t/snippets/expect/novalign.def | 9 ++ t/snippets/expect/novalign.novalign | 9 ++ t/snippets/novalign.in | 9 ++ t/snippets/novalign.par | 1 + t/snippets/packing_list.txt | 2 + t/snippets25.t | 141 ++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+), 10 deletions(-) create mode 100644 t/snippets/expect/novalign.def create mode 100644 t/snippets/expect/novalign.novalign create mode 100644 t/snippets/novalign.in create mode 100644 t/snippets/novalign.par create mode 100644 t/snippets25.t diff --git a/bin/perltidy b/bin/perltidy index 7041cf67..49c7411a 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -3130,20 +3130,22 @@ will flatten this down to one line: # perltidy (default) my @list = ( 1, 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, ); -This formatting loses important information. If we place a side comment on one -of the lines, for example, we get the following result with with default formatting -parameters: +This formatting loses the nice structure. If we place a side comment anywhere +between the opening and closing parens, the original line break points are +retained. For example, my @list = ( - 1, # a side comment, comment, or blank keeps list intact + 1, # a side comment forces the original line breakpoints to be kept 1, 1, 1, 2, 1, 1, 3, 3, 1, 1, 4, 6, 4, 1, ); +The side comment can be a single hash symbol without any text. We could achieve the same result with a blank line or full comment -anywhere between the opening and closing parens. +anywhere between the opening and closing parens. Vertical alignment +of the list items will still occur if possible. For another possibility see the -fs flag in L. @@ -3163,9 +3165,8 @@ the original style, yields 1, 3, 3, 1, 1, 4, 6, 4, 1,); -A disadvantage of this flag is that all tables in the file -must already be nicely formatted. - +A disadvantage of this flag compared to the methods discussed above is that all +tables in the file must already be nicely formatted. =item B<-mft=n>, B<--maximum-fields-per-table=n> @@ -4018,8 +4019,8 @@ aligned in the following statement: Proto => 'tcp' ); -Vertical alignment can be completely turned off using B<-novalign>, a flag -mainly intended for debugging. However, vertical alignment can be forced to +Vertical alignment can be completely turned off using the B<-novalign> flag +mentioned below. However, vertical alignment can be forced to stop and restart by selectively introducing blank lines. For example, a blank has been inserted in the following code to keep somewhat similar things aligned. @@ -4050,6 +4051,15 @@ For example, Proto=> 'tcp' ); +=over 4 + +=item B + +The default is to use vertical alignment, but bertical alignment can be +completely turned of with the B<-novalign> flag. + +=back + =head2 Other Controls =over 4 diff --git a/t/snippets/expect/novalign.def b/t/snippets/expect/novalign.def new file mode 100644 index 00000000..61f326db --- /dev/null +++ b/t/snippets/expect/novalign.def @@ -0,0 +1,9 @@ +# simple vertical alignment of '=' and '#' +my $lines = 0; # checksum: #lines +my $bytes = 0; # checksum: #bytes +my $sum = 0; # checksum: system V sum +my $patchdata = 0; # saw patch data +my $pos = 0; # start of patch data +my $endkit = 0; # saw end of kit +my $fail = 0; # failed + diff --git a/t/snippets/expect/novalign.novalign b/t/snippets/expect/novalign.novalign new file mode 100644 index 00000000..ee672bc4 --- /dev/null +++ b/t/snippets/expect/novalign.novalign @@ -0,0 +1,9 @@ +# simple vertical alignment of '=' and '#' +my $lines = 0; # checksum: #lines +my $bytes = 0; # checksum: #bytes +my $sum = 0; # checksum: system V sum +my $patchdata = 0; # saw patch data +my $pos = 0; # start of patch data +my $endkit = 0; # saw end of kit +my $fail = 0; # failed + diff --git a/t/snippets/novalign.in b/t/snippets/novalign.in new file mode 100644 index 00000000..ee672bc4 --- /dev/null +++ b/t/snippets/novalign.in @@ -0,0 +1,9 @@ +# simple vertical alignment of '=' and '#' +my $lines = 0; # checksum: #lines +my $bytes = 0; # checksum: #bytes +my $sum = 0; # checksum: system V sum +my $patchdata = 0; # saw patch data +my $pos = 0; # start of patch data +my $endkit = 0; # saw end of kit +my $fail = 0; # failed + diff --git a/t/snippets/novalign.par b/t/snippets/novalign.par new file mode 100644 index 00000000..230ed038 --- /dev/null +++ b/t/snippets/novalign.par @@ -0,0 +1 @@ +-novalign diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 147bab5c..bffe841d 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -467,3 +467,5 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets25.t novalign.def +../snippets25.t novalign.novalign diff --git a/t/snippets25.t b/t/snippets25.t new file mode 100644 index 00000000..cd91e975 --- /dev/null +++ b/t/snippets25.t @@ -0,0 +1,141 @@ +# Created with: ./make_t.pl + +# Contents: +#1 novalign.def +#2 novalign.novalign + +# To locate test #13 you can search for its name or the string '#13' + +use strict; +use Test::More; +use Carp; +use Perl::Tidy; +my $rparams; +my $rsources; +my $rtests; + +BEGIN { + + ########################################### + # BEGIN SECTION 1: Parameter combinations # + ########################################### + $rparams = { + 'def' => "", + 'novalign' => "-novalign", + }; + + ############################ + # BEGIN SECTION 2: Sources # + ############################ + $rsources = { + + 'novalign' => <<'----------', +# simple vertical alignment of '=' and '#' +my $lines = 0; # checksum: #lines +my $bytes = 0; # checksum: #bytes +my $sum = 0; # checksum: system V sum +my $patchdata = 0; # saw patch data +my $pos = 0; # start of patch data +my $endkit = 0; # saw end of kit +my $fail = 0; # failed + +---------- + }; + + #################################### + # BEGIN SECTION 3: Expected output # + #################################### + $rtests = { + + 'novalign.def' => { + source => "novalign", + params => "def", + expect => <<'#1...........', +# simple vertical alignment of '=' and '#' +my $lines = 0; # checksum: #lines +my $bytes = 0; # checksum: #bytes +my $sum = 0; # checksum: system V sum +my $patchdata = 0; # saw patch data +my $pos = 0; # start of patch data +my $endkit = 0; # saw end of kit +my $fail = 0; # failed + +#1........... + }, + + 'novalign.novalign' => { + source => "novalign", + params => "novalign", + expect => <<'#2...........', +# simple vertical alignment of '=' and '#' +my $lines = 0; # checksum: #lines +my $bytes = 0; # checksum: #bytes +my $sum = 0; # checksum: system V sum +my $patchdata = 0; # saw patch data +my $pos = 0; # start of patch data +my $endkit = 0; # saw end of kit +my $fail = 0; # failed + +#2........... + }, + }; + + my $ntests = 0 + keys %{$rtests}; + plan tests => $ntests; +} + +############### +# EXECUTE TESTS +############### + +foreach my $key ( sort keys %{$rtests} ) { + my $output; + my $sname = $rtests->{$key}->{source}; + my $expect = $rtests->{$key}->{expect}; + my $pname = $rtests->{$key}->{params}; + my $source = $rsources->{$sname}; + my $params = defined($pname) ? $rparams->{$pname} : ""; + my $stderr_string; + my $errorfile_string; + my $err = Perl::Tidy::perltidy( + source => \$source, + destination => \$output, + perltidyrc => \$params, + argv => '', # for safety; hide any ARGV from perltidy + stderr => \$stderr_string, + errorfile => \$errorfile_string, # not used when -se flag is set + ); + if ( $err || $stderr_string || $errorfile_string ) { + print STDERR "Error output received for test '$key'\n"; + if ($err) { + print STDERR "An error flag '$err' was returned\n"; + ok( !$err ); + } + if ($stderr_string) { + print STDERR "---------------------\n"; + print STDERR "<>\n$stderr_string\n"; + print STDERR "---------------------\n"; + ok( !$stderr_string ); + } + if ($errorfile_string) { + print STDERR "---------------------\n"; + print STDERR "<<.ERR file>>\n$errorfile_string\n"; + print STDERR "---------------------\n"; + ok( !$errorfile_string ); + } + } + else { + if ( !is( $output, $expect, $key ) ) { + my $leno = length($output); + my $lene = length($expect); + if ( $leno == $lene ) { + print STDERR +"#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n"; + } + else { + print STDERR +"#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n"; + } + } + } +} -- 2.39.5