I usually number my tests. I frequently find myself "wedging" tests between other tests as I run out of test numbers. This small program lets me renumber my tests on the fly. It pretends to be portable, but don't shoot me if it's not. I supports simply "mv"ing the tests or, if you prefer, "svn mv".

#!/usr/bin/perl use strict; use warnings; use File::Spec; use Getopt::Long; my $dir = "."; my $test_num = 10; my $step = 10; GetOptions( "dir=s" => \$dir, "start=i" => \$test_num, "step=i" => \$step, "dry" => \my $dry_run, "svn" => \my $svn, ); unless ( -d $dir ) { die "I cannot find the directory ($dir)"; } my $tests = File::Spec->catfile( $dir, "*.t" ); if ( $tests =~ /^(.+)\*.t$/ ) { $dir = $1; # now we have the directory with the separator } my @tests = glob $tests; unless (@tests) { die "No tests found in ($tests)"; } { no warnings 'numeric'; @tests = map { s/^\d+//; $_ } sort { $a <=> $b } map { s{^$dir(\d+)/}{$1$dir$1}; $_ } grep { /^\Q$dir\E\d+/ } @tests; # only take numbered tests } unless ($dry_run) { print <<" END_WARNING"; Warning: this is not a dry run and you're really going to renumber the tests. Are you sure you want to continue? (y/n) END_WARNING my $response = <STDIN>; unless ($response =~ /^[Yy]/) { print "Answer was not 'y' or 'Y'. Aborting"; exit(0); } } my $digits = length( $test_num + ( $step * @tests ) ); $test_num = $test_num - $step; # because of how we handle th +e s/// foreach my $test (@tests) { my $new_name = $test; $new_name =~ s{(?<=\Q$dir\E)\d+} { $test_num += $step; sprintf "%0${digits}d", $test_num; }e; next if $new_name eq $test; my @command = ( "mv", $test, $new_name ); if ($svn) { unshift @command, "svn"; } if ($dry_run) { print "@command\n"; } else { system(@command); } }

In reply to Renumbering tests by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.