1Test2::Tools(3)       User Contributed Perl Documentation      Test2::Tools(3)
2
3
4

NAME

6       Test2::Tools - Documentation for Tools.
7

DESCRIPTION

9       Tools are packages that export test functions, typically all related to
10       a specific aspect of testing. If you have a couple different categories
11       of exports then you may want to break them into separate modules.
12
13       Tools should export testing functions. Loading tools should not have
14       side effects, or alter the behavior of other tools. If you want to
15       alter behaviors or create side effects then you probably want to write
16       a Test2::Plugin.
17

FAQ

19       Why is it called Test2::Tools, and not Test2::Tool?
20           This question arises since Tools is the only namespace in the
21           plural. This is because each Plugin should be a distinct unit of
22           functionality, but a Tools dist can (and usually should) export
23           several tools. A bundle is also typically described as a single
24           unit. Nobody would like Test2::Bundles::Foo.
25
26       Should my tools subclass Test2::Tools?
27           No. Currently this class is empty. Eventually we may want to add
28           behavior, in which case we do not want anyone to already be
29           subclassing it.
30

HOW DO I WRITE A 'TOOLS' MODULE?

32       It is very easy to write tools:
33
34           package Test2::Tools::Mine
35           use strict;
36           use warnings;
37
38           # All tools should use the context() function.
39           use Test2::API qw/context/;
40
41           our @EXPORTS = qw/ok plan/;
42           use base 'Exporter';
43
44           sub ok($;$) {
45               my ($bool, $name) = @_;
46
47               # All tool functions should start by grabbing a context
48               my $ctx = context();
49
50               # The context is the primary interface for generating events
51               $ctx->ok($bool, $name);
52
53               # When you are done you release the context
54               $ctx->release;
55
56               return $bool ? 1 : 0;
57           }
58
59           sub plan {
60               my ($max) = @_;
61               my $ctx = context();
62               $ctx->plan($max);
63               $ctx->release;
64           }
65
66           1;
67
68       See Test2::API::Context for documentation on what the $ctx object can
69       do.
70

SOURCE

72       The source code repository for Test2-Suite can be found at
73       https://github.com/Test-More/Test2-Suite/.
74

MAINTAINERS

76       Chad Granum <exodist@cpan.org>
77

AUTHORS

79       Chad Granum <exodist@cpan.org>
80
82       Copyright 2018 Chad Granum <exodist@cpan.org>.
83
84       This program is free software; you can redistribute it and/or modify it
85       under the same terms as Perl itself.
86
87       See http://dev.perl.org/licenses/
88
89
90
91perl v5.32.0                      2020-12-16                   Test2::Tools(3)
Impressum