Test::Stream::Event - Base class for events
Base class for all event objects that get passed through Test::Stream.
package Test::Stream::Event::MyEvent; use strict; use warnings; # This will make our class an event subclass, add the specified accessors, # inject a helper method into the context objects, and add constants for # all our fields, and fields we inherit. use Test::Stream::Event( accessors => [qw/foo bar baz/], ctx_method => 'my_event', ); # Chance to initialize some defaults sub init { my $self = shift; # no other args in @_ $self->SUPER::init(); $self->set_foo('xxx') unless defined $self->foo; # Events are arrayrefs, all accessors have a constant defined with # their index. $self->[BAR] ||= ""; ... } # If your event produces TAP output it must define this method sub to_tap { my $self = shift; return ( # Constants are defined at import, all are optional, and may appear # any number of times. [OUT_STD, $self->foo], [OUT_ERR, $self->bar], [OUT_STD, $self->baz], ); } # This is your hook to add details to the summary fields. sub extra_details { my $self = shift; my @super_details = $self->SUPER::extra_details(); return ( @super_details, foo => $self->foo || undef, bar => $self->bar || '', ... ); } 1;
In addition to the arguments listed here, you may pass in any arguments accepted by Test::Stream::ArrayBase.
This specifies the name of the helper meth that will be injected into Test::Stream::Context to help generate your events. If this is not specified it will use the lowercased last section of your package name.
This lets you specify an event class to subclass. THIS MUST BE AN EVENT CLASS. If you do not specify anything here then Test::Stream::Event will be used.
Test::Stream::Event
This lets you define any fields you wish to be present in your class. This is the only way to define storage for your event. Each field specified will get a read-only accessor with the same name as the field, as well as a setter set_FIELD(). You will also get a constant that returns the index of the field in the classes arrayref. The constant is the name of the field in all upper-case.
set_FIELD()
Test::Stream::Event is added to your @INC for you, unless you specify an alternative base class, which must itself subclass Test::Stream::Event.
Events CAN NOT use multiple inheritance in most cases. This is mainly because events are arrayrefs and not hashrefs. Each subclass must add fields as new indexes after the last index of the parent class.
All events need some initial fields for construction. These fields include a context, and some other state from construction time. The context object will get helper methods for all events that fill in these fields for you. It is not advised to ever construct an event object yourself, you should always use the context helper method.
Events are an arrayref. Events use Test::Stream::ArrayBase under the hood to generate accessors, constants, and field indexes. The key thing to take away from this is that you cannot add attributes on the fly, you MUST use Test::Stream::Event and/or Test::Stream::ArrayBase to add fields.
If you need a place to store extar generic, and possibly unpredictable, data, you should add a field and assign a hashref to it, then use that hashref to store your mixed data.
Get a snapshot of the context as it was when this event was generated
Get the caller() details from when the objects was created. This is usually the call to the tool that generated the event such as Test::More::ok().
caller()
Test::More::ok()
Check if the event was generated within a subtest.
Get the encoding that was in effect when the event was generated
Get an ordered key/value pair list of summary fields for the event. Override this to add additional fields.
Get an ordered key/value pair list of summary fields for the event, including parent class fields. In general you should not override this as it has a useful (thought not depended upon) order.
These are the fields that will be present when calling my %sum = $e->summary. Please note that the fields are returned as an order key+pair list, they can be directly assigned to a hash if desired, or they can be assigned to an array to preserver the order. The order is as it appears below, NOT alphabetical.
my %sum = $e->summary
The name of the event type, typically this is the lowercase form of the last part of the class name.
The package that generated this event.
The file in which the event was generated, and to which errors should be attributed.
The line number on which the event was generated, and to which errors should be attributed.
The package that provided the tool that generated the event (example: Test::More)
The name of the sub that produced the event (examples: ok(), is()).
ok()
is()
The encoding that should be used when printing the TAP output from this event.
True if the event was generated while TODO was in effect.
The todo message if the event was generated with TODO in effect.
The PID in which the event was generated.
The skip message if the event was generated via skip.
The source code repository for Test::More can be found at http://github.com/Test-More/test-more/.
The following people have all contributed to the Test-More dist (sorted using VIM's sort function).
There has been a lot of code migration between modules, here are all the original copyrights together:
Copyright 2014 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
Originally authored by Michael G Schwern <schwern@pobox.com> with much inspiration from Joshua Pritikin's Test module and lots of help from Barrie Slaymaker, Tony Bowden, blackstar.co.uk, chromatic, Fergal Daly and the perl-qa gang.
Idea by Tony Bowden and Paul Johnson, code by Michael G Schwern <schwern@pobox.com>, wardrobe by Calvin Klein.
Copyright 2001-2008 by Michael G Schwern <schwern@pobox.com>.
To the extent possible under law, 唐鳳 has waived all copyright and related or neighboring rights to Test-use-ok.
This work is published from Taiwan.
http://creativecommons.org/publicdomain/zero/1.0
This module is copyright 2005 Fergal Daly <fergal@esatclear.ie>, some parts are based on other people's work.
Under the same license as Perl itself
Copyright Mark Fowler <mark@twoshortplanks.com> 2002, 2004.
To install Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Simple
CPAN shell
perl -MCPAN -e shell install Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.