]> git.donarmstrong.com Git - perltidy.git/commitdiff
added test for long line with here target
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 8 Sep 2020 02:57:29 +0000 (19:57 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 8 Sep 2020 02:57:29 +0000 (19:57 -0700)
t/snippets/expect/here_long.def [new file with mode: 0644]
t/snippets/expect/here_long.here_long [new file with mode: 0644]
t/snippets/here_long.in [new file with mode: 0644]
t/snippets/here_long.par [new file with mode: 0644]
t/snippets/packing_list.txt
t/snippets21.t
t/snippets22.t [new file with mode: 0644]

diff --git a/t/snippets/expect/here_long.def b/t/snippets/expect/here_long.def
new file mode 100644 (file)
index 0000000..4a75504
--- /dev/null
@@ -0,0 +1,6 @@
+# must not break first line regardless of value of maximum-line-length
+$sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL";
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
diff --git a/t/snippets/expect/here_long.here_long b/t/snippets/expect/here_long.here_long
new file mode 100644 (file)
index 0000000..4a75504
--- /dev/null
@@ -0,0 +1,6 @@
+# must not break first line regardless of value of maximum-line-length
+$sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL";
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
diff --git a/t/snippets/here_long.in b/t/snippets/here_long.in
new file mode 100644 (file)
index 0000000..c454891
--- /dev/null
@@ -0,0 +1,6 @@
+# must not break first line regardless of value of maximum-line-length
+$sth= $dbh->prepare (<<"END_OF_SELECT") or die "Couldn't prepare SQL" ;
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
diff --git a/t/snippets/here_long.par b/t/snippets/here_long.par
new file mode 100644 (file)
index 0000000..4756128
--- /dev/null
@@ -0,0 +1 @@
+-l=33
index 13f4718840df36323cbe4a07c786146492da1bd0..f4cd202e044a9b66b99aff996bb640ac05bf0cfc 100644 (file)
 ../snippets21.t        nib.def
 ../snippets21.t        nib.nib1
 ../snippets21.t        nib.nib2
+../snippets21.t        scbb-csc.def
+../snippets21.t        scbb-csc.scbb-csc
 ../snippets3.t ce_wn1.ce_wn
 ../snippets3.t ce_wn1.def
 ../snippets3.t colin.colin
 ../snippets9.t rt98902.def
 ../snippets9.t rt98902.rt98902
 ../snippets9.t rt99961.def
-../snippets21.t        scbb-csc.def
-../snippets21.t        scbb-csc.scbb-csc
+../snippets21.t        here_long.def
+../snippets22.t        here_long.here_long
index 03d540f030835348d48ce624f87dbc6cf8a154d5..6f684e722a2e99310878915ff418d5238be95f1b 100644 (file)
@@ -19,6 +19,7 @@
 #16 nib.nib2
 #17 scbb-csc.def
 #18 scbb-csc.scbb-csc
+#19 here_long.def
 
 # To locate test #13 you can search for its name or the string '#13'
 
@@ -95,6 +96,15 @@ else {                    # We're the third word to have this
     # abbreviation, so skip to the next word.
     next WORD;
 }
+----------
+
+        'here_long' => <<'----------',
+# must not break first line regardless of value of maximum-line-length
+$sth= $dbh->prepare (<<"END_OF_SELECT") or die "Couldn't prepare SQL" ;
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
 ----------
 
         'lop' => <<'----------',
@@ -771,6 +781,19 @@ sub perlmod_install_advice {
 
 #18...........
         },
+
+        'here_long.def' => {
+            source => "here_long",
+            params => "def",
+            expect => <<'#19...........',
+# must not break first line regardless of value of maximum-line-length
+$sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL";
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
+#19...........
+        },
     };
 
     my $ntests = 0 + keys %{$rtests};
diff --git a/t/snippets22.t b/t/snippets22.t
new file mode 100644 (file)
index 0000000..6a04e27
--- /dev/null
@@ -0,0 +1,115 @@
+# Created with: ./make_t.pl
+
+# Contents:
+#1 here_long.here_long
+
+# To locate test #13 you can search for its name or the string '#13'
+
+use strict;
+use Test::More;
+use Carp;
+use Perl::Tidy;
+my $rparams;
+my $rsources;
+my $rtests;
+
+BEGIN {
+
+    ###########################################
+    # BEGIN SECTION 1: Parameter combinations #
+    ###########################################
+    $rparams = { 'here_long' => "-l=33", };
+
+    ############################
+    # BEGIN SECTION 2: Sources #
+    ############################
+    $rsources = {
+
+        'here_long' => <<'----------',
+# must not break first line regardless of value of maximum-line-length
+$sth= $dbh->prepare (<<"END_OF_SELECT") or die "Couldn't prepare SQL" ;
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
+----------
+    };
+
+    ####################################
+    # BEGIN SECTION 3: Expected output #
+    ####################################
+    $rtests = {
+
+        'here_long.here_long' => {
+            source => "here_long",
+            params => "here_long",
+            expect => <<'#1...........',
+# must not break first line regardless of value of maximum-line-length
+$sth = $dbh->prepare(<<"END_OF_SELECT") or die "Couldn't prepare SQL";
+    SELECT COUNT(duration),SUM(duration) 
+    FROM logins WHERE username='$user'
+END_OF_SELECT
+
+#1...........
+        },
+    };
+
+    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 ) {
+        print STDERR "Error output received for test '$key'\n";
+        if ($err) {
+            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";
+            ok( !$stderr_string );
+        }
+        if ($errorfile_string) {
+            print STDERR "---------------------\n";
+            print STDERR "<<.ERR file>>\n$errorfile_string\n";
+            print STDERR "---------------------\n";
+            ok( !$errorfile_string );
+        }
+    }
+    else {
+        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";
+            }
+        }
+    }
+}