run_tests.pl 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. use strict;
  9. use warnings;
  10. # Recognise VERBOSE and V which is common on other projects.
  11. BEGIN {
  12. $ENV{HARNESS_VERBOSE} = "yes" if $ENV{VERBOSE} || $ENV{V};
  13. }
  14. use File::Spec::Functions qw/catdir catfile curdir abs2rel rel2abs/;
  15. use File::Basename;
  16. use if $^O ne "VMS", 'File::Glob' => qw/glob/;
  17. use Test::Harness qw/runtests $switches/;
  18. my $srctop = $ENV{SRCTOP} || $ENV{TOP};
  19. my $bldtop = $ENV{BLDTOP} || $ENV{TOP};
  20. my $recipesdir = catdir($srctop, "test", "recipes");
  21. my $testlib = catdir($srctop, "test", "testlib");
  22. my $utillib = catdir($srctop, "util");
  23. # It seems that $switches is getting interpreted with 'eval' or something
  24. # like that, and that we need to take care of backslashes or they will
  25. # disappear along the way.
  26. $testlib =~ s|\\|\\\\|g if $^O eq "MSWin32";
  27. $utillib =~ s|\\|\\\\|g if $^O eq "MSWin32";
  28. # Test::Harness provides the variable $switches to give it
  29. # switches to be used when it calls our recipes.
  30. $switches = "-w \"-I$testlib\" \"-I$utillib\"";
  31. my @alltests = find_matching_tests("*");
  32. my %tests = ();
  33. my $initial_arg = 1;
  34. foreach my $arg (@ARGV ? @ARGV : ('alltests')) {
  35. if ($arg eq 'list') {
  36. foreach (@alltests) {
  37. (my $x = basename($_)) =~ s|^[0-9][0-9]-(.*)\.t$|$1|;
  38. print $x,"\n";
  39. }
  40. exit 0;
  41. }
  42. if ($arg eq 'alltests') {
  43. warn "'alltests' encountered, ignoring everything before that...\n"
  44. unless $initial_arg;
  45. %tests = map { $_ => 1 } @alltests;
  46. } elsif ($arg =~ m/^(-?)(.*)/) {
  47. my $sign = $1;
  48. my $test = $2;
  49. my @matches = find_matching_tests($test);
  50. # If '-foo' is the first arg, it's short for 'alltests -foo'
  51. if ($sign eq '-' && $initial_arg) {
  52. %tests = map { $_ => 1 } @alltests;
  53. }
  54. if (scalar @matches == 0) {
  55. warn "Test $test found no match, skipping ",
  56. ($sign eq '-' ? "removal" : "addition"),
  57. "...\n";
  58. } else {
  59. foreach $test (@matches) {
  60. if ($sign eq '-') {
  61. delete $tests{$test};
  62. } else {
  63. $tests{$test} = 1;
  64. }
  65. }
  66. }
  67. } else {
  68. warn "I don't know what '$arg' is about, ignoring...\n";
  69. }
  70. $initial_arg = 0;
  71. }
  72. runtests(map { abs2rel($_, rel2abs(curdir())); } sort keys %tests);
  73. sub find_matching_tests {
  74. my ($glob) = @_;
  75. if ($glob =~ m|^[\d\[\]\?\-]+$|) {
  76. return glob(catfile($recipesdir,"$glob-*.t"));
  77. }
  78. return glob(catfile($recipesdir,"*-$glob.t"));
  79. }