+
+# The following is quite a bit of hackery to adapt to both TAP::Harness
+# and Test::Harness, depending on what's available.
+# The TAP::Harness hack allows support for HARNESS_VERBOSE_FAILURE* and
+# HARNESS_TAP_COPY, while the Test::Harness hack can't, because the pre
+# TAP::Harness Test::Harness simply doesn't have support for this sort of
+# thing.
+#
+# We use eval to avoid undue interruption if TAP::Harness isn't present.
+
+my $package;
+my $eres;
+
+$eres = eval {
+ package TAP::Parser::OpenSSL;
+ use parent 'TAP::Parser';
+
+ sub new {
+ my $class = shift;
+ my %opts = %{ shift() };
+ my $failure_verbosity = $openssl_args{failure_verbosity};
+ my @plans = (); # initial level, no plan yet
+ my $output_buffer = "";
+
+ # We rely heavily on perl closures to make failure verbosity work
+ # We need to do so, because there's no way to safely pass extra
+ # objects down all the way to the TAP::Parser::Result object
+ my @failure_output = ();
+ my %callbacks = ();
+ if ($failure_verbosity > 0 || defined $openssl_args{tap_copy}) {
+ $callbacks{ALL} = sub { # on each line of test output
+ my $self = shift;
+ my $fh = $openssl_args{tap_copy};
+ print $fh $self->as_string, "\n"
+ if defined $fh;
+
+ my $failure_verbosity = $openssl_args{failure_verbosity};
+ if ($failure_verbosity > 0) {
+ my $is_plan = $self->is_plan;
+ my $tests_planned = $is_plan && $self->tests_planned;
+ my $is_test = $self->is_test;
+ my $is_ok = $is_test && $self->is_ok;
+
+ # workaround for parser not coping with sub-test indentation
+ if ($self->is_unknown) {
+ my $level = $#plans;
+ my $indent = $level < 0 ? "" : " " x ($level * 4);
+
+ ($is_plan, $tests_planned) = (1, $1)
+ if ($self->as_string =~ m/^$indent 1\.\.(\d+)/);
+ ($is_test, $is_ok) = (1, !$1)
+ if ($self->as_string =~ m/^$indent(not )?ok /);
+ }
+
+ if ($is_plan) {
+ push @plans, $tests_planned;
+ $output_buffer = ""; # ignore comments etc. until plan
+ } elsif ($is_test) { # result of a test
+ pop @plans if @plans && --($plans[-1]) <= 0;
+ print $output_buffer if !$is_ok;
+ print "\n".$self->as_string
+ if !$is_ok || $failure_verbosity == 2;
+ print "\n# ------------------------------------------------------------------------------" if !$is_ok;
+ $output_buffer = "";
+ } elsif ($self->as_string ne "") {
+ # typically is_comment or is_unknown
+ $output_buffer .= "\n".$self->as_string;
+ }
+ }
+ }
+ }
+
+ if ($failure_verbosity > 0) {
+ $callbacks{EOF} = sub {
+ my $self = shift;
+
+ # We know we are a TAP::Parser::Aggregator object
+ if (scalar $self->failed > 0 && @failure_output) {
+ # We add an extra empty line, because in the case of a
+ # progress counter, we're still at the end of that progress
+ # line.
+ print $_, "\n" foreach (("", @failure_output));
+ }
+ # Echo any trailing comments etc.
+ print "$output_buffer";
+ };
+ }
+
+ if (keys %callbacks) {
+ # If %opts already has a callbacks element, the order here
+ # ensures we do not override it
+ %opts = ( callbacks => { %callbacks }, %opts );
+ }
+
+ return $class->SUPER::new({ %opts });