1 # Created with: ./make_t.pl
21 # To locate test #13 you can search for its name or the string '#13'
33 ###########################################
34 # BEGIN SECTION 1: Parameter combinations #
35 ###########################################
39 'fpva2' => "-sfp -nfpva",
40 'git54' => "-bbp=3 -bbpi=2 -ci=4 -lp",
42 'lpxl3' => <<'----------',
45 'lpxl4' => <<'----------',
48 'lpxl5' => <<'----------',
51 'rt136417' => "-vtc=3",
54 ############################
55 # BEGIN SECTION 2: Sources #
56 ############################
59 'align35' => <<'----------',
60 # different module names, do not align commas (fixes rt136416)
61 use File::Spec::Functions 'catfile', 'catdir';
62 use Mojo::Base 'Mojolicious', '-signatures';
64 # same module names, align fat commas
65 use constant PI => 4 * atan2 1, 1;
66 use constant TWOPI => 2 * PI;
67 use constant FOURPI => 4 * PI;
69 # same module names, align commas
70 use TestCounter '3rd-party', 0, '3rd-party no longer visible';
71 use TestCounter 'replace', 1, 'replacement now visible';
72 use TestCounter 'root';
74 # same module name, align fat commas but not commas
75 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
76 use constant COUNTUP => reverse 1, 2, 3, 4, 5;
77 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
80 'code_skipping' => <<'----------',
81 %Hdr=%U2E=%E2U=%Fallback=();
82 $in_charmap=$nerror=$nwarning=0;
84 #<<V code skipping: perltidy will pass this verbatim without error checking
93 'fpva' => <<'----------',
94 log_something_with_long_function( 'This is a log message.', 2 );
95 Coro::AnyEvent::sleep( 3, 4 );
101 'git54' => <<'----------',
102 # testing sensitivity to excess commas
157 'git63' => <<'----------',
158 my $fragment = $parser-> #parse_html_string
159 parse_balanced_chunk($I);
162 'lpxl' => <<'----------',
163 # simple function call
164 my $loanlength = getLoanLength(
165 $borrower->{'categorycode'}, # sc1
166 $iteminformation->{'itemtype'},
167 $borrower->{'branchcode'} # sc3
170 # function call, more than one level deep
171 my $o = very::long::class::name->new(
179 # function call with sublist
182 "Extra-Parameters: " . join("<->", $extra_parms),
183 "Config: " . join("<->", %config)
186 # simple function call with code block
187 $m->command(-label => 'Save',
188 -command => sub { print "DOS\n"; save_dialog($win); });
190 # function call, ternary in list
192 OptArgs2::Result->usage(
193 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
194 'usage: ' . $usage . "\n" );
196 # not a function call
204 # 'local' is a keyword, not a user function
206 $len, $pts, @colspec, $char, $cols,
207 $repeat, $celldata, $at_text, $after_text
210 # square bracket with sublists
212 ListElem->new(id => 0, val => 100),
213 ListElem->new(id => 2, val => 50),
214 ListElem->new(id => 1, val => 10),
217 # curly brace with sublists
219 cat => {nap => "lap", eat => "meat"},
220 dog => {prowl => "growl", pool => "drool"},
221 mouse => {nibble => "kibble"},
225 'numbers' => <<'----------',
243 0.00000000000000000000000000000000000000000000000000000000000000000001,
246 0o12_345, # optional 'o' and 'O' added in perl v5.33.5
251 'rt136417' => <<'----------',
263 ####################################
264 # BEGIN SECTION 3: Expected output #
265 ####################################
271 expect => <<'#1...........',
272 # testing sensitivity to excess commas
325 expect => <<'#2...........',
326 # testing sensitivity to excess commas
385 expect => <<'#3...........',
386 log_something_with_long_function( 'This is a log message.', 2 );
387 Coro::AnyEvent::sleep( 3, 4 );
397 expect => <<'#4...........',
398 log_something_with_long_function ( 'This is a log message.', 2 );
399 Coro::AnyEvent::sleep ( 3, 4 );
409 expect => <<'#5...........',
410 log_something_with_long_function ( 'This is a log message.', 2 );
411 Coro::AnyEvent::sleep ( 3, 4 );
421 expect => <<'#6...........',
422 # simple function call
423 my $loanlength = getLoanLength(
424 $borrower->{'categorycode'}, # sc1
425 $iteminformation->{'itemtype'},
426 $borrower->{'branchcode'} # sc3
429 # function call, more than one level deep
430 my $o = very::long::class::name->new(
438 # function call with sublist
441 "Extra-Parameters: " . join( "<->", $extra_parms ),
442 "Config: " . join( "<->", %config )
445 # simple function call with code block
448 -command => sub { print "DOS\n"; save_dialog($win); }
451 # function call, ternary in list
452 return OptArgs2::Result->usage(
453 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
454 'usage: ' . $usage . "\n" );
456 # not a function call
464 # 'local' is a keyword, not a user function
466 $len, $pts, @colspec, $char, $cols,
467 $repeat, $celldata, $at_text, $after_text
470 # square bracket with sublists
472 ListElem->new( id => 0, val => 100 ),
473 ListElem->new( id => 2, val => 50 ),
474 ListElem->new( id => 1, val => 10 ),
477 # curly brace with sublists
479 cat => { nap => "lap", eat => "meat" },
480 dog => { prowl => "growl", pool => "drool" },
481 mouse => { nibble => "kibble" },
489 expect => <<'#7...........',
490 # simple function call
491 my $loanlength = getLoanLength(
492 $borrower->{'categorycode'}, # sc1
493 $iteminformation->{'itemtype'},
494 $borrower->{'branchcode'} # sc3
497 # function call, more than one level deep
498 my $o = very::long::class::name->new(
506 # function call with sublist
509 "Extra-Parameters: " . join( "<->", $extra_parms ),
510 "Config: " . join( "<->", %config )
513 # simple function call with code block
514 $m->command( -label => 'Save',
515 -command => sub { print "DOS\n"; save_dialog($win); } );
517 # function call, ternary in list
519 OptArgs2::Result->usage(
520 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
521 'usage: ' . $usage . "\n" );
523 # not a function call
531 # 'local' is a keyword, not a user function
533 $len, $pts, @colspec, $char, $cols,
534 $repeat, $celldata, $at_text, $after_text
537 # square bracket with sublists
539 ListElem->new( id => 0, val => 100 ),
540 ListElem->new( id => 2, val => 50 ),
541 ListElem->new( id => 1, val => 10 ),
544 # curly brace with sublists
546 cat => { nap => "lap", eat => "meat" },
547 dog => { prowl => "growl", pool => "drool" },
548 mouse => { nibble => "kibble" },
556 expect => <<'#8...........',
557 # simple function call
558 my $loanlength = getLoanLength(
559 $borrower->{'categorycode'}, # sc1
560 $iteminformation->{'itemtype'},
561 $borrower->{'branchcode'} # sc3
564 # function call, more than one level deep
565 my $o = very::long::class::name->new(
573 # function call with sublist
576 "Extra-Parameters: " . join( "<->", $extra_parms ),
577 "Config: " . join( "<->", %config )
580 # simple function call with code block
583 -command => sub { print "DOS\n"; save_dialog($win); } );
585 # function call, ternary in list
587 OptArgs2::Result->usage(
588 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
589 'usage: ' . $usage . "\n" );
591 # not a function call
599 # 'local' is a keyword, not a user function
601 $len, $pts, @colspec, $char, $cols,
602 $repeat, $celldata, $at_text, $after_text
605 # square bracket with sublists
607 ListElem->new( id => 0, val => 100 ),
608 ListElem->new( id => 2, val => 50 ),
609 ListElem->new( id => 1, val => 10 ),
612 # curly brace with sublists
614 cat => { nap => "lap", eat => "meat" },
615 dog => { prowl => "growl", pool => "drool" },
616 mouse => { nibble => "kibble" },
624 expect => <<'#9...........',
625 # simple function call
626 my $loanlength = getLoanLength(
627 $borrower->{'categorycode'}, # sc1
628 $iteminformation->{'itemtype'},
629 $borrower->{'branchcode'} # sc3
632 # function call, more than one level deep
633 my $o = very::long::class::name->new(
641 # function call with sublist
644 "Extra-Parameters: " . join( "<->", $extra_parms ),
645 "Config: " . join( "<->", %config )
648 # simple function call with code block
649 $m->command( -label => 'Save',
650 -command => sub { print "DOS\n"; save_dialog($win); } );
652 # function call, ternary in list
654 OptArgs2::Result->usage(
655 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
656 'usage: ' . $usage . "\n" );
658 # not a function call
666 # 'local' is a keyword, not a user function
668 $len, $pts, @colspec, $char, $cols,
669 $repeat, $celldata, $at_text, $after_text
672 # square bracket with sublists
674 ListElem->new( id => 0, val => 100 ),
675 ListElem->new( id => 2, val => 50 ),
676 ListElem->new( id => 1, val => 10 ),
679 # curly brace with sublists
681 cat => { nap => "lap", eat => "meat" },
682 dog => { prowl => "growl", pool => "drool" },
683 mouse => { nibble => "kibble" },
691 expect => <<'#10...........',
692 # simple function call
693 my $loanlength = getLoanLength(
694 $borrower->{'categorycode'}, # sc1
695 $iteminformation->{'itemtype'},
696 $borrower->{'branchcode'} # sc3
699 # function call, more than one level deep
700 my $o = very::long::class::name->new(
708 # function call with sublist
711 "Extra-Parameters: " . join( "<->", $extra_parms ),
712 "Config: " . join( "<->", %config )
715 # simple function call with code block
718 -command => sub { print "DOS\n"; save_dialog($win); } );
720 # function call, ternary in list
722 OptArgs2::Result->usage(
723 $style == OptArgs2::STYLE_FULL ? 'FullUsage' : 'NormalUsage',
724 'usage: ' . $usage . "\n" );
726 # not a function call
734 # 'local' is a keyword, not a user function
736 $len, $pts, @colspec, $char, $cols,
737 $repeat, $celldata, $at_text, $after_text
740 # square bracket with sublists
742 ListElem->new( id => 0, val => 100 ),
743 ListElem->new( id => 2, val => 50 ),
744 ListElem->new( id => 1, val => 10 ),
747 # curly brace with sublists
749 cat => { nap => "lap", eat => "meat" },
750 dog => { prowl => "growl", pool => "drool" },
751 mouse => { nibble => "kibble" },
759 expect => <<'#11...........',
760 my $fragment = $parser-> #parse_html_string
761 parse_balanced_chunk($I);
768 expect => <<'#12...........',
769 # different module names, do not align commas (fixes rt136416)
770 use File::Spec::Functions 'catfile', 'catdir';
771 use Mojo::Base 'Mojolicious', '-signatures';
773 # same module names, align fat commas
774 use constant PI => 4 * atan2 1, 1;
775 use constant TWOPI => 2 * PI;
776 use constant FOURPI => 4 * PI;
778 # same module names, align commas
779 use TestCounter '3rd-party', 0, '3rd-party no longer visible';
780 use TestCounter 'replace', 1, 'replacement now visible';
781 use TestCounter 'root';
783 # same module name, align fat commas but not commas
784 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
785 use constant COUNTUP => reverse 1, 2, 3, 4, 5;
786 use constant COUNTDOWN => scalar reverse 1, 2, 3, 4, 5;
791 source => "rt136417",
793 expect => <<'#13...........',
806 'rt136417.rt136417' => {
807 source => "rt136417",
808 params => "rt136417",
809 expect => <<'#14...........',
824 expect => <<'#15...........',
842 0.00000000000000000000000000000000000000000000000000000000000000000001,
845 0o12_345, # optional 'o' and 'O' added in perl v5.33.5
851 'code_skipping.def' => {
852 source => "code_skipping",
854 expect => <<'#16...........',
855 %Hdr = %U2E = %E2U = %Fallback = ();
856 $in_charmap = $nerror = $nwarning = 0;
858 #<<V code skipping: perltidy will pass this verbatim without error checking
869 my $ntests = 0 + keys %{$rtests};
870 plan tests => $ntests;
877 foreach my $key ( sort keys %{$rtests} ) {
879 my $sname = $rtests->{$key}->{source};
880 my $expect = $rtests->{$key}->{expect};
881 my $pname = $rtests->{$key}->{params};
882 my $source = $rsources->{$sname};
883 my $params = defined($pname) ? $rparams->{$pname} : "";
885 my $errorfile_string;
886 my $err = Perl::Tidy::perltidy(
888 destination => \$output,
889 perltidyrc => \$params,
890 argv => '', # for safety; hide any ARGV from perltidy
891 stderr => \$stderr_string,
892 errorfile => \$errorfile_string, # not used when -se flag is set
894 if ( $err || $stderr_string || $errorfile_string ) {
895 print STDERR "Error output received for test '$key'\n";
897 print STDERR "An error flag '$err' was returned\n";
900 if ($stderr_string) {
901 print STDERR "---------------------\n";
902 print STDERR "<<STDERR>>\n$stderr_string\n";
903 print STDERR "---------------------\n";
904 ok( !$stderr_string );
906 if ($errorfile_string) {
907 print STDERR "---------------------\n";
908 print STDERR "<<.ERR file>>\n$errorfile_string\n";
909 print STDERR "---------------------\n";
910 ok( !$errorfile_string );
914 if ( !is( $output, $expect, $key ) ) {
915 my $leno = length($output);
916 my $lene = length($expect);
917 if ( $leno == $lene ) {
919 "#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
923 "#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";