Configure,test/recipes: "pin" glob to File::Glob::glob.
[openssl.git] / test / run_tests.pl
1 #! /usr/bin/env perl
2 # Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the OpenSSL license (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 use strict;
10 use warnings;
11
12 # Recognise VERBOSE and V which is common on other projects.
13 BEGIN {
14     $ENV{HARNESS_VERBOSE} = "yes" if $ENV{VERBOSE} || $ENV{V};
15 }
16
17 use File::Spec::Functions qw/catdir catfile curdir abs2rel rel2abs/;
18 use File::Basename;
19 if ($^O ne "VMS") {
20     use File::Glob qw/glob/;
21 }
22 use Test::Harness qw/runtests $switches/;
23
24 my $srctop = $ENV{SRCTOP} || $ENV{TOP};
25 my $bldtop = $ENV{BLDTOP} || $ENV{TOP};
26 my $recipesdir = catdir($srctop, "test", "recipes");
27 my $testlib = catdir($srctop, "test", "testlib");
28 my $utillib = catdir($srctop, "util");
29
30 # It seems that $switches is getting interpreted with 'eval' or something
31 # like that, and that we need to take care of backslashes or they will
32 # disappear along the way.
33 $testlib =~ s|\\|\\\\|g if $^O eq "MSWin32";
34 $utillib =~ s|\\|\\\\|g if $^O eq "MSWin32";
35
36 # Test::Harness provides the variable $switches to give it
37 # switches to be used when it calls our recipes.
38 $switches = "-w \"-I$testlib\" \"-I$utillib\"";
39
40 my @tests = ( "alltests" );
41 if (@ARGV) {
42     @tests = @ARGV;
43 }
44 my $list_mode = scalar(grep /^list$/, @tests) != 0;
45 if (grep /^(alltests|list)$/, @tests) {
46     @tests = grep {
47         basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
48     } glob(catfile($recipesdir,"*.t"));
49 } else {
50     my @t = ();
51     foreach (@tests) {
52         push @t, grep {
53             basename($_) =~ /^[0-9][0-9]-[^\.]*\.t$/
54         } glob(catfile($recipesdir,"*-$_.t"));
55     }
56     @tests = @t;
57 }
58
59 if ($list_mode) {
60     @tests = map { $_ = basename($_); $_ =~ s/^[0-9][0-9]-//; $_ =~ s/\.t$//;
61                    $_ } @tests;
62     print join("\n", @tests), "\n";
63 } else {
64     @tests = map { abs2rel($_, rel2abs(curdir())); } @tests;
65
66     runtests(sort @tests);
67 }