]> git.donarmstrong.com Git - perltidy.git/commitdiff
add -s option to convergence test utility
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 4 Jul 2023 00:46:23 +0000 (17:46 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 4 Jul 2023 00:46:23 +0000 (17:46 -0700)
dev-bin/run_convergence_tests.pl

index 88224335c686aac910c28d4c15f16376093a3de2..ed1d5f09002e954a3ae27d586c43030c718dd522 100755 (executable)
@@ -16,7 +16,7 @@ There are four options: run [DEFAULT], pack, merge, unpack ( -r -p -m -u )
 
 usage:
 
-   $0 -h -u -m -p -r [ arg1 arg2 ...
+   $0 -h -u -m -p -r -s [ arg1 arg2 ...
 
 where one parameter may be given to specify the operation to be done:
 
@@ -26,6 +26,7 @@ where one parameter may be given to specify the operation to be done:
   -m merge files given in arg list into the default or specified database
   -p packs files given in arg list into a new database
   -e overwrites old expect data with the new results for cases run
+  -s write statistics on parameter frequency to stdout and exit
   -r runs the tests [DEFAULT operation]
 
   arg1 arg2 ... may contain: 
@@ -88,6 +89,7 @@ my @option_string = qw(
   m
   p
   r
+  s
   u
 );
 
@@ -114,10 +116,12 @@ if ( -e $tmp_dir && !-d $tmp_dir ) {
     exit 1;
 }
 
-print <<EOM;
+if ( !$Opts{s} ) {
+    print <<EOM;
 default temporary output directory: 
 $tmp_dir
 EOM
+}
 
 # Sift through the args...
 my @files;
@@ -220,6 +224,15 @@ else {
     exit 1;
 }
 
+###################
+# s: run statistics
+###################
+
+if ( $Opts{s} ) {
+    dump_parameter_frequency($rdata_files); 
+    exit 1;
+}
+
 my $rexpect_files;
 if ( -e $expect_fname ) {
     $rexpect_files = read_data_to_hash($expect_fname);
@@ -612,6 +625,41 @@ EOM
     return;
 }
 
+sub dump_parameter_frequency {
+    my ($rdata_files) = @_;
+
+    # Dump a list of parameters and the number of times they appear
+    my $rcount = {};
+
+    foreach my $fname ( keys %{$rdata_files} ) {
+        if ( $fname =~ /^(.*)\.par$/ ) {
+            my $string = $rdata_files->{$fname};
+            my @lines  = split /^/, $string;
+            foreach my $line (@lines) {
+                $line =~ s/^\s+//;
+                $line =~ s/\s+$//;
+                if ( $line && $line =~ /^-/ ) {
+                    if ( $line =~ /^-+(\w[\w-]*)/ ) {
+                        $rcount->{$1}++;
+                    }
+                }
+            }
+        }
+    }
+
+    # For a spreadsheet:
+##  my @sorted_keys = sort { $rcount->{$b} <=> $rcount->{$a} } keys %{$rcount};
+##  foreach my $key (@sorted_keys) {
+##      print "$rcount->{$key}, $key\n";
+##  }
+
+    # For a script:
+    use Data::Dumper;
+    print Dumper($rcount);
+
+    return;
+}
+
 sub pack_data {
     my ( $db_fname, $rfiles ) = @_;
     my $rdata = read_files_to_hash($rfiles);