1 # Created with: ./make_t.pl
25 # To locate test #13 you can search for its name or the string '#13'
37 ###########################################
38 # BEGIN SECTION 1: Parameter combinations #
39 ###########################################
43 'rt81852' => <<'----------',
50 ############################
51 # BEGIN SECTION 2: Sources #
52 ############################
55 'rt70747' => <<'----------',
56 coerce Q2RawStatGroupArray, from ArrayRef [Q2StatGroup], via {
59 $g->{stats} = [ map { scalar $_->as_array } @{ $g->{stats} } ]; $g;
65 'rt74856' => <<'----------',
73 my $baz = 'something else';
77 'rt78156' => <<'----------',
78 package Some::Class 2.012;
81 'rt78764' => <<'----------',
82 qr/3/ ~~ ['1234'] ? 1 : 0;
83 map { $_ ~~ [ '0', '1' ] ? 'x' : 'o' } @a;
86 'rt79813' => <<'----------',
87 my %hash = ( a => { bbbbbbbbb => {
88 cccccccccc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
92 'rt79947' => <<'----------',
93 try { croak "An Error!"; }
95 print STDERR $error . "\n";
99 'rt80645' => <<'----------',
107 'rt81852' => <<'----------',
113 } while ( $n++ < 10 );
116 'rt81854' => <<'----------',
117 return "this is a descriptive error message"
118 if $res->is_error or not length $data;
121 'rt87502' => <<'----------',
122 if ( @ARGV ~~ { map { $_ => 1 } qw(re restart reload) } ) {
127 'rt93197' => <<'----------',
128 $to = $to->{$_} ||= {} for @key; if (1) {2;} else {3;}
131 'rt94338' => <<'----------',
132 # for-loop in a parenthesized block-map triggered an error message
133 map( { foreach my $item ( '0', '1' ) { print $item} } qw(a b c) );
136 'rt95419' => <<'----------',
142 'rt95708' => <<'----------',
146 when => time(), message => 'abc' };
147 my $json = encode_json {
148 when => time(), message => 'abc' };
149 my $json2 = encode_json + {
150 when => time(), message => 'abc' };
153 'rt96021' => <<'----------',
162 'rt96101' => <<'----------',
163 # Example for rt.cpan.org #96101; Perltidy not properly formatting subroutine
164 # references inside subroutine execution.
166 # closing brace of second sub should get outdented here
170 'authentication' => {
171 'autoload_user' => 1,
172 'session_key' => rand(),
174 return HaloVP::Users->load(@_);
176 'validate_user' => sub {
177 return HaloVP::Users->login(@_);
185 'rt98902' => <<'----------',
188 beta => 2, gamma => 3,
194 padding => ( ' ' x $_ ),
198 'rt99961' => <<'----------',
199 %thing = %{ print qq[blah1\n]; $b; };
203 ####################################
204 # BEGIN SECTION 3: Expected output #
205 ####################################
208 'rt70747.rt70747' => {
211 expect => <<'#1...........',
212 coerce Q2RawStatGroupArray, from ArrayRef [Q2StatGroup], via {
216 $g->{stats} = [ map { scalar $_->as_array } @{ $g->{stats} } ];
227 expect => <<'#2...........',
235 my $baz = 'something else';
243 expect => <<'#3...........',
244 package Some::Class 2.012;
251 expect => <<'#4...........',
252 qr/3/ ~~ ['1234'] ? 1 : 0;
253 map { $_ ~~ [ '0', '1' ] ? 'x' : 'o' } @a;
260 expect => <<'#5...........',
264 cccccccccc => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
274 expect => <<'#6...........',
275 try { croak "An Error!"; }
277 print STDERR $error . "\n";
285 expect => <<'#7...........',
297 expect => <<'#8...........',
303 } while ( $n++ < 10 );
307 'rt81852.rt81852' => {
310 expect => <<'#9...........',
314 }} while ($n++ < 10);
321 expect => <<'#10...........',
322 return "this is a descriptive error message"
323 if $res->is_error or not length $data;
330 expect => <<'#11...........',
331 if ( @ARGV ~~ { map { $_ => 1 } qw(re restart reload) } ) {
341 expect => <<'#12...........',
342 $to = $to->{$_} ||= {} for @key;
351 expect => <<'#13...........',
352 # for-loop in a parenthesized block-map triggered an error message
354 foreach my $item ( '0', '1' ) {
364 expect => <<'#14...........',
374 expect => <<'#15...........',
381 my $json = encode_json {
385 my $json2 = encode_json + {
395 expect => <<'#16...........',
408 expect => <<'#17...........',
409 # Example for rt.cpan.org #96101; Perltidy not properly formatting subroutine
410 # references inside subroutine execution.
412 # closing brace of second sub should get outdented here
416 'authentication' => {
417 'autoload_user' => 1,
418 'session_key' => rand(),
420 return HaloVP::Users->load(@_);
422 'validate_user' => sub {
423 return HaloVP::Users->login(@_);
435 expect => <<'#18...........',
443 map { { number => $_, character => chr $_, padding => ( ' ' x $_ ), } }
448 'rt98902.rt98902' => {
451 expect => <<'#19...........',
454 beta => 2, gamma => 3,
461 padding => ( ' ' x $_ ),
470 expect => <<'#20...........',
479 my $ntests = 0 + keys %{$rtests};
480 plan tests => $ntests;
487 foreach my $key ( sort keys %{$rtests} ) {
489 my $sname = $rtests->{$key}->{source};
490 my $expect = $rtests->{$key}->{expect};
491 my $pname = $rtests->{$key}->{params};
492 my $source = $rsources->{$sname};
493 my $params = defined($pname) ? $rparams->{$pname} : "";
495 my $errorfile_string;
496 my $err = Perl::Tidy::perltidy(
498 destination => \$output,
499 perltidyrc => \$params,
500 argv => '', # for safety; hide any ARGV from perltidy
501 stderr => \$stderr_string,
502 errorfile => \$errorfile_string, # not used when -se flag is set
504 if ( $err || $stderr_string || $errorfile_string ) {
505 print STDERR "Error output received for test '$key'\n";
507 print STDERR "An error flag '$err' was returned\n";
510 if ($stderr_string) {
511 print STDERR "---------------------\n";
512 print STDERR "<<STDERR>>\n$stderr_string\n";
513 print STDERR "---------------------\n";
514 ok( !$stderr_string );
516 if ($errorfile_string) {
517 print STDERR "---------------------\n";
518 print STDERR "<<.ERR file>>\n$errorfile_string\n";
519 print STDERR "---------------------\n";
520 ok( !$errorfile_string );
524 if ( !is( $output, $expect, $key ) ) {
525 my $leno = length($output);
526 my $lene = length($expect);
527 if ( $leno == $lene ) {
529 "#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
533 "#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";