File Coverage

blib/lib/Test/Module/Runnable.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 4 4 100.0
total 26 26 100.0


line stmt bran cond sub pod time code
1             # Module test framework
2             # Copyright (c) 2015-2017, Duncan Ross Palmer (2E0EOL) and others,
3             # All rights reserved.
4             #
5             # Redistribution and use in source and binary forms, with or without
6             # modification, are permitted provided that the following conditions are met:
7             #
8             # * Redistributions of source code must retain the above copyright notice,
9             # this list of conditions and the following disclaimer.
10             #
11             # * Redistributions in binary form must reproduce the above copyright
12             # notice, this list of conditions and the following disclaimer in the
13             # documentation and/or other materials provided with the distribution.
14             #
15             # * Neither the name of the Daybo Logic nor the names of its contributors
16             # may be used to endorse or promote products derived from this software
17             # without specific prior written permission.
18             #
19             # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20             # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21             # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22             # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23             # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24             # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25             # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26             # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27             # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28             # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29             # POSSIBILITY OF SUCH DAMAGE.
30              
31             =head1 NAME
32              
33             Test::Module::Runnable - A runnable framework on Moose for running tests
34              
35             =head1 SYNOPSIS
36              
37             package YourTestSuite;
38             use Moose;
39             use Test::More 0.96;
40              
41             extends 'Test::Module::Runnable';
42              
43             sub helper { } # Not called
44              
45             sub testExample { } # Automagically called due to 'test' prefix.
46              
47             package main;
48              
49             my $tester = new YourTestSuite;
50             plan tests => $tester->testCount;
51             foreach my $name ($tester->testMethods) {
52             subtest $name => $tester->$name;
53             }
54              
55             alternatively...
56              
57             my $tester = new YourTestSuite;
58             return $tester->run;
59              
60             =head1 DESCRIPTION
61              
62             A test framework based on Moose introspection to automagically
63             call all methods matching a user-defined pattern. Supports per-test
64             setup and tear-down routines and easy early L<Test::Builder/BAIL_OUT> using
65             L<Test::More>.
66              
67             =cut
68              
69             package Test::Module::Runnable;
70 4     4   1181873 use Moose;
  4         360858  
  4         24  
71 4     4   23998 use Test::More 0.96;
  4         139921  
  4         32  
72 4     4   1418 use POSIX qw/EXIT_SUCCESS/;
  4         4416  
  4         29  
73              
74             BEGIN {
75 4     4   1599 our $VERSION = '0.2.3';
76             }
77              
78             extends 'Test::Module::Runnable::Base';
79              
80             =head1 USER DEFINED METHODS
81              
82             =over
83              
84             =item C<setUpBeforeClass>
85              
86             If you need to initialize your test suite before any tests run,
87             this hook is your opportunity. If the setup fails, you should
88             return C<EXIT_FAILURE>. you must return C<EXIT_SUCCESS> in order
89             for tests to proceed.
90              
91             Don't write code here! Override the method in your test class.
92              
93             The default action is to do nothing.
94              
95             =cut
96              
97             sub setUpBeforeClass {
98 2     2 1 7 return EXIT_SUCCESS;
99             }
100              
101             =item C<tearDownAfterClass>
102              
103             If you need to finalize any cleanup for your test suite, after all
104             tests have completed running, this hook is your opportunity. If the
105             cleanup fails, you should return C<EXIT_FAILURE>. If cleanup succeeds,
106             you should return C<EXIT_SUCCESS>. You can also perform final sanity checking
107             here, because retuning C<EXIT_FAILURE> causes the suite to call
108             L<Test::Builder/BAIL_OUT>.
109              
110             Don't write code here! Override the method in your test class.
111              
112             The default action is to do nothing.
113              
114             =cut
115              
116             sub tearDownAfterClass {
117 3     3 1 10 return EXIT_SUCCESS;
118             }
119              
120             =item C<setUp>
121              
122             If you need to perform per-test setup, ie. before individual test methods
123             run, you should override this hook. You must return C<EXIT_SUCCESS> from
124             the hook, otherwise the entire test suite will be aborted via L<Test::Builder/BAIL_OUT>.
125              
126             Don't write code here! Override the method in your test class.
127              
128             The default action is to do nothing.
129              
130             =cut
131              
132             sub setUp {
133 1     1 1 3 return EXIT_SUCCESS;
134             }
135              
136             =item C<tearDown>
137              
138             If you need to perform per-test cleanup, ie. after individual test methods
139             run, you should override this hook. You must return C<EXIT_SUCCESS> from
140             the hook, otherwise the entire test suite will be aborted via L<Test::Builder/BAIL_OUT>.
141              
142             Don't write code here! Override the method in your test class.
143              
144             The default action is to do nothing.
145              
146             =cut
147              
148             sub tearDown {
149 3     3 1 9 return EXIT_SUCCESS;
150             }
151              
152             =back
153              
154             =cut
155              
156             1;