fc9b5336138a58d6d1baf6cac964cd3bbf9bc7c1
[openssl.git] / test / testlib / OpenSSL / Test / Utils.pm
1 package OpenSSL::Test::Utils;
2
3 use strict;
4 use warnings;
5
6 use Exporter;
7 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
8 $VERSION = "0.1";
9 @ISA = qw(Exporter);
10 @EXPORT = qw(disabled);
11
12 =head1 NAME
13
14 OpenSSL::Test::Utils - test utility functions
15
16 =head1 SYNOPSIS
17
18   use OpenSSL::Test::Utils;
19
20   disabled("dh");
21
22 =head1 DESCRIPTION
23
24 This module provides utility functions for the testing framework.
25
26 =cut
27
28 use OpenSSL::Test;
29
30 =over 4
31
32 =item B<disabled ARRAY>
33
34 In a scalar context returns 1 if any of the features in ARRAY is disabled.
35
36 In an array context returns an array with each element set to 1 if the
37 corresponding feature is disabled and 0 otherwise.
38
39 =back
40
41 =cut
42
43 our %disabled;
44 my $disabled_set = 0;
45
46 sub check_disabled {
47 #print STDERR "Running check_disabled\n";
48     foreach (run(app(["openssl", "list", "-disabled"]), capture => 1)) {
49         chomp;
50         next if /:/;    # skip header
51         $disabled{lc $_} = 1;
52     }
53     $disabled_set = 1;
54 }
55
56 # args:
57 #  list of features to check
58 sub disabled {
59     check_disabled() unless $disabled_set;
60     if (wantarray) {
61         my @ret;
62         foreach (@_) {
63             push @ret, exists $disabled{lc $_} ? 1 : 0;
64         }
65         return @ret;
66     }
67     foreach (@_) {
68         return 1 if exists $disabled{lc $_};
69     }
70     return 0;
71 }
72
73 =head1 SEE ALSO
74
75 L<OpenSSL::Test>
76
77 =head1 AUTHORS
78
79 Stephen Henson E<lt>steve@openssl.orgE<gt> with inspiration
80 from Richard Levitte E<lt>levitte@openssl.orgE<gt>
81
82 =cut
83
84 1;