Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cassandane: support multiple output formats per run #4970

Merged
merged 6 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
# OF THIS SOFTWARE.
#

package Cassandane::Unit::RunnerPretty;
package Cassandane::Unit::FormatPretty;
use strict;
use warnings;

use lib '.';
use base qw(Cassandane::Unit::Runner);
use base qw(Cassandane::Unit::Formatter);

sub new
{
Expand All @@ -66,7 +66,7 @@ sub new
sub ansi
{
my ($self, $codes, @args) = @_;
my $isatty = -t $self->print_stream;
my $isatty = -t $self->{fh};

my $ansi;

Expand All @@ -77,13 +77,6 @@ sub ansi
return $ansi;
}

sub start_test
{
my $self = shift;
my $test = shift;
# prevent the default action which is to print "."
}

sub add_pass
{
my $self = shift;
Expand All @@ -100,8 +93,6 @@ sub add_error
my $self = shift;
my $test = shift;

$self->record_failed($test);

my $line = sprintf "%s %s\n",
$self->ansi([31], '[ERROR ]'),
_getname($test);
Expand All @@ -113,7 +104,6 @@ sub add_failure
my $self = shift;
my $test = shift;

$self->record_failed($test);
my $line = sprintf "%s %s\n",
$self->ansi([33], '[FAILED]'),
_getname($test);
Expand Down Expand Up @@ -149,8 +139,8 @@ sub print_errors
my $saved_output_stream;
if ($self->{_quiet}) {
if ($self->{_quiet_report_fh}) {
$saved_output_stream = $self->{_Print_stream};
$self->{_Print_stream} = $self->{_quiet_report_fh};
$saved_output_stream = $self->{fh};
$self->{fh} = $self->{_quiet_report_fh};
}
else {
return;
Expand Down Expand Up @@ -178,7 +168,7 @@ sub print_errors
}

if ($saved_output_stream) {
$self->{_Print_stream} = $saved_output_stream;
$self->{fh} = $saved_output_stream;
}
}

Expand All @@ -189,8 +179,8 @@ sub print_failures
my $saved_output_stream;
if ($self->{_quiet}) {
if ($self->{_quiet_report_fh}) {
$saved_output_stream = $self->{_Print_stream};
$self->{_Print_stream} = $self->{_quiet_report_fh};
$saved_output_stream = $self->{fh};
$self->{fh} = $self->{_quiet_report_fh};
}
else {
return;
Expand Down Expand Up @@ -218,7 +208,7 @@ sub print_failures
}

if ($saved_output_stream) {
$self->{_Print_stream} = $saved_output_stream;
$self->{fh} = $saved_output_stream;
}
}

Expand Down
44 changes: 15 additions & 29 deletions cassandane/testrunner.pl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@

use lib '.';
use Cassandane::Util::Setup;
use Cassandane::Unit::FormatPretty;
use Cassandane::Unit::FormatTAP;
use Cassandane::Unit::Runner;
use Cassandane::Unit::RunnerPretty;
use Cassandane::Unit::TestPlan;
use Cassandane::Util::Log;
use Cassandane::Cassini;
Expand Down Expand Up @@ -146,36 +146,22 @@
return Cassandane::Unit::FormatTAP->new($fh);
},
},
);
my %runners =
(
pretty => sub
{
my ($plan, $fh) = @_;
local *__ANON__ = "runner_pretty";
my $runner = Cassandane::Unit::RunnerPretty->new({}, $fh);
my @filters = qw(x skip_version skip_missing_features
skip_runtime_check
enable_wanted_properties);
push @filters, 'skip_slow' if $plan->{skip_slow};
push @filters, 'slow_only' if $plan->{slow_only};
$runner->filter(@filters);
return $runner->do_run($plan, 0);
pretty => {
writes_to_stdout => 1,
formatter => sub {
my ($fh) = @_;
return Cassandane::Unit::FormatPretty->new({}, $fh);
},
},
prettier => sub
{
my ($plan, $fh) = @_;
local *__ANON__ = "runner_prettier";
my $runner = Cassandane::Unit::RunnerPretty->new({quiet=>1}, $fh);
my @filters = qw(x skip_version skip_missing_features
skip_runtime_check
enable_wanted_properties);
push @filters, 'skip_slow' if $plan->{skip_slow};
push @filters, 'slow_only' if $plan->{slow_only};
$runner->filter(@filters);
return $runner->do_run($plan, 0);
prettier => {
writes_to_stdout => 1,
formatter => sub {
my ($fh) = @_;
return Cassandane::Unit::FormatPretty->new({quiet=>1}, $fh);
},
},
);
my %runners = ();

become_cyrus();

Expand Down Expand Up @@ -385,7 +371,7 @@ sub usage
$plan->schedule(@names);

# Run the schedule
$want_formats{tap} = 1 if not scalar keys %want_formats;
$want_formats{prettier} = 1 if not scalar keys %want_formats;
elliefm marked this conversation as resolved.
Show resolved Hide resolved
my @writes_to_stdout = grep {
$formatters{$_}->{writes_to_stdout}
} keys %want_formats;
Expand Down