# Copyright 2016-2021 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
package OpenSSL::Test;
use strict;
use warnings;
use Carp;
use Test::More 0.96;
use Exporter;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = "1.0";
@ISA = qw(Exporter);
@EXPORT = (@Test::More::EXPORT, qw(setup run indir cmd app fuzz test
perlapp perltest subtest));
@EXPORT_OK = (@Test::More::EXPORT_OK, qw(bldtop_dir bldtop_file
srctop_dir srctop_file
data_file data_dir
result_file result_dir
pipe with cmdstr
openssl_versions
ok_nofips is_nofips isnt_nofips));
=head1 NAME
OpenSSL::Test - a private extension of Test::More
=head1 SYNOPSIS
use OpenSSL::Test;
setup("my_test_name");
plan tests => 2;
ok(run(app(["openssl", "version"])), "check for openssl presence");
indir "subdir" => sub {
ok(run(test(["sometest", "arg1"], stdout => "foo.txt")),
"run sometest with output to foo.txt");
};
=head1 DESCRIPTION
This module is a private extension of L<Test::More> for testing OpenSSL.
In addition to the Test::More functions, it also provides functions that
easily find the diverse programs within a OpenSSL build tree, as well as
some other useful functions.
This module I<depends> on the environment variables C<$TOP> or C<$SRCTOP>
and C<$BLDTOP>. Without one of the combinations it refuses to work.
See L</ENVIRONMENT> below.
With each test recipe, a parallel data directory with (almost) the same name
as the recipe is possible in the source directory tree. For example, for a
recipe C<$SRCTOP/test/recipes/99-foo.t>, there could be a directory
C<$SRCTOP/test/recipes/99-foo_data/>.
=cut
use File::Copy;
use File::Spec::Functions qw/file_name_is_absolute curdir canonpath splitdir
catdir catfile splitpath catpath devnull abs2rel/;
use File::Path 2.00 qw/rmtree mkpath/;
use File::Basename;
use Cwd qw/getcwd abs_path/;
use OpenSSL::Util;
my $level = 0;
# The name of the test. This is set by setup() and is used in the other
# functions to verify that setup() has been used.
my $test_name = undef;
# Directories we want to keep track of TOP, APPS, TEST and RESULTS are the
# ones we're interested in, corresponding to the environment variables TOP
# (mandatory), BIN_D, TEST_D, UTIL_D and RESULT_D.
my %directories = ();
# The environment variables that gave us the contents in %directories. These
# get modified whenever we change directories, so that subprocesses can use
# the values of those environment variables as well
my @direnv = ();
# A bool saying if we shall stop all testing if the current recipe has failing
# tests or not. This is set by setup() if the environment variable STOPTEST
# is defined with a non-empty value.
my $end_with_bailout = 0;
# A set of hooks that is affected by with() and may be used in diverse places.
# All hooks are expected to be CODE references.
my %hooks = (
# exit_checker is used by run() directly after completion of a command.
# it receives the exit code from that command and is expected to return
# 1 (for success) or 0 (for failure). This is the status value that run()
# will give back (through the |statusvar| reference and as returned value
# when capture => 1 doesn't apply).