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