line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!perl -Tw |
2
|
|
|
|
|
|
|
# Copyright Dominique Quatravaux 2006 - Licensed under the same terms as Perl itself |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
186
|
use 5.006; # "our" keyword |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
78
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
B - invoke a test suite at the end of a module. |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 SYNOPSIS |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package MyPackage; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
require My::Tests::Below unless caller(); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
1; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
__END__ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use MyPackage; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# And there you go with your test suite |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
DOMQ is a guy who releases CPAN packages from time to time - you are |
32
|
|
|
|
|
|
|
probably frobbing into one of them right now. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This package is a helper that supports my coding style for unit tests |
35
|
|
|
|
|
|
|
so as to facilitate relasing my code to the world. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 How it works |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
The test code is written in L style, that is, at the |
40
|
|
|
|
|
|
|
bottom of the Perl module to test, after an __END__ marker. This way |
41
|
|
|
|
|
|
|
of organizing test code is not unlike L, by Adam Kennedy |
42
|
|
|
|
|
|
|
et al, in that it keeps code, documentation and tests in the same |
43
|
|
|
|
|
|
|
place, encouraging developers to modify all three at once. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
I like to use L for the unit perlmodlib-style unit tests, |
46
|
|
|
|
|
|
|
because counting and recounting my tests drives me nuts :-). However |
47
|
|
|
|
|
|
|
C itself is testing-framework agnostic (its own |
48
|
|
|
|
|
|
|
self-test suite, for instance, uses only plain old L). |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Invoking C from anywhere (the idiomatic form |
51
|
|
|
|
|
|
|
is shown in L) results in the block of code after the |
52
|
|
|
|
|
|
|
__END__ marker being run at once. Due to the way this construct abuses |