c5a84d5ca365b39668ef19ba2cf3f9ef66fee563
[openssl.git] / util / perl / OpenSSL / Test / Simple.pm
1 # Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
2 #
3 # Licensed under the OpenSSL license (the "License").  You may not use
4 # this file except in compliance with the License.  You can obtain a copy
5 # in the file LICENSE in the source distribution or at
6 # https://www.openssl.org/source/license.html
7
8 package OpenSSL::Test::Simple;
9
10 use strict;
11 use warnings;
12
13 use Exporter;
14 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
15 $VERSION = "0.2";
16 @ISA = qw(Exporter);
17 @EXPORT = qw(simple_test);
18
19 =head1 NAME
20
21 OpenSSL::Test::Simple - a few very simple test functions
22
23 =head1 SYNOPSIS
24
25   use OpenSSL::Test::Simple;
26
27   simple_test("my_test_name", "destest", "des");
28
29 =head1 DESCRIPTION
30
31 Sometimes, the functions in L<OpenSSL::Test> are quite tedious for some
32 repetitive tasks.  This module provides functions to make life easier.
33 You could call them hacks if you wish.
34
35 =cut
36
37 use OpenSSL::Test;
38 use OpenSSL::Test::Utils;
39
40 =over 4
41
42 =item B<simple_test NAME, PROGRAM, ALGORITHM>
43
44 Runs a test named NAME, running the program PROGRAM with no arguments,
45 to test the algorithm ALGORITHM.
46
47 A complete recipe looks like this:
48
49   use OpenSSL::Test::Simple;
50
51   simple_test("test_bf", "bftest", "bf");
52
53 =back
54
55 =cut
56
57 # args:
58 #  name                 (used with setup())
59 #  algorithm            (used to check if it's at all supported)
60 #  name of binary       (the program that does the actual test)
61 sub simple_test {
62     my ($name, $prgr, @algos) = @_;
63
64     setup($name);
65
66     if (scalar(disabled(@algos))) {
67         if (scalar(@algos) == 1) {
68             plan skip_all => $algos[0]." is not supported by this OpenSSL build";
69         } else {
70             my $last = pop @algos;
71             plan skip_all => join(", ", @algos)." and $last are not supported by this OpenSSL build";
72         }
73     }
74
75     plan tests => 1;
76
77     ok(run(test([$prgr])), "running $prgr");
78 }
79
80 =head1 SEE ALSO
81
82 L<OpenSSL::Test>
83
84 =head1 AUTHORS
85
86 Richard Levitte E<lt>levitte@openssl.orgE<gt> with inspiration
87 from Rich Salz E<lt>rsalz@openssl.orgE<gt>.
88
89 =cut
90
91 1;