Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Sunday November 20, 2005
04:42 PM

Renumbering tests

[ #27667 ]

Back in the early 90s when I was doing BASIC programming, I was soooo happy when I finally used a system which allowed me to automatically renumber my program lines. It made programming much easier. Today, I routinely find myself wedging tests between other tests since I number my tests.

70_Tr ait_SUPER2_test.t
91_trait_ performs.t

Today I got fed up with that and wrote a simple test renumbering program. You may not find it useful but it does exactly what I need. Admittedly, tests should run in any order but I have a convention that lower numbered test failures should be addressed first as they're likely the ones causing other test errors.

The following is a bit of a hack and it's certainly not portable, but then, I didn't really right it for anyone else :)


use strict;
use warnings;

use Getopt::Long;
my $dir      = ".";
my $test_num = 10;
my $step     = 10;

    "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 = glob "$dir/*.t";
unless (@tests) {
    die "No tests found in ($dir)";

@tests =
  sort grep { /^\d+/ }
  map { s{^\Q$dir/}{}; $_ } @tests;    # only take numbered tests

my $digits = length( $test_num + ( $step * @tests ) );

foreach my $test (@tests) {
    my $new_name = $test;
    $new_name =~ s{^\d+(.*)$}
                     my $name = sprintf "%0${digits}d$1", $test_num;
                     $test_num += $step;

    next if $new_name eq $test;
    my @command = ( "mv", "$dir/$test", "$dir/$new_name" );
    if ($svn) {
        unshift @command, "svn";
    if ($dry_run) {
        print "@command\n";
    else {

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I wrote Test::Manifest because I think ordering tests by their filename is silly. Not only that, by specifying which tests to run and which order to run them in using a separate file makes it easy to turn off tests while I'm developing. :)
  • In theory, you should never have two tests that have the same name, differing only in the sequence number portion of the name. If, in practice, you ever did however, the rename could cause problems if the first one processed is being renamed to have the old sequence number of the second one.