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

Subtests and todos #537

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/Test/Stream/Event/Subtest.pm
Expand Up @@ -43,6 +43,29 @@ sub init {
push @{$self->[DIAG]} => " No tests run for subtest."
unless $self->[EXCEPTION] || $self->[EARLY_RETURN] || $self->[STATE]->[STATE_COUNT];

# I HAVE NO IDEA WHAT I'M DOING !!!
# The state of the aggregate is computed as follow:
# 1. If there is any real error => the aggregate is not ok. Full stop.
# 2. If not, if there is any TODO subtests, the aggregate is also TODO
# 3. If a TODO is failing, the aggregate result is not ok.

if ( $self->real_bool ) {
# [8][4] == list of events. There's probably a less savage way
# of getting them
for my $event ( @{ $self->[8][4] || [] } ) {
# only bother if it's an OK event and it's in a todo state
next unless ( ref $event eq 'Test::Stream::Event::Ok'
or ref $event eq 'Test::Stream::Event::Subtest' )
and $event->context->in_todo;

# force the parent test to be in a TODO state
$self->context->[3] ||= 1; # force to be TODO

# if a child fail, so is the parent
$self->set_real_bool( 0 ) if not $event->real_bool ;
}
}

# Have the 'OK' init run
$self->SUPER::init();
}
Expand Down
69 changes: 69 additions & 0 deletions subtest_checks.pl
@@ -0,0 +1,69 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;

subtest passing => sub {
pass;
};

subtest failing => sub {
fail;
};

subtest 'todo okay' => sub {
local $TODO = 'normal todo';
fail;
};

subtest 'todo flagged as passing' => sub {
local $TODO = 'normal todo';
pass;
};

subtest 'failing' => sub {
fail;

local $TODO = 'normal todo';
pass;
};

subtest 'todo flagged as passing' => sub {
pass;

local $TODO = 'normal todo';
pass;
};

subtest 'todo ok' => sub {
pass;

local $TODO = 'normal todo';
fail;
};

subtest 'embedded top is okay' => sub {
subtest 'level 1' => sub {
local $TODO = 'normal todo';
fail;
};
};

subtest 'embedded top is flagged' => sub {
subtest 'level 1' => sub {
local $TODO = 'normal todo';
pass;
};
};

subtest 'embedded top is flagged' => sub {
local $TODO = 'normal todo';
subtest 'level 1' => sub {
local $TODO = 'normal todo';
pass;
};
};

done_testing;