From 2efe838bbbf13bee4357a1995874aec3d2483d56 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 7 Sep 2020 19:57:29 -0700 Subject: [PATCH] added test for long line with here target --- t/snippets/expect/here_long.def | 6 ++ t/snippets/expect/here_long.here_long | 6 ++ t/snippets/here_long.in | 6 ++ t/snippets/here_long.par | 1 + t/snippets/packing_list.txt | 6 +- t/snippets21.t | 23 ++++++ t/snippets22.t | 115 ++++++++++++++++++++++++++ 7 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 t/snippets/expect/here_long.def create mode 100644 t/snippets/expect/here_long.here_long create mode 100644 t/snippets/here_long.in create mode 100644 t/snippets/here_long.par create mode 100644 t/snippets22.t diff --git a/t/snippets/expect/here_long.def b/t/snippets/expect/here_long.def new file mode 100644 index 00000000..4a75504e --- /dev/null +++ b/t/snippets/expect/here_long.def @@ -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 index 00000000..4a75504e --- /dev/null +++ b/t/snippets/expect/here_long.here_long @@ -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 index 00000000..c4548912 --- /dev/null +++ b/t/snippets/here_long.in @@ -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 index 00000000..47561282 --- /dev/null +++ b/t/snippets/here_long.par @@ -0,0 +1 @@ +-l=33 diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 13f47188..f4cd202e 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -267,6 +267,8 @@ ../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 @@ -407,5 +409,5 @@ ../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 diff --git a/t/snippets21.t b/t/snippets21.t index 03d540f0..6f684e72 100644 --- a/t/snippets21.t +++ b/t/snippets21.t @@ -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 index 00000000..6a04e27d --- /dev/null +++ b/t/snippets22.t @@ -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 "<>\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"; + } + } + } +} -- 2.39.5