]> git.donarmstrong.com Git - perltidy.git/commitdiff
be sure DEVEL_MODE is set for random testing
authorSteve Hancock <perltidy@users.sourceforge.net>
Tue, 5 Oct 2021 13:19:36 +0000 (06:19 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Tue, 5 Oct 2021 13:19:36 +0000 (06:19 -0700)
dev-bin/perltidy_random_setup.pl

index d3696fc81beccfc329c8c895bbe8b63b5008324e..9b4da0a5c522c7a586d21a634d1498b9901c02e1 100755 (executable)
@@ -40,7 +40,10 @@ else {
     }
 }
 
-# TODO: see if DEVEL_MODE is set, turn it on if not
+# see if DEVEL_MODE is set, turn it on if not
+if ($perltidy eq "./perltidy.pl") {
+   check_DEVEL_MODE($perltidy);
+}
 
 query(<<EOM);
 
@@ -1314,3 +1317,38 @@ EOM
         return \@random_parameters;
     }
 }
+
+sub check_DEVEL_MODE {
+    my ($fname) = @_;
+    my $fh;
+    my $changed_count;
+    my @output;
+    open( $fh, '<', $fname )
+      or die "can't open '$fname' : $!\n";
+    while (<$fh>) {
+        my $line = $_;
+        if ( $line =~
+            /^(\s*use\s+constant\s+(?:DEVEL)_[A-Z]+\s*)=>\s*(-?\d*);(.*)$/ )
+        {
+            if ( $2 != '1' ) {
+                $changed_count++;
+                $line = <<EOM;
+$1=> 1;$3
+EOM
+            }
+        }
+        push @output, $line;
+    }
+    $fh->close();
+
+    if ( $changed_count && @output ) {
+        my $fh_out;
+        open( $fh_out, '>', $fname )
+          or die "can't open '$fname' : $!\n";
+        foreach (@output) {
+            $fh_out->print($_);
+        }
+        $fh_out->close();
+        print STDERR "Changed to DEVEL_MODE => 1\n";
+    }
+}