1 # Created with: ./make_t.pl
4 #1 misc_tests.misc_tests
11 #8 tightness.tightness1
12 #9 tightness.tightness2
13 #10 tightness.tightness3
18 #15 space_paren.space_paren1
19 #16 space_paren.space_paren2
24 # To locate test #13 you can search for its name or the string '#13'
36 ###########################################
37 # BEGIN SECTION 1: Parameter combinations #
38 ###########################################
41 'braces5' => <<'----------',
46 'maths3' => <<'----------',
47 # test some bizarre spacing around operators
48 -nwls="= / *" -wrs="= / *" -nwrs="+ -" -wls="+ -"
50 'misc_tests' => <<'----------',
51 -sts -ssc -sfs -nsak="my for" -ndsm
53 'outdent1' => <<'----------',
60 'space_paren1' => "-sfp -skp",
61 'space_paren2' => "-sak=push",
62 'tightness1' => "-pt=0 -sbt=0 -bt=0 -bbt=0",
63 'tightness2' => <<'----------',
64 -pt=1 -sbt=1 -bt=1 -bbt=1
67 'tightness3' => <<'----------',
68 -pt=2 -sbt=2 -bt=2 -bbt=2
73 ############################
74 # BEGIN SECTION 2: Sources #
75 ############################
78 'braces' => <<'----------',
80 if ( !defined( $_[0] ) ) {
81 print("Hello, World\n");
89 print("Hello, World\n");
93 my $app = App::perlbrew->new( "install-patchperl", "-q" );
100 Mojo::IOLoop->next_tick(
104 push @kept_alive, pop->kept_alive;
105 Mojo::IOLoop->next_tick( sub { Mojo::IOLoop->stop } );
112 sswitch( $words[ rand @words ] ) {
116 case $words[3]: { 'ok' }
129 'maths' => <<'----------',
130 $tmp = $day - 32075 + 1461 * ( $year + 4800 - ( 14 - $month ) / 12 ) / 4 + 367
131 * ( $month - 2 + ( ( 14 - $month ) / 12 ) * 12 ) / 12 - 3 * ( ( $year + 4900 -
132 ( 14 - $month ) / 12 ) / 100 ) / 4;
134 return ( $r**$n ) * ( pi**( $n / 2 ) ) / ( sqrt(pi) * factorial( 2 * ( int( $n
135 / 2 ) ) + 2 ) / factorial( int( $n / 2 ) + 1 ) / ( 4**( int( $n / 2 ) + 1 ) )
138 $root=-$b+sqrt($b*$b-4.*$a*$c)/(2.*$a);
141 'misc_tests' => <<'----------',
142 for ( @a = @$ap, $u = shift @a; @a; $u = $v ) { ... } # test -sfs
144 $i = 0; ## =1; test -ssc
146 my ( $a, $b, $c ) = @_; # test -nsak="my for"
149 'outdent' => <<'----------',
151 LOOP: while ( $i = <FOTOS> ) {
159 'sbq' => <<'----------',
164 'scbb' => <<'----------',
170 push( @lines, "$w1 $w2 $w3 $w4\n" );
178 'space_paren' => <<'----------',
179 myfunc ( $a, $b, $c ); # test -sfp
180 push ( @array, $val ); # test -skp and also -sak='push'
181 split( /\|/, $txt ); # test -skp and also -sak='push'
182 my ( $v1, $v2 ) = @_; # test -sak='push'
185 'tightness' => <<'----------',
186 if (( my $len_tab = length( $tabstr ) ) > 0) { } # test -pt
187 $width = $col[ $j + $k ] - $col[ $j ]; # test -sbt
188 $obj->{ $parsed_sql->{ 'table' }[0] }; # test -bt
189 %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt
193 ####################################
194 # BEGIN SECTION 3: Expected output #
195 ####################################
198 'misc_tests.misc_tests' => {
199 source => "misc_tests",
200 params => "misc_tests",
201 expect => <<'#1...........',
202 for( @a = @$ap, $u = shift @a ; @a ; $u = $v ) { ... } # test -sfs
204 $i = 0 ; ## =1; test -ssc
209 my( $a, $b, $c ) = @_ ; # test -nsak="my for"
216 expect => <<'#2...........',
218 LOOP: while ( $i = <FOTOS> ) {
227 'outdent.outdent1' => {
229 params => "outdent1",
230 expect => <<'#3...........',
232 LOOP: while ( $i = <FOTOS> ) {
244 expect => <<'#4...........',
253 expect => <<'#5...........',
262 expect => <<'#6...........',
269 source => "tightness",
271 expect => <<'#7...........',
272 if ( ( my $len_tab = length($tabstr) ) > 0 ) { } # test -pt
273 $width = $col[ $j + $k ] - $col[$j]; # test -sbt
274 $obj->{ $parsed_sql->{'table'}[0] }; # test -bt
275 %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt
279 'tightness.tightness1' => {
280 source => "tightness",
281 params => "tightness1",
282 expect => <<'#8...........',
283 if ( ( my $len_tab = length( $tabstr ) ) > 0 ) { } # test -pt
284 $width = $col[ $j + $k ] - $col[ $j ]; # test -sbt
285 $obj->{ $parsed_sql->{ 'table' }[ 0 ] }; # test -bt
286 %bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt
290 'tightness.tightness2' => {
291 source => "tightness",
292 params => "tightness2",
293 expect => <<'#9...........',
294 if ( ( my $len_tab = length($tabstr) ) > 0 ) { } # test -pt
295 $width = $col[ $j + $k ] - $col[$j]; # test -sbt
296 $obj->{ $parsed_sql->{'table'}[0] }; # test -bt
297 %bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.'; # test -bbt
301 'tightness.tightness3' => {
302 source => "tightness",
303 params => "tightness3",
304 expect => <<'#10...........',
305 if ((my $len_tab = length($tabstr)) > 0) { } # test -pt
306 $width = $col[$j + $k] - $col[$j]; # test -sbt
307 $obj->{$parsed_sql->{'table'}[0]}; # test -bt
308 %bf = map {$_ => -M $_} grep {/\.deb$/} dirents '.'; # test -bbt
312 'braces.braces4' => {
315 expect => <<'#11...........',
317 if ( !defined( $_[0] ) ) {
318 print("Hello, World\n");
321 print( $_[0], "\n" );
326 print("Hello, World\n");
330 my $app = App::perlbrew->new( "install-patchperl", "-q" );
338 Mojo::IOLoop->next_tick(
342 push @kept_alive, pop->kept_alive;
343 Mojo::IOLoop->next_tick( sub { Mojo::IOLoop->stop } );
350 sswitch( $words[ rand @words ] ) {
354 case $words[3]: { 'ok' }
371 expect => <<'#12...........',
377 push( @lines, "$w1 $w2 $w3 $w4\n" );
389 expect => <<'#13...........',
395 push( @lines, "$w1 $w2 $w3 $w4\n" );
401 'space_paren.def' => {
402 source => "space_paren",
404 expect => <<'#14...........',
405 myfunc( $a, $b, $c ); # test -sfp
406 push( @array, $val ); # test -skp and also -sak='push'
407 split( /\|/, $txt ); # test -skp and also -sak='push'
408 my ( $v1, $v2 ) = @_; # test -sak='push'
412 'space_paren.space_paren1' => {
413 source => "space_paren",
414 params => "space_paren1",
415 expect => <<'#15...........',
416 myfunc ( $a, $b, $c ); # test -sfp
417 push ( @array, $val ); # test -skp and also -sak='push'
418 split ( /\|/, $txt ); # test -skp and also -sak='push'
419 my ( $v1, $v2 ) = @_; # test -sak='push'
423 'space_paren.space_paren2' => {
424 source => "space_paren",
425 params => "space_paren2",
426 expect => <<'#16...........',
427 myfunc( $a, $b, $c ); # test -sfp
428 push ( @array, $val ); # test -skp and also -sak='push'
429 split( /\|/, $txt ); # test -skp and also -sak='push'
430 my ( $v1, $v2 ) = @_; # test -sak='push'
434 'braces.braces5' => {
437 expect => <<'#17...........',
440 if ( !defined( $_[0] ) )
442 print("Hello, World\n");
446 print( $_[0], "\n" );
451 print("Hello, World\n");
455 my $app = App::perlbrew->new( "install-patchperl", "-q" );
463 Mojo::IOLoop->next_tick(
467 push @kept_alive, pop->kept_alive;
468 Mojo::IOLoop->next_tick( sub { Mojo::IOLoop->stop } );
476 sswitch( $words[ rand @words ] )
481 case $words[3]: { 'ok' }
497 'braces.braces6' => {
500 expect => <<'#18...........',
502 if ( !defined( $_[0] ) ) {
503 print("Hello, World\n");
505 print( $_[0], "\n" );
510 print("Hello, World\n");
514 my $app = App::perlbrew->new( "install-patchperl", "-q" );
521 Mojo::IOLoop->next_tick(
525 push @kept_alive, pop->kept_alive;
526 Mojo::IOLoop->next_tick( sub { Mojo::IOLoop->stop } );
533 sswitch( $words[ rand @words ] ) {
537 case $words[3]: { 'ok' }
553 expect => <<'#19...........',
556 1461* ( $year +4800 -( 14 -$month )/ 12 )/ 4 +
557 367* ( $month -2 +( ( 14 -$month )/ 12 )* 12 )/ 12 -
558 3* ( ( $year +4900 -( 14 -$month )/ 12 )/ 100 )/ 4;
563 sqrt(pi)* factorial( 2* ( int( $n/ 2 ) ) +2 )/ factorial( int( $n/ 2 ) +1 )
564 / ( 4**( int( $n/ 2 ) +1 ) ) );
566 $root= -$b +sqrt( $b* $b -4.* $a* $c )/ ( 2.* $a );
571 my $ntests = 0 + keys %{$rtests};
572 plan tests => $ntests;
579 foreach my $key ( sort keys %{$rtests} ) {
581 my $sname = $rtests->{$key}->{source};
582 my $expect = $rtests->{$key}->{expect};
583 my $pname = $rtests->{$key}->{params};
584 my $source = $rsources->{$sname};
585 my $params = defined($pname) ? $rparams->{$pname} : "";
587 my $errorfile_string;
588 my $err = Perl::Tidy::perltidy(
590 destination => \$output,
591 perltidyrc => \$params,
592 argv => '', # for safety; hide any ARGV from perltidy
593 stderr => \$stderr_string,
594 errorfile => \$errorfile_string, # not used when -se flag is set
596 if ( $err || $stderr_string || $errorfile_string ) {
597 print STDERR "Error output received for test '$key'\n";
599 print STDERR "An error flag '$err' was returned\n";
602 if ($stderr_string) {
603 print STDERR "---------------------\n";
604 print STDERR "<<STDERR>>\n$stderr_string\n";
605 print STDERR "---------------------\n";
606 ok( !$stderr_string );
608 if ($errorfile_string) {
609 print STDERR "---------------------\n";
610 print STDERR "<<.ERR file>>\n$errorfile_string\n";
611 print STDERR "---------------------\n";
612 ok( !$errorfile_string );
616 if ( !is( $output, $expect, $key ) ) {
617 my $leno = length($output);
618 my $lene = length($expect);
619 if ( $leno == $lene ) {
621 "#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n";
625 "#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n";