From ec80df7424d13999ca55fb5d67699899f87f5946 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Mon, 7 Sep 2020 16:39:22 -0700 Subject: [PATCH] improve error summary --- t/snippets/perltidy_random_parameters.pl | 97 +++++++++++++++++++++--- 1 file changed, 87 insertions(+), 10 deletions(-) diff --git a/t/snippets/perltidy_random_parameters.pl b/t/snippets/perltidy_random_parameters.pl index 0b644c3b..73609ac7 100755 --- a/t/snippets/perltidy_random_parameters.pl +++ b/t/snippets/perltidy_random_parameters.pl @@ -52,6 +52,9 @@ if ( $max_cases !~ /^\d+$/ ) { $max_cases = 100; } +# only work on regular files with non-zero length +@files=grep {-f $_ && !-z $_} @files; + if ( !@files ) { die "$usage" } my $file_count = 0; my $rsummary = []; @@ -65,6 +68,7 @@ EOM my $stop_file = 'stop.now'; if ( -e $stop_file ) { unlink $stop_file } +my @chkfile_errors; foreach my $file (@files) { next unless -e $file; $file_count++; @@ -91,7 +95,6 @@ foreach my $file (@files) { RUN: for ( 1 .. $max_cases ) { $case += 1; - print STDERR "\n-----\nCase $case, File $file_count, File name: '$ifile'\n"; # Use same random parameters for second and later files.. my $profile = "profile.$case"; @@ -115,7 +118,12 @@ foreach my $file (@files) { my $ofile = "ofile.$ext"; my $chkfile = "chkfile.$ext"; - system "perltidy < $ifile > $ofile -pro=$profile"; + + print STDERR "\n-----\nprofile='$profile', ifile='$ifile'\n"; + + my $cmd = "perltidy <$ifile >$ofile -pro=$profile"; + print STDERR "$cmd\n"; + system $cmd; my $efile = "perltidy.ERR"; my $logfile = "perltidy.LOG"; if ( -e $efile ) { rename $efile, "ERR.$ext" } @@ -167,7 +175,9 @@ foreach my $file (@files) { # run perltidy on the output to see if it can be reformatted # without errors - system "perltidy < $ofile > $chkfile"; + my $cmd2="perltidy <$ofile >$chkfile"; + system $cmd2; + print STDERR "$cmd2\n"; my $err; if ( -e $efile ) { rename $efile, "$chkfile.ERR"; @@ -176,8 +186,9 @@ foreach my $file (@files) { $has_starting_error=1; } elsif ( !$has_starting_error ) { - print STDERR "**Error reformatting** see $chkfile.ERR\n"; + print STDERR "**ERROR reformatting** see $chkfile.ERR\n"; $error_count++; + push @chkfile_errors, $chkfile; } } if ( !-e $chkfile ) { @@ -218,7 +229,7 @@ foreach my $file (@files) { # Summary for one file run with all profiles $rsummary->[$file_count] = { - input_name => $ifile_original, + input_original_name => $ifile_original, input_size => $ifile_size, error_count => $error_count, efile_count => $efile_count, @@ -275,6 +286,17 @@ EOM foreach my $nf (@problems) { report_results( $rsummary->[$nf] ); } + if (@chkfile_errors) { + local $"=')('; + my $num=@chkfile_errors; + $num=10 if ($num>10); + print STDERR <{input_name}; + my $ifile_original = $rh->{input_original_name}; my $ifile_size = $rh->{input_size}; my $error_count = $rh->{error_count}; my $efile_count = $rh->{efile_count}; @@ -316,8 +345,9 @@ sub report_results { my $efile_case_max = $rh->{maximum_error_case}; print STDERR <', $runme ) ) { + print RUN <<'EOM'; +#!/usr/bin/perl -w +my $nohup = "nohup.out"; +my $ofile = "nohup.out.err"; +open( IN, '<', $nohup ) || die "cannot open $nohup: $!\n"; +open( OUT, '>', $ofile ) || die "cannot open $ofile: $!\n"; +my $lno = 0; +my $count = 0; +my @lines=; +my $nlines=@lines; +foreach my $line (@lines) { + $lno++; + if ( $line =~ /uninitialized/ || length($line) > 80 ) { + + # ignore last few lines + next if ( $lno > $nlines - 4 ); + $count++; + print OUT "$lno: $line"; + print STDERR "$lno: $line"; + } +} +close IN; +close OUT; +my $gfile="nohup.out.grep"; +my $cmd1 = "grep 'Thank you' ERR.* >>$gfile"; +my $cmd2 = "grep 'Thank you' *.ERR >>$gfile"; +system ($cmd1); +system ($cmd2); +print STDERR "$count problems seen in $nohup\n"; +if ($count) { + print STDERR "please see $ofile\n"; +} +if (-s $gfile) { + print STDERR "please see $gfile\n"; +} +EOM + close RUN; + system("chmod +x $runme"); + print "Wrote '$runme'\n"; + return; + } +} -- 2.39.5