Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Revision history for Perl distribution Test-Class-Moose
[ENHANCEMENTS]

* Greatly expanded documentation for the test control methods.
* When using the sequential executor, the subtests used by
Test::Class::Moose are now streamed. Implemented by Greg Oschwald. GH
#107.


0.98 2019-10-26
Expand Down
7 changes: 7 additions & 0 deletions lib/Test/Class/Moose/Executor/Parallel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use Scalar::Util qw(reftype);
use TAP::Formatter::Color 3.29;
use Test2::API qw( test2_stack );
use Test2::AsyncSubtest 0.000018 ();
use Test2::Tools::AsyncSubtest qw( async_subtest );
use Test::Class::Moose::AttributeRegistry;
use Test::Class::Moose::Report::Class;
use Try::Tiny;
Expand Down Expand Up @@ -194,6 +195,12 @@ sub _build_color {
return TAP::Formatter::Color->new;
}

sub _run_subtest {
shift;

async_subtest(@_)->finish;
}

1;

=for Pod::Coverage Tags Tests runtests
19 changes: 19 additions & 0 deletions lib/Test/Class/Moose/Executor/Sequential.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,28 @@ our $VERSION = '0.99';

use Moose 2.0000;
use Carp;
use Test2::API qw( context run_subtest );
use namespace::autoclean;
with 'Test::Class::Moose::Role::Executor';

sub _run_subtest {
shift;
my $name = shift;
my $params = shift;
my $code = shift;

my $ctx = context();
my $pass = run_subtest(
$name,
$code,
{ %{$params}, buffered => 0 },
@_,
);
$ctx->release;

return $pass;
}

__PACKAGE__->meta->make_immutable;

1;
Expand Down
20 changes: 9 additions & 11 deletions lib/Test/Class/Moose/Role/Executor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use namespace::autoclean;
use List::SomeUtils qw(uniq);
use List::Util qw(shuffle);
use Test2::API qw( test2_stack );
use Test2::Tools::AsyncSubtest qw( async_subtest );
use Test::Class::Moose::AttributeRegistry;
use Test::Class::Moose::Config;
use Test::Class::Moose::Report::Class;
Expand All @@ -23,6 +22,8 @@ use Test::Class::Moose::Report;
use Test::Class::Moose::Util qw( context_do );
use Try::Tiny;

requires '_run_subtest';

has 'test_configuration' => (
is => 'ro',
isa => 'Test::Class::Moose::Config',
Expand Down Expand Up @@ -94,11 +95,11 @@ sub _run_test_classes {
my @test_classes = @_;

for my $test_class (@test_classes) {
async_subtest(
$self->_run_subtest(
$test_class,
{ manual_skip_all => 1 },
sub { $self->run_test_class($test_class) }
)->finish;
);
}
}

Expand Down Expand Up @@ -180,7 +181,7 @@ sub _maybe_wrap_test_instance {
) unless $in_subtest;

my $instance_report;
async_subtest(
$self->_run_subtest(
$test_instance->test_instance_name,
{ manual_skip_all => 1 },
sub {
Expand All @@ -189,7 +190,7 @@ sub _maybe_wrap_test_instance {
$class_report,
);
},
)->finish;
);

return $instance_report;
}
Expand Down Expand Up @@ -225,8 +226,6 @@ sub run_test_instance {
return;
}

my $report = $self->test_report;

