Perl 5 version 26.3 documentation

Test2::Formatter::TAP

NAME

Test2::Formatter::TAP - Standard TAP formatter

DESCRIPTION

This is what takes events and turns them into TAP.

SYNOPSIS

  1. use Test2::Formatter::TAP;
  2. my $tap = Test2::Formatter::TAP->new();
  3. # Switch to utf8
  4. $tap->encoding('utf8');
  5. $tap->write($event, $number); # Output an event

METHODS

  • $bool = $tap->no_numbers
  • $tap->set_no_numbers($bool)

    Use to turn numbers on and off.

  • $arrayref = $tap->handles
  • $tap->set_handles(\@handles);

    Can be used to get/set the filehandles. Indexes are identified by the OUT_STD and OUT_ERR constants.

  • $encoding = $tap->encoding
  • $tap->encoding($encoding)

    Get or set the encoding. By default no encoding is set, the original settings of STDOUT and STDERR are used.

    This directly modifies the stored filehandles, it does not create new ones.

  • $tap->write($e, $num)

    Write an event to the console.

  • Test2::Formatter::TAP->register_event($pkg, sub { ... });

    In general custom events are not supported. There are however occasions where you might want to write a custom event type that results in TAP output. In order to do this you use the register_event() class method.

    1. package My::Event;
    2. use Test2::Formatter::TAP;
    3. use base 'Test2::Event';
    4. use Test2::Util::HashBase qw/pass name diag note/;
    5. Test2::Formatter::TAP->register_event(
    6. __PACKAGE__,
    7. sub {
    8. my $self = shift;
    9. my ($e, $num) = @_;
    10. return (
    11. [Test2::Formatter::TAP::OUT_STD, "ok $num - " . $e->name . "\n"],
    12. [Test2::Formatter::TAP::OUT_ERR, "# " . $e->name . " " . $e->diag . "\n"],
    13. [Test2::Formatter::TAP::OUT_STD, "# " . $e->name . " " . $e->note . "\n"],
    14. );
    15. }
    16. );
    17. 1;

EVENT METHODS

All these methods require the event itself. Optionally they can all except a test number.

All methods return a list of array-refs. Each array-ref will have 2 items, the first is an integer identifying an output handle, the second is a string that should be written to the handle.

  • @out = $TAP->event_ok($e)
  • @out = $TAP->event_ok($e, $num)

    Process an Test2::Event::Ok event.

  • @out = $TAP->event_plan($e)
  • @out = $TAP->event_plan($e, $num)

    Process an Test2::Event::Plan event.

  • @out = $TAP->event_note($e)
  • @out = $TAP->event_note($e, $num)

    Process an Test2::Event::Note event.

  • @out = $TAP->event_diag($e)
  • @out = $TAP->event_diag($e, $num)

    Process an Test2::Event::Diag event.

  • @out = $TAP->event_bail($e)
  • @out = $TAP->event_bail($e, $num)

    Process an Test2::Event::Bail event.

  • @out = $TAP->event_exception($e)
  • @out = $TAP->event_exception($e, $num)

    Process an Test2::Event::Exception event.

  • @out = $TAP->event_skip($e)
  • @out = $TAP->event_skip($e, $num)

    Process an Test2::Event::Skip event.

  • @out = $TAP->event_subtest($e)
  • @out = $TAP->event_subtest($e, $num)

    Process an Test2::Event::Subtest event.

  • @out = $TAP->event_other($e, $num)

    Fallback for unregistered event types. It uses the Test2::Event API to convert the event to TAP.

SOURCE

The source code repository for Test2 can be found at http://github.com/Test-More/test-more/.

MAINTAINERS

  • Chad Granum <exodist@cpan.org>

AUTHORS

  • Chad Granum <exodist@cpan.org>
  • Kent Fredric <kentnl@cpan.org>

COPYRIGHT

Copyright 2016 Chad Granum <exodist@cpan.org>.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://dev.perl.org/licenses/