1 # Created with: ./make_t.pl
24 # To locate test #13 you can search for its name or the string '#13'
36 ###########################################
37 # BEGIN SECTION 1: Parameter combinations #
38 ###########################################
42 'fpva2' => <<'----------',
43 -sfp -wls='->' -wrs='->' -nfpva
45 'git51' => <<'----------',
46 --maximum-line-length=120
49 --entab-leading-whitespace=4
50 --continuation-indentation=4
51 --extended-continuation-indentation
52 --no-delete-old-newlines
53 --no-outdent-long-lines
57 --opening-sub-brace-on-new-line
58 --square-bracket-tightness=2
63 -sal='first any sum sum0 reduce'
65 'git54' => "-bbp=3 -bbpi=2 -ci=4 -lp",
67 'lpxl3' => <<'----------',
70 'lpxl4' => <<'----------',
73 'lpxl5' => <<'----------',
76 'rt136417' => "-vtc=3",
79 ############################
80 # BEGIN SECTION 2: Sources #
81 ############################
84 'align35' => <<'----------',
85 # different module names, do not align commas (fixes rt136416)
86 use File::Spec::Functions 'catfile', 'catdir';
87 use Mojo::Base 'Mojolicious', '-signatures';
89 # same module names, align fat commas
90 use constant PI => 4 * atan2 1, 1;
91 use constant TWOPI => 2 * PI;
92 use constant FOURPI => 4 * PI;
94 # same module names, align commas
95 use TestCounter '3rd-party', 0, '3rd-party no longer visible';
96 use TestCounter 'replace', 1, 'replacement now visible';
97 use TestCounter 'root';
99 # same module name, align fat commas but not commas
100 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
101 use constant COUNTUP => reverse 1, 2, 3, 4, 5;
102 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
105 'code_skipping' => <<'----------',
106 %Hdr=%U2E=%E2U=%Fallback=();
107 $in_charmap=$nerror=$nwarning=0;
109 #<<V code skipping: perltidy will pass this verbatim without error checking
118 'fpva' => <<'----------',
119 log_something_with_long_function( 'This is a log message.', 2 );
120 Coro::AnyEvent::sleep( 3, 4 );
124 $self -> method ( 'parameter_0', 'parameter_1' );
125 $self -> method_with_long_name ( 'parameter_0', 'parameter_1' );
128 'git51' => <<'----------',
129 Type::Libraries->setup_class(
133 Types::Common::Numeric
138 'git54' => <<'----------',
139 # testing sensitivity to excess commas
194 'git63' => <<'----------',
195 my $fragment = $parser-> #parse_html_string
196 parse_balanced_chunk($I);
199 'lpxl' => <<'----------',
200 # simple function call
201 my $loanlength = getLoanLength(
202 $borrower->{'categorycode'}, # sc1
203 $iteminformation->{'itemtype'},
204 $borrower->{'branchcode'} # sc3
207 # function call, more than one level deep
208 my $o = very::long::class::name->new(
216 # function call with sublist
219 "Extra-Parameters: " . join("<->", $extra_parms),
220 "Config: " . join("<->", %config)
223 # simple function call with code block
224 $m->command(-label => 'Save',
225 -command => sub { print "DOS\n"; save_dialog($win); });
227 # function call, ternary in list
229 OptArgs2::Result->usage(
230 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
231 'usage: ' . $usage . "\n" );
233 # not a function call
241 # 'local' is a keyword, not a user function
243 $len, $pts, @colspec, $char, $cols,
244 $repeat, $celldata, $at_text, $after_text
247 # square bracket with sublists
249 ListElem->new(id => 0, val => 100),
250 ListElem->new(id => 2, val => 50),
251 ListElem->new(id => 1, val => 10),
254 # curly brace with sublists
256 cat => {nap => "lap", eat => "meat"},
257 dog => {prowl => "growl", pool => "drool"},
258 mouse => {nibble => "kibble"},
262 'numbers' => <<'----------',
280 0.00000000000000000000000000000000000000000000000000000000000000000001,
283 0o12_345, # optional 'o' and 'O' added in perl v5.33.5
288 'pretok' => <<'----------',
289 # test sub split_pretoken
290 my$s1=$^??"def":"not def";
291 my$s2=$^ ?"def":"not def";
298 my$s8='hi'.'s'x10if(1);
299 my$s9='merci'x0.1e4.$s8;
302 'rt136417' => <<'----------',
314 ####################################
315 # BEGIN SECTION 3: Expected output #
316 ####################################
322 expect => <<'#1...........',
323 # testing sensitivity to excess commas
376 expect => <<'#2...........',
377 # testing sensitivity to excess commas
436 expect => <<'#3...........',
437 log_something_with_long_function( 'This is a log message.', 2 );
438 Coro::AnyEvent::sleep( 3, 4 );
442 $self->method( 'parameter_0', 'parameter_1' );
443 $self->method_with_long_name( 'parameter_0', 'parameter_1' );
450 expect => <<'#4...........',
451 log_something_with_long_function ( 'This is a log message.', 2 );
452 Coro::AnyEvent::sleep ( 3, 4 );
456 $self->method ( 'parameter_0', 'parameter_1' );
457 $self->method_with_long_name ( 'parameter_0', 'parameter_1' );
464 expect => <<'#5...........',
465 log_something_with_long_function ( 'This is a log message.', 2 );
466 Coro::AnyEvent::sleep ( 3, 4 );
470 $self -> method ( 'parameter_0', 'parameter_1' );
471 $self -> method_with_long_name ( 'parameter_0', 'parameter_1' );
478 expect => <<'#6...........',
479 # simple function call
480 my $loanlength = getLoanLength(
481 $borrower->{'categorycode'}, # sc1
482 $iteminformation->{'itemtype'},
483 $borrower->{'branchcode'} # sc3
486 # function call, more than one level deep
487 my $o = very::long::class::name->new(
495 # function call with sublist
498 "Extra-Parameters: " . join( "<->", $extra_parms ),
499 "Config: " . join( "<->", %config )
502 # simple function call with code block
505 -command => sub { print "DOS\n"; save_dialog($win); }
508 # function call, ternary in list
509 return OptArgs2::Result->usage(
510 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
511 'usage: ' . $usage . "\n" );
513 # not a function call
521 # 'local' is a keyword, not a user function
523 $len, $pts, @colspec, $char, $cols,
524 $repeat, $celldata, $at_text, $after_text
527 # square bracket with sublists
529 ListElem->new( id => 0, val => 100 ),
530 ListElem->new( id => 2, val => 50 ),
531 ListElem->new( id => 1, val => 10 ),
534 # curly brace with sublists
536 cat => { nap => "lap", eat => "meat" },
537 dog => { prowl => "growl", pool => "drool" },
538 mouse => { nibble => "kibble" },
546 expect => <<'#7...........',
547 # simple function call
548 my $loanlength = getLoanLength(
549 $borrower->{'categorycode'}, # sc1
550 $iteminformation->{'itemtype'},
551 $borrower->{'branchcode'} # sc3
554 # function call, more than one level deep
555 my $o = very::long::class::name->new(
563 # function call with sublist
566 "Extra-Parameters: " . join( "<->", $extra_parms ),
567 "Config: " . join( "<->", %config )
570 # simple function call with code block
571 $m->command( -label => 'Save',
572 -command => sub { print "DOS\n"; save_dialog($win); } );
574 # function call, ternary in list
576 OptArgs2::Result->usage(
577 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
578 'usage: ' . $usage . "\n" );
580 # not a function call
588 # 'local' is a keyword, not a user function
590 $len, $pts, @colspec, $char, $cols,
591 $repeat, $celldata, $at_text, $after_text
594 # square bracket with sublists
596 ListElem->new( id => 0, val => 100 ),
597 ListElem->new( id => 2, val => 50 ),
598 ListElem->new( id => 1, val => 10 ),
601 # curly brace with sublists
603 cat => { nap => "lap", eat => "meat" },
604 dog => { prowl => "growl", pool => "drool" },
605 mouse => { nibble => "kibble" },
613 expect => <<'#8...........',
614 # simple function call
615 my $loanlength = getLoanLength(
616 $borrower->{'categorycode'}, # sc1
617 $iteminformation->{'itemtype'},
618 $borrower->{'branchcode'} # sc3
621 # function call, more than one level deep
622 my $o = very::long::class::name->new(
630 # function call with sublist
633 "Extra-Parameters: " . join( "<->", $extra_parms ),
634 "Config: " . join( "<->", %config )
637 # simple function call with code block
640 -command => sub { print "DOS\n"; save_dialog($win); }
643 # function call, ternary in list
644 return OptArgs2::Result->usage(
645 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
646 'usage: ' . $usage . "\n" );
648 # not a function call
656 # 'local' is a keyword, not a user function
658 $len, $pts, @colspec, $char, $cols,
659 $repeat, $celldata, $at_text, $after_text
662 # square bracket with sublists
664 ListElem->new( id => 0, val => 100 ),
665 ListElem->new( id => 2, val => 50 ),
666 ListElem->new( id => 1, val => 10 ),
669 # curly brace with sublists
671 cat => { nap => "lap", eat => "meat" },
672 dog => { prowl => "growl", pool => "drool" },
673 mouse => { nibble => "kibble" },
681 expect => <<'#9...........',
682 # simple function call
683 my $loanlength = getLoanLength(
684 $borrower->{'categorycode'}, # sc1
685 $iteminformation->{'itemtype'},
686 $borrower->{'branchcode'} # sc3
689 # function call, more than one level deep
690 my $o = very::long::class::name->new(
698 # function call with sublist
701 "Extra-Parameters: " . join( "<->", $extra_parms ),
702 "Config: " . join( "<->", %config )
705 # simple function call with code block
706 $m->command( -label => 'Save',
707 -command => sub { print "DOS\n"; save_dialog($win); } );
709 # function call, ternary in list
711 OptArgs2::Result->usage(
712 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
713 'usage: ' . $usage . "\n" );
715 # not a function call
723 # 'local' is a keyword, not a user function
725 $len, $pts, @colspec, $char, $cols,
726 $repeat, $celldata, $at_text, $after_text
729 # square bracket with sublists
731 ListElem->new( id => 0, val => 100 ),
732 ListElem->new( id => 2, val => 50 ),
733 ListElem->new( id => 1, val => 10 ),
736 # curly brace with sublists
738 cat => { nap => "lap", eat => "meat" },
739 dog => { prowl => "growl", pool => "drool" },
740 mouse => { nibble => "kibble" },
748 expect => <<'#10...........',
749 # simple function call
750 my $loanlength = getLoanLength(
751 $borrower->{'categorycode'}, # sc1
752 $iteminformation->{'itemtype'},
753 $borrower->{'branchcode'} # sc3
756 # function call, more than one level deep
757 my $o = very::long::class::name->new(
765 # function call with sublist
768 "Extra-Parameters: " . join( "<->", $extra_parms ),
769 "Config: " . join( "<->", %config )
772 # simple function call with code block
775 -command => sub { print "DOS\n"; save_dialog($win); }
778 # function call, ternary in list
779 return OptArgs2::Result->usage(
780 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
781 'usage: ' . $usage . "\n" );
783 # not a function call
791 # 'local' is a keyword, not a user function
793 $len, $pts, @colspec, $char, $cols,
794 $repeat, $celldata, $at_text, $after_text
797 # square bracket with sublists
799 ListElem->new( id => 0, val => 100 ),
800 ListElem->new( id => 2, val => 50 ),
801 ListElem->new( id => 1, val => 10 ),
804 # curly brace with sublists
806 cat => { nap => "lap", eat => "meat" },
807 dog => { prowl => "growl", pool => "drool" },
808 mouse => { nibble => "kibble" },
816 expect => <<'#11...........',
817 my $fragment = $parser-> #parse_html_string
818 parse_balanced_chunk($I);
825 expect => <<'#12...........',
826 # different module names, do not align commas (fixes rt136416)
827 use File::Spec::Functions 'catfile', 'catdir';
828 use Mojo::Base 'Mojolicious', '-signatures';
830 # same module names, align fat commas
831 use constant PI => 4 * atan2 1, 1;
832 use constant TWOPI => 2 * PI;
833 use constant FOURPI => 4 * PI;
835 # same module names, align commas
836 use TestCounter '3rd-party', 0, '3rd-party no longer visible';
837 use TestCounter 'replace', 1, 'replacement now visible';
838 use TestCounter 'root';
840 # same module name, align fat commas but not commas
841 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
842 use constant COUNTUP => reverse 1, 2, 3, 4, 5;
843 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
848 source => "rt136417",
850 expect => <<'#13...........',
863 'rt136417.rt136417' => {
864 source => "rt136417",
865 params => "rt136417",
866 expect => <<'#14...........',
881 expect => <<'#15...........',
899 0.00000000000000000000000000000000000000000000000000000000000000000001,
902 0o12_345, # optional 'o' and 'O' added in perl v5.33.5
908 'code_skipping.def' => {
909 source => "code_skipping",
911 expect => <<'#16...........',
912 %Hdr = %U2E = %E2U = %Fallback = ();
913 $in_charmap = $nerror = $nwarning = 0;
915 #<<V code skipping: perltidy will pass this verbatim without error checking
928 expect => <<'#17...........',
929 Type::Libraries->setup_class(
933 Types::Common::Numeric
942 expect => <<'#18...........',
943 Type::Libraries->setup_class(
947 Types::Common::Numeric
956 expect => <<'#19...........',
957 # test sub split_pretoken
958 my $s1 = $^? ? "def" : "not def";
959 my $s2 = $^ ? "def" : "not def";
960 my $s3 = $^ if ($s2);
961 my $s4 = $^O eq "linux";
962 my $s5 = $^O ne "linux";
963 my $s6 = $^O ne "linux";
965 my $s8 = 'hi' . 's' x 10 if (1);
966 my $s9 = 'merci' x 0.1e4 . $s8;
971 my $ntests = 0 + keys %{$rtests};
972 plan tests => $ntests;
979 foreach my $key ( sort keys %{$rtests} ) {
981 my $sname = $rtests->{$key}->{source};
982 my $expect = $rtests->{$key}->{expect};
983 my $pname = $rtests->{$key}->{params};
984 my $source = $rsources->{$sname};
985 my $params = defined($pname) ? $rparams->{$pname} : "";
987 my $errorfile_string;
988 my $err = Perl::Tidy::perltidy(
990 destination => \$output,
991 perltidyrc => \$params,
992 argv => '', # for safety; hide any ARGV from perltidy
993 stderr => \$stderr_string,
994 errorfile => \$errorfile_string, # not used when -se flag is set
996 if ( $err || $stderr_string || $errorfile_string ) {
997 print STDERR "Error output received for test '$key'\n";
999 print STDERR "An error flag '$err' was returned\n";
1002 if ($stderr_string) {
1003 print STDERR "---------------------\n";
1004 print STDERR "<<STDERR>>\n$stderr_string\n";
1005 print STDERR "---------------------\n";
1006 ok( !$stderr_string );
1008 if ($errorfile_string) {
1009 print STDERR "---------------------\n";
1010 print STDERR "<<.ERR file>>\n$errorfile_string\n";
1011 print STDERR "---------------------\n";
1012 ok( !$errorfile_string );
1016 if ( !is( $output, $expect, $key ) ) {
1017 my $leno = length($output);
1018 my $lene = length($expect);
1019 if ( $leno == $lene ) {
1021 "#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
1025 "#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";