]> git.donarmstrong.com Git - perltidy.git/blobdiff - t/snippets10.t
New upstream version 20210717
[perltidy.git] / t / snippets10.t
index 2bda303f530882788e0794616bc63c19cab87e6a..302e61485b90d23d07a54c1d68a9fe407b5bb724 100644 (file)
@@ -25,7 +25,7 @@
 # To locate test #13 you can search for its name or the string '#13'
 
 use strict;
-use Test;
+use Test::More;
 use Carp;
 use Perl::Tidy;
 my $rparams;
@@ -302,6 +302,9 @@ qr/3/ ~~ 12345;
 
     # remove unwanted spaces after $ and -> here
     &{ $ _ -> [1] }( delete $ _ [$#_   ]{ $_   ->     [0] } );
+
+    # this has both tabs and spaces to remove
+    $   setup = $       labels ->       labelsetup( Output_Width       => 2.625) ;
 ----------
 
         'space2' => <<'----------',
@@ -494,34 +497,34 @@ foreach ( split( //, $input ) ) { }
             params => "def",
             expect => <<'#8...........',
 \&foo !~~ \&foo;
-\&foo ~~ \&foo;
-\&foo ~~ \&foo;
-\&foo ~~ sub { };
-sub { } ~~ \&foo;
-\&foo ~~ \&bar;
-\&bar ~~ \&foo;
-1 ~~ sub { shift };
-sub { shift } ~~ 1;
-0 ~~ sub { shift };
-sub { shift } ~~ 0;
-1 ~~ sub { scalar @_ };
+\&foo             ~~ \&foo;
+\&foo             ~~ \&foo;
+\&foo             ~~ sub { };
+sub { }           ~~ \&foo;
+\&foo             ~~ \&bar;
+\&bar             ~~ \&foo;
+1                 ~~ sub { shift };
+sub { shift }     ~~ 1;
+0                 ~~ sub { shift };
+sub { shift }     ~~ 0;
+1                 ~~ sub { scalar @_ };
 sub { scalar @_ } ~~ 1;
-[]           ~~ \&bar;
-\&bar        ~~ [];
-{}           ~~ \&bar;
-\&bar        ~~ {};
-qr//         ~~ \&bar;
-\&bar        ~~ qr//;
-a_const      ~~ "a constant";
-"a constant" ~~ a_const;
-a_const      ~~ a_const;
-a_const      ~~ a_const;
-a_const      ~~ b_const;
-b_const      ~~ a_const;
-{}           ~~ {};
-{}           ~~ {};
-{}           ~~ { 1 => 2 };
-{ 1 => 2 } ~~ {};
+[]                ~~ \&bar;
+\&bar             ~~ [];
+{}                ~~ \&bar;
+\&bar             ~~ {};
+qr//              ~~ \&bar;
+\&bar             ~~ qr//;
+a_const           ~~ "a constant";
+"a constant"      ~~ a_const;
+a_const           ~~ a_const;
+a_const           ~~ a_const;
+a_const           ~~ b_const;
+b_const           ~~ a_const;
+{}                ~~ {};
+{}                ~~ {};
+{}                ~~ { 1 => 2 };
+{ 1 => 2 }        ~~ {};
 { 1 => 2 } ~~ { 1 => 2 };
 { 1 => 2 } ~~ { 1 => 2 };
 { 1 => 2 } ~~ { 1 => 3 };
@@ -555,56 +558,56 @@ qr/[13579]$/            ~~ +{ 0 .. 100 };
 []                      ~~ [];
 []                      ~~ [1];
 [1]                     ~~ [];
-[ ["foo"], ["bar"] ] ~~ [ qr/o/, qr/a/ ];
-[ qr/o/, qr/a/ ] ~~ [ ["foo"], ["bar"] ];
-[ "foo", "bar" ] ~~ [ qr/o/, qr/a/ ];
-[ qr/o/, qr/a/ ] ~~ [ "foo", "bar" ];
-$deep1                 ~~ $deep1;
-$deep1                 ~~ $deep1;
-$deep1                 ~~ $deep2;
-$deep2                 ~~ $deep1;
-\@nums                 ~~ \@tied_nums;
-\@tied_nums            ~~ \@nums;
-[qw(foo bar baz quux)] ~~ qr/x/;
-qr/x/                  ~~ [qw(foo bar baz quux)];
-[qw(foo bar baz quux)] ~~ qr/y/;
-qr/y/                  ~~ [qw(foo bar baz quux)];
-[qw(1foo 2bar)]        ~~ 2;
-2                      ~~ [qw(1foo 2bar)];
-[qw(1foo 2bar)]        ~~ "2";
-"2"                    ~~ [qw(1foo 2bar)];
-2                      ~~ 2;
-2                      ~~ 2;
-2                      ~~ 3;
-3                      ~~ 2;
-2                      ~~ "2";
-"2"                    ~~ 2;
-2                      ~~ "2.0";
-"2.0"                  ~~ 2;
-2                      ~~ "2bananas";
-"2bananas"             ~~ 2;
-2_3                    ~~ "2_3";
-"2_3"                  ~~ 2_3;
-qr/x/                  ~~ "x";
-"x"                    ~~ qr/x/;
-qr/y/                  ~~ "x";
-"x"                    ~~ qr/y/;
-12345                  ~~ qr/3/;
-qr/3/                  ~~ 12345;
-@nums                  ~~ 7;
-7                      ~~ @nums;
-@nums                  ~~ \@nums;
-\@nums                 ~~ @nums;
-@nums                  ~~ \\@nums;
-\\@nums                ~~ @nums;
-@nums                  ~~ [ 1 .. 10 ];
-[ 1 .. 10 ]            ~~ @nums;
-@nums                  ~~ [ 0 .. 9 ];
-[ 0 .. 9 ]             ~~ @nums;
-%hash                  ~~ "foo";
-"foo"                  ~~ %hash;
-%hash                  ~~ /bar/;
-/bar/                  ~~ %hash;
+[ ["foo"], ["bar"] ]    ~~ [ qr/o/, qr/a/ ];
+[ qr/o/, qr/a/ ]        ~~ [ ["foo"], ["bar"] ];
+[ "foo", "bar" ]        ~~ [ qr/o/, qr/a/ ];
+[ qr/o/, qr/a/ ]        ~~ [ "foo", "bar" ];
+$deep1                  ~~ $deep1;
+$deep1                  ~~ $deep1;
+$deep1                  ~~ $deep2;
+$deep2                  ~~ $deep1;
+\@nums                  ~~ \@tied_nums;
+\@tied_nums             ~~ \@nums;
+[qw(foo bar baz quux)]  ~~ qr/x/;
+qr/x/                   ~~ [qw(foo bar baz quux)];
+[qw(foo bar baz quux)]  ~~ qr/y/;
+qr/y/                   ~~ [qw(foo bar baz quux)];
+[qw(1foo 2bar)]         ~~ 2;
+2                       ~~ [qw(1foo 2bar)];
+[qw(1foo 2bar)]         ~~ "2";
+"2"                     ~~ [qw(1foo 2bar)];
+2                       ~~ 2;
+2                       ~~ 2;
+2                       ~~ 3;
+3                       ~~ 2;
+2                       ~~ "2";
+"2"                     ~~ 2;
+2                       ~~ "2.0";
+"2.0"                   ~~ 2;
+2                       ~~ "2bananas";
+"2bananas"              ~~ 2;
+2_3                     ~~ "2_3";
+"2_3"                   ~~ 2_3;
+qr/x/                   ~~ "x";
+"x"                     ~~ qr/x/;
+qr/y/                   ~~ "x";
+"x"                     ~~ qr/y/;
+12345                   ~~ qr/3/;
+qr/3/                   ~~ 12345;
+@nums                   ~~ 7;
+7                       ~~ @nums;
+@nums                   ~~ \@nums;
+\@nums                  ~~ @nums;
+@nums                   ~~ \\@nums;
+\\@nums                 ~~ @nums;
+@nums                   ~~ [ 1 .. 10 ];
+[ 1 .. 10 ]             ~~ @nums;
+@nums                   ~~ [ 0 .. 9 ];
+[ 0 .. 9 ]              ~~ @nums;
+%hash                   ~~ "foo";
+"foo"                   ~~ %hash;
+%hash                   ~~ /bar/;
+/bar/                   ~~ %hash;
 #8...........
         },
 
@@ -620,6 +623,9 @@ qr/3/                  ~~ 12345;
 
     # remove unwanted spaces after $ and -> here
     &{ $_->[1] }( delete $_[$#_]{ $_->[0] } );
+
+    # this has both tabs and spaces to remove
+    $setup = $labels->labelsetup( Output_Width => 2.625 );
 #9...........
         },
 
@@ -754,7 +760,7 @@ sub arrange_topframe {
 # This test snippet is from package bbbike v3.214 by Slaven Rezic; GPL 2.0 licence
 sub arrange_topframe {
   my (@order) = (
-    $hslabel_frame, $km_frame, $speed_frame[0],
+    $hslabel_frame,  $km_frame,   $speed_frame[0],
     $power_frame[0], $wind_frame, $percent_frame, $temp_frame,
     @speed_frame[1 .. $#speed_frame],
     @power_frame[1 .. $#power_frame],
@@ -1008,32 +1014,39 @@ foreach my $key ( sort keys %{$rtests} ) {
         perltidyrc  => \$params,
         argv        => '',             # for safety; hide any ARGV from perltidy
         stderr      => \$stderr_string,
-        errorfile => \$errorfile_string,    # not used when -se flag is set
+        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
-"This error received calling Perl::Tidy with '$sname' + '$pname'\n";
+            print STDERR "An error flag '$err' was returned\n";
             ok( !$err );
         }
         if ($stderr_string) {
             print STDERR "---------------------\n";
             print STDERR "<<STDERR>>\n$stderr_string\n";
             print STDERR "---------------------\n";
-            print STDERR
-"This error received calling Perl::Tidy with '$sname' + '$pname'\n";
             ok( !$stderr_string );
         }
         if ($errorfile_string) {
             print STDERR "---------------------\n";
             print STDERR "<<.ERR file>>\n$errorfile_string\n";
             print STDERR "---------------------\n";
-            print STDERR
-"This error received calling Perl::Tidy with '$sname' + '$pname'\n";
             ok( !$errorfile_string );
         }
     }
     else {
-        ok( $output, $expect );
+        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";
+            }
+        }
     }
 }