xref: /openssl/util/perl/OpenSSL/Test/Simple.pm (revision 9059ab42)
1# Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
2#
3# Licensed under the Apache License 2.0 (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
8package OpenSSL::Test::Simple;
9
10use strict;
11use warnings;
12
13use Exporter;
14use 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
21OpenSSL::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
31Sometimes, the functions in L<OpenSSL::Test> are quite tedious for some
32repetitive tasks.  This module provides functions to make life easier.
33You could call them hacks if you wish.
34
35=cut
36
37use OpenSSL::Test;
38use OpenSSL::Test::Utils;
39
40=over 4
41
42=item B<simple_test NAME, PROGRAM, ALGORITHM>
43
44Runs a test named NAME, running the program PROGRAM with no arguments,
45to test the algorithm ALGORITHM.
46
47A 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)
61sub 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
82L<OpenSSL::Test>
83
84=head1 AUTHORS
85
86Richard Levitte E<lt>levitte@openssl.orgE<gt> with inspiration
87from Rich Salz E<lt>rsalz@openssl.orgE<gt>.
88
89=cut
90
911;
92