Because I run a lot of test code from Perlmonks that I don't understand, and so I decided to start keeping track of it. I made a directory to hold all my tests and this dirty little script. When I run it, it creates a new file with a filename that is a number one greater than the previous one. It then links that file to current test. Requires Inline::Files. Comments welcome (I need help on learning how to *think* Perl).

P.S. I'm aware of the huge race condition potential. I don't really care, because this is "just for me code" (famous last words).
#!/usr/bin/perl use Inline::Files; use warnings; use strict; open NUMBER, '+<'; my $number = <NUMBER>; seek NUMBER, 0, 0; print NUMBER ++$number; my @args = ("vim $number && rm current_test && ln -s $number current_t +est"); system @args and exit; __NUMBER__ 0


Who is Kayser Söze?

Replies are listed 'Best First'.
Re: Perl test management
by Roger (Parson) on Nov 11, 2003 at 04:16 UTC
    Good idea. Well done. But you don't really need the extra last-number file. You can determine it on-the-fly. Hope the following code helps: The script will first look for sample_<number>.pl files, extract the biggest number, and start the next file with filename of sample_<last number + 1>.pl.

    #!/usr/bin/perl -w use strict; use IO::Dir; my $rootdir = "."; my $lastno = GetLastNumber($rootdir) + 1; my $newpl = "$rootdir/sample_${lastno}.pl"; # forgot to add .pl extens +ion # thanks jweed. system "vim $newpl && rm current_test && ln -s $newpl current_test"; sub GetLastNumber { my $dir = shift; my $d = IO::Dir->new($dir) or die "Can not open directory $dir for read!"; my $lastno = 0; while (defined(my $f = $d->read)) { next if $f !~ /sample\_\d+\.pl/; my ($no) = $f =~ /sample_(\d+)\.pl/; $lastno = $no if $no > $lastno; } return $lastno; }
      Excellent. ++. I had this idea but was unsure as to implementation.

      P.S. There is a slight code bug. You test in GetLastNumber for a file of the format "sample_<number>.pl", but you create a file of the for "sample_<number>".

      Brain fart issue, I suppose. :)


      Who is Kayser Söze?
Re: Perl test management
by dominix (Deacon) on Dec 15, 2003 at 02:22 UTC
    very cool, solution adopted !
    my "samples" will become toto_x.pl instead of sample_... it's just a matter of culture :))
    --
    DominiX