Simple.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. package OpenSSL::Test::Simple;
  8. use strict;
  9. use warnings;
  10. use Exporter;
  11. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  12. $VERSION = "0.2";
  13. @ISA = qw(Exporter);
  14. @EXPORT = qw(simple_test);
  15. =head1 NAME
  16. OpenSSL::Test::Simple - a few very simple test functions
  17. =head1 SYNOPSIS
  18. use OpenSSL::Test::Simple;
  19. simple_test("my_test_name", "destest", "des");
  20. =head1 DESCRIPTION
  21. Sometimes, the functions in L<OpenSSL::Test> are quite tedious for some
  22. repetitive tasks. This module provides functions to make life easier.
  23. You could call them hacks if you wish.
  24. =cut
  25. use OpenSSL::Test;
  26. use OpenSSL::Test::Utils;
  27. =over 4
  28. =item B<simple_test NAME, PROGRAM, ALGORITHM>
  29. Runs a test named NAME, running the program PROGRAM with no arguments,
  30. to test the algorithm ALGORITHM.
  31. A complete recipe looks like this:
  32. use OpenSSL::Test::Simple;
  33. simple_test("test_bf", "bftest", "bf");
  34. =back
  35. =cut
  36. # args:
  37. # name (used with setup())
  38. # algorithm (used to check if it's at all supported)
  39. # name of binary (the program that does the actual test)
  40. sub simple_test {
  41. my ($name, $prgr, @algos) = @_;
  42. setup($name);
  43. if (scalar(disabled(@algos))) {
  44. if (scalar(@algos) == 1) {
  45. plan skip_all => $algos[0]." is not supported by this OpenSSL build";
  46. } else {
  47. my $last = pop @algos;
  48. plan skip_all => join(", ", @algos)." and $last are not supported by this OpenSSL build";
  49. }
  50. }
  51. plan tests => 1;
  52. ok(run(test([$prgr])), "running $prgr");
  53. }
  54. =head1 SEE ALSO
  55. L<OpenSSL::Test>
  56. =head1 AUTHORS
  57. Richard Levitte E<lt>levitte@openssl.orgE<gt> with inspiration
  58. from Rich Salz E<lt>rsalz@openssl.orgE<gt>.
  59. =cut
  60. 1;