NAME

TAP::Formatter::Event - event interface to TAP::Formatter or TAP::Harness::Async

VERSION

version 0.001

SYNOPSIS

use TAP::Harness;
use TAP::Formatter::Event;
my $harness = TAP::Harness->new({
  formatter => TAP::Formatter::Event->new({ verbosity => 1 })->add_handler_for_event(
    test_failed => sub {
      my ($self, $session, $test) = @_;
      print "Failed test: " . $test->description . "\n";
    }
  ),
});
$harness->runtests(@ARGV);

DESCRIPTION

Used by some examples in TAP::Harness::Async. Note that TAP::Harness provides an event interface already, so unless you're specifically after the async approach for running tests then you may be better served by "CALLBACKS" in TAP::Parser.

METHODS

Normally all methods would be called from TAP::Harness::Async. See Mixin::Event::Dispatch and TAP::Formatter::Base for other available methods.

open_test

summary

EVENTS

Events are triggered through the "invoke_event" in Mixin::Event::Dispatch interface, use "add_handler_for_event" in Mixin::Event::Dispatch to attach handlers as required. Unhandled events are ignored.

Example:

my $file;
$formatter->add_handler_for_event(
  test_failed => sub { warn "Test failed: " . $_[1]->description },
  new_session => sub {
    my ($self, $session) = @_;
    $file = $session->name;
    warn "Started session for [$file]";
    return $self;
  },
  test_passed => sub {
    my ($self, $test) = @_;
    warn "Test passed, description: " . $test->description;
    ++$passed{$self->testfile};
    $self;
  }
);

new_session

Called when a new session ("test file") starts.

Receives a single TAP::Parser::Result object.

test_started

A test run has started.

test_result

We have received a single result.

test_plan

This is the plan for the current test.

test_passed

A test has passed.

test_failed

A test has failed.

test_unknown

Unknown test result.

test_finished

A test file has finished.

summary

The summary results are ready.

SEE ALSO

AUTHOR

Tom Molesworth <cpan@entitymodel.com>

LICENSE

Copyright Tom Molesworth 2011-2012. Licensed under the same terms as Perl itself.