On Thu, Jun 24, 2021 at 10:26:18PM -0400, Andrew Dunstan wrote: > Since the file isn't read in using slurp_file, that $ won't match > because the lines will end \r\n instead of \n.
I did not remember this one with Msys, thanks. I am not sure that there is any need for an eval block here actually once you remove open()? What do you think about something like the attached? -- Michael
diff --git a/src/bin/pgbench/t/001_pgbench_with_server.pl b/src/bin/pgbench/t/001_pgbench_with_server.pl index ff5b31d4df..a136e18b0e 100644 --- a/src/bin/pgbench/t/001_pgbench_with_server.pl +++ b/src/bin/pgbench/t/001_pgbench_with_server.pl @@ -1193,28 +1193,29 @@ sub check_pgbench_logs my $log_number = 0; for my $log (sort @logs) { - eval { - open my $fh, '<', $log or die "$@"; - my @contents = <$fh>; - my $clen = @contents; - ok( $min <= $clen && $clen <= $max, - "transaction count for $log ($clen)"); - my $clen_match = grep(/$re/, @contents); - ok($clen_match == $clen, "transaction format for $prefix"); - # Show more information if some logs don't match - # to help with debugging. - if ($clen_match != $clen) + # Check the contents of each log file. + my $contents_raw = slurp_file($log); + + # On Msys, filter out any CRLF. + $contents_raw =~ s/\r\n/\n/g if $Config{osname} eq 'msys'; + my @contents = split("\n", $contents_raw); + my $clen = @contents; + ok( $min <= $clen && $clen <= $max, + "transaction count for $log ($clen)"); + my $clen_match = grep(/$re/, @contents); + ok($clen_match == $clen, "transaction format for $prefix"); + + # Show more information if some logs don't match + # to help with debugging. + if ($clen_match != $clen) + { + foreach my $log (@contents) { - foreach my $log (@contents) - { - print "# Log entry not matching: $log\n" - unless $log =~ /$re/; - } + print "# Log entry not matching: $log\n" + unless $log =~ /$re/; } - close $fh or die "$@"; - }; + } } - ok(unlink(@logs), "remove log files"); return; }
signature.asc
Description: PGP signature