unless (
$self->run_test_control_method(
$test_instance, 'test_startup', $instance_report,
Expand Down Expand Up @@ -436,8 +435,7 @@ sub run_test_method {

$method_report->_start_benchmark;

my $num_tests = 0;
my $test_class = $test_instance->test_class;
my $num_tests = 0;

context_do {
my $ctx = shift;
Expand All @@ -446,7 +444,7 @@ sub run_test_method {

# If the call to ->$test_method fails then this subtest will fail and
# Test2::API will also include a diagnostic message with the error.
my $p = async_subtest(
my $p = $self->_run_subtest(
$test_method,
{ manual_skip_all => 1 },
sub {
Expand All @@ -466,7 +464,7 @@ sub run_test_method {
$test_instance->$test_method($method_report);
$num_tests = $hub->count;
},
)->finish;
);

$method_report->_end_benchmark;
if ( $self->test_configuration->show_timing ) {
Expand Down
36 changes: 26 additions & 10 deletions t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@ subtest_streamed(
call max => 2;
};
TestsFor::Basic->expected_test_events;
event Note => sub {
call message => 'TestsFor::Basic::Subclass';
};
event Subtest => sub {
call name => 'TestsFor::Basic::Subclass';
call pass => F();
call subevents => array {
event Plan => sub {
call max => 6;
};
event Note => sub {
call message => 'test_me';
};
event Subtest => sub {
call name => 'test_me';
call pass => T();
Expand All @@ -113,6 +119,9 @@ subtest_streamed(
end();
};
};
event Note => sub {
call message => 'test_my_instance_name';
};
event Subtest => sub {
call name => 'test_my_instance_name';
call pass => T();
Expand All @@ -128,6 +137,9 @@ subtest_streamed(
end();
};
};
event Note => sub {
call message => 'test_reporting';
};
event Subtest => sub {
call name => 'test_reporting';
call pass => T();
Expand Down Expand Up @@ -158,6 +170,9 @@ subtest_streamed(
end();
};
};
event Note => sub {
call message => 'test_this_baby';
};
event Subtest => sub {
call name => 'test_this_baby';
call pass => T();
Expand Down Expand Up @@ -188,6 +203,9 @@ subtest_streamed(
end();
};
};
event Note => sub {
call message => 'test_this_should_be_run';
};
event Subtest => sub {
call name => 'test_this_should_be_run';
call pass => T();
Expand Down Expand Up @@ -223,30 +241,28 @@ subtest_streamed(
end();
};
};
event Note => sub {
call message => 'test_this_will_die';
};
event Subtest => sub {
call name => 'test_this_will_die';
call pass => F();
call subevents => array {
event Exception => sub {
call error => match
qr{\Qforced die at \E.*\Qbasic.t\E.+}s;
};
event Plan => sub {
call max => 0;
};
end();
};
};
event Diag => sub {
call message => match qr{^\n?Failed test};
};
event Diag => sub {
call message => match
qr{\QFailed test 'test_this_will_die'\E.+}s;
qr{\Qforced die at \E.*\Qbasic.t\E.+}s;
};
end();
};
};
event Diag => sub {
call message => match
qr{\QFailed test 'TestsFor::Basic::Subclass'\E.+}s;
call message => match qr{^\n?Failed test};
};
end();
}
Expand Down
143 changes: 143 additions & 0 deletions t/basiclib/TestsFor/Basic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,149 @@ sub test_reporting {
}

sub expected_test_events {
event Note => sub {
call message => 'TestsFor::Basic';
};
event Subtest => sub {
call name => 'TestsFor::Basic';
call pass => T();
call subevents => array {
filter_items {
grep {
!$_->isa('Test2::AsyncSubtest::Event::Attach')
&& !$_->isa('Test2::AsyncSubtest::Event::Detach')
} @_;
};
event Plan => sub {
call max => 4;
call trace => object {
call package => 'Test::Class::Moose::Role::Executor';
call subname => 'Test::Class::Moose::Util::context_do';
};
};
event Note => sub {
call message => 'test_me';
};
event Subtest => sub {
call name => 'test_me';
call pass => T();
call subevents => array {
event Ok => sub {
call pass => T();
call name => 'test_me() ran (TestsFor::Basic)';
call trace => object {
call package => 'TestsFor::Basic';
call subname => 'Test2::Tools::Basic::ok';
};
};
event Ok => sub {
call pass => T();
call name => 'this is another test (TestsFor::Basic)';
call trace => object {
call package => 'TestsFor::Basic';
call subname => 'Test2::Tools::Basic::ok';
};
};
event Ok => sub {
call pass => T();
call name =>
'test_setup() should know our current class name';
};
event Ok => sub {
call pass => T();
call name => '... and our current method name';
};
event Plan => sub {
call max => 4;
};
end();
};
};
event Note => sub {
call message => 'test_my_instance_name';
};
event Subtest => sub {
call name => 'test_my_instance_name';
call pass => T();
call subevents => array {
event Ok => sub {
call pass => T();
call name => 'test_instance_name matches class name';
call trace => object {
call package => 'TestsFor::Basic';
call subname => 'Test2::Tools::Compare::is';
};
};
event Plan => sub {
call max => 1;
};
end();
};
};
event Note => sub {
call message => 'test_reporting';
};
event Subtest => sub {
call name => 'test_reporting';
call pass => T();
call subevents => array {
event Ok => sub {
call pass => T();
call name =>
'current_instance() should report the correct class name';
};
event Ok => sub {
call pass => T();
call name =>
'... and we should also be able to get the current method name';
};
event Ok => sub {
call pass => T();
call name =>
'test_setup() should know our current class name';
};
event Ok => sub {
call pass => T();
call name => '... and our current method name';
};
event Plan => sub {
call max => 4;
};
end();
};
};
event Note => sub {
call message => 'test_this_baby';
};
event Subtest => sub {
call name => 'test_this_baby';
call pass => T();
call subevents => array {
event Ok => sub {
call pass => T();
call name => 'whee! (TestsFor::Basic)';
};
event Ok => sub {
call pass => T();
call name =>
'test_setup() should know our current class name';
};
event Ok => sub {
call pass => T();
call name => '... and our current method name';
};
event Plan => sub {
call max => 3;
};
end();
};
};
end();
};
};
}

sub expected_parallel_test_events {
event Subtest => sub {
call name => 'TestsFor::Basic';
call pass => T();
Expand Down
Loading