run_tests.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #! /usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use File::Spec::Functions qw/catdir catfile curdir abs2rel rel2abs/;
  5. use File::Basename;
  6. use Test::Harness qw/runtests $switches/;
  7. my $srctop = $ENV{SRCTOP} || $ENV{TOP};
  8. my $bldtop = $ENV{BLDTOP} || $ENV{TOP};
  9. my $recipesdir = catdir($srctop, "test", "recipes");
  10. my $testlib = catdir($srctop, "test", "testlib");
  11. my $utillib = catdir($srctop, "util");
  12. # It seems that $switches is getting interpreted with 'eval' or something
  13. # like that, and that we need to take care of backslashes or they will
  14. # disappear along the way.
  15. $testlib =~ s|\\|\\\\|g if $^O eq "MSWin32";
  16. $utillib =~ s|\\|\\\\|g if $^O eq "MSWin32";
  17. # Test::Harness provides the variable $switches to give it
  18. # switches to be used when it calls our recipes.
  19. $switches = "-w \"-I$testlib\" \"-I$utillib\"";
  20. my @tests = ( "alltests" );
  21. if (@ARGV) {
  22. @tests = @ARGV;
  23. }
  24. my $list_mode = scalar(grep /^list$/, @tests) != 0;
  25. if (grep /^alltests|list$/, @tests) {
  26. @tests = grep {
  27. basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
  28. } glob(catfile($recipesdir,"*.t"));
  29. } else {
  30. my @t = ();
  31. foreach (@tests) {
  32. push @t, grep {
  33. basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
  34. } glob(catfile($recipesdir,"*-$_.t"));
  35. }
  36. @tests = @t;
  37. }
  38. if ($list_mode) {
  39. @tests = map { $_ = basename($_); $_ =~ s/^[0-9][0-9]-//; $_ =~ s/\.t$//;
  40. $_ } @tests;
  41. print join("\n", @tests), "\n";
  42. } else {
  43. @tests = map { abs2rel($_, rel2abs(curdir())); } @tests;
  44. runtests(sort @tests);
  45. }