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

NAME

6       Test2::Require - Base class and documentation for skip-unless type test
7       packages.
8

DESCRIPTION

10       Test2::Require::* packages are packages you load to ensure your test
11       file is skipped unless a specific requirement is met. Modules in this
12       namespace may subclass Test2::Require if they wish, but it is not
13       strictly necessary to do so.
14

HOW DO I WRITE A 'REQUIRE' MODULE?

16   AS A SUBCLASS
17           package Test2::Require::Widget;
18           use strict;
19           use warnings;
20
21           use base 'Test2::Require';
22
23           sub HAVE_WIDGETS { ... };
24
25           sub skip {
26               my $class = shift;
27               my @import_args = @_;
28
29               if (HAVE_WIDGETS()) {
30                   # We have widgets, do not skip
31                   return undef;
32               }
33               else {
34                   # No widgets, skip the test
35                   return "Skipped because there are no widgets" unless HAVE_WIDGETS();
36               }
37           }
38
39           1;
40
41       A subclass of Test2::Require simply needs to implement a "skip()"
42       method.  This method will receive all import arguments. This method
43       should return undef if the test should run, and should return a reason
44       for skipping if the test should be skipped.
45
46   STAND-ALONE
47       If you do not wish to subclass Test2::Require then you should write an
48       "import()" method:
49
50           package Test2::Require::Widget;
51           use strict;
52           use warnings;
53
54           use Test2::API qw/context/;
55
56           sub HAVE_WIDGETS { ... };
57
58           sub import {
59               my $class = shift;
60
61               # Have widgets, should run.
62               return if HAVE_WIDGETS();
63
64               # Use the context object to create the event
65               my $ctx = context();
66               $ctx->plan(0, SKIP => "Skipped because there are no widgets");
67               $ctx->release;
68           }
69
70           1;
71

SOURCE

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

MAINTAINERS

77       Chad Granum <exodist@cpan.org>
78

AUTHORS

80       Chad Granum <exodist@cpan.org>
81
83       Copyright 2018 Chad Granum <exodist@cpan.org>.
84
85       This program is free software; you can redistribute it and/or modify it
86       under the same terms as Perl itself.
87
88       See http://dev.perl.org/licenses/
89
90
91
92perl v5.36.0                      2022-07-22                 Test2::Require(3)
Impressum