]> git.donarmstrong.com Git - perltidy.git/commitdiff
added test cases regarding spaces between tokens
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 29 Apr 2020 14:36:21 +0000 (07:36 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 29 Apr 2020 14:36:21 +0000 (07:36 -0700)
t/snippets/expect/space6.def [new file with mode: 0644]
t/snippets/expect/space6.space6 [new file with mode: 0644]
t/snippets/make_expect.pl
t/snippets/packing_list.txt
t/snippets/spp.in
t/snippets20.t [new file with mode: 0644]

diff --git a/t/snippets/expect/space6.def b/t/snippets/expect/space6.def
new file mode 100644 (file)
index 0000000..cdc00de
--- /dev/null
@@ -0,0 +1,5 @@
+# test some spacing rules at possible filehandles
+my $z = $x / $y;    # ok to change spaces around both sides of the /
+print $x / $y;      # do not remove space before or after / here
+print $x/ $y;       # do not add a space before the / here
+print $x+ $y;       # do not add a space before the + here
diff --git a/t/snippets/expect/space6.space6 b/t/snippets/expect/space6.space6
new file mode 100644 (file)
index 0000000..99b84f1
--- /dev/null
@@ -0,0 +1,5 @@
+# test some spacing rules at possible filehandles
+my $z = $x/$y;    # ok to change spaces around both sides of the /
+print $x / $y;    # do not remove space before or after / here
+print $x/$y;      # do not add a space before the / here
+print $x+$y;      # do not add a space before the + here
index 0db334a1605da104982fac9987e58c11dc1e4e23..cdbc678baf5eaad507b00753c71a82ba1bb7ad5d 100755 (executable)
@@ -222,12 +222,14 @@ if (@changed) {
     print "------\n";
 }
 
+my $runme = "RUNME.sh";
+
 if ( !@mv ) {
     print "No differences\n";
+    if (-e $runme) {unlink $runme}
     exit;
 }
 
-my $runme = "RUNME.sh";
 if ( open( RUN, ">$runme" ) ) {
     print RUN <<EOM;
 #!/bin/sh
index 051470326cfe888a26d41ce6ee20007fab656e32..913908c583aab579c5158dc8a081003e7db9de2a 100644 (file)
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
+../snippets20.t        space6.def
+../snippets20.t        space6.space6
index f54bbe8abd0ce1d7b8757fcbc6fc98997701328a..fdbe014f0793a5653d355e09493f3b2835c9b6a1 100644 (file)
@@ -3,3 +3,5 @@ sub get_val() { }
 sub get_Val  () { }
 
 sub Get_val            () { }
+my $sub1=sub                     () { };
+my $sub2=sub () { };
diff --git a/t/snippets20.t b/t/snippets20.t
new file mode 100644 (file)
index 0000000..aad2cf4
--- /dev/null
@@ -0,0 +1,125 @@
+# Created with: ./make_t.pl
+
+# Contents:
+#1 space6.def
+#2 space6.space6
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+    ###########################################
+    # BEGIN SECTION 1: Parameter combinations #
+    ###########################################
+    $rparams = {
+        'def'    => "",
+        'space6' => <<'----------',
+-nwrs="+ - / *"
+-nwls="+ - / *"
+----------
+    };
+
+    ############################
+    # BEGIN SECTION 2: Sources #
+    ############################
+    $rsources = {
+
+        'space6' => <<'----------',
+# test some spacing rules at possible filehandles
+my $z=$x/$y;     # ok to change spaces around both sides of the /
+print $x / $y;   # do not remove space before or after / here
+print $x/$y;     # do not add a space before the / here
+print $x+$y;     # do not add a space before the + here
+----------
+    };
+
+    ####################################
+    # BEGIN SECTION 3: Expected output #
+    ####################################
+    $rtests = {
+
+        'space6.def' => {
+            source => "space6",
+            params => "def",
+            expect => <<'#1...........',
+# test some spacing rules at possible filehandles
+my $z = $x / $y;    # ok to change spaces around both sides of the /
+print $x / $y;      # do not remove space before or after / here
+print $x/ $y;       # do not add a space before the / here
+print $x+ $y;       # do not add a space before the + here
+#1...........
+        },
+
+        'space6.space6' => {
+            source => "space6",
+            params => "space6",
+            expect => <<'#2...........',
+# test some spacing rules at possible filehandles
+my $z = $x/$y;    # ok to change spaces around both sides of the /
+print $x / $y;    # do not remove space before or after / here
+print $x/$y;      # do not add a space before the / here
+print $x+$y;      # do not add a space before the + here
+#2...........
+        },
+    };
+
+    my $ntests = 0 + keys %{$rtests};
+    plan tests => $ntests;
+}
+
+###############
+# EXECUTE TESTS
+###############
+
+foreach my $key ( sort keys %{$rtests} ) {
+    my $output;
+    my $sname  = $rtests->{$key}->{source};
+    my $expect = $rtests->{$key}->{expect};
+    my $pname  = $rtests->{$key}->{params};
+    my $source = $rsources->{$sname};
+    my $params = defined($pname) ? $rparams->{$pname} : "";
+    my $stderr_string;
+    my $errorfile_string;
+    my $err = Perl::Tidy::perltidy(
+        source      => \$source,
+        destination => \$output,
+        perltidyrc  => \$params,
+        argv        => '',             # for safety; hide any ARGV from perltidy
+        stderr      => \$stderr_string,
+        errorfile => \$errorfile_string,    # not used when -se flag is set
+    );
+    if ( $err || $stderr_string || $errorfile_string ) {
+        if ($err) {
+            print STDERR
+"This error received calling Perl::Tidy with '$sname' + '$pname'\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 );
+    }
+}