Doctest/Example.pm

filter: Statementstmt 100% 10 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 93.3% 14 / 15 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Doctest.pm ↑ Summary
1 package Test::Doctest::Example;
2  
3 1 ▶use 5.005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # You can test this module from the command line:
8 # $ perl -MTest::Doctest -e run Test/Doctest/Example.pm
9  
10 =head1 Example
11  
12 =head2 This is only an example.
13  
14 >>> 1 + 1
15 2
16  
17 =head2 Checked values are perl expressons.
18  
19 >>> 'foo'
20 'foo'
21 >>> undef
22 undef
23  
24 =head2 They are compared in deep manner.
25  
26 >>> [1, 2, 3, {foo => 'bar', bar => 'foo'}]
27 [1, 2, 3, {bar => 'foo', foo => 'bar'}]
28  
29 =head2 Multiline statements are supported.
30  
31 >>> 90 / (
32 ... 4 + 5
33 ... )
34 10
35  
36 =head2 Result could also be multiline
37  
38 >>> [1, 2, 3, {foo => 'bar', bar => 'foo'}]
39 [
40 1, 2, 3,
41 {bar => 'foo', foo => 'bar'}
42 ]
43  
44 =head2 Test::Deep helpers work
45  
46 >>> [1, 2, 3, {foo => 'bar', bar => 'foo'}]
47 [1, 2, 3, ignore]
48  
49 >>> [1, 2, 3]
50 bag(3, 1, 2)
51  
52 =head2 Original Test::Doctest one-line statements are supported too.
53  
54 $ 1 + 1
55 2
56  
57 =head2 Variables that were localized inside pod block...
58  
59 >>> my $foo = 10
60 10
61  
62 ...are local to the end of the block.
63  
64 >>> $foo *= 2
65 20
66  
67 =head2 Variables that were localized inside pod block...
68  
69 ...and to the end of consequent blocks with the same name.
70  
71 >>> $foo *= 2
72 40
73  
74 =head2 But no longer.
75  
76 >>> no strict 'vars'
77 >>> $foo
78 undef
79  
80 =head2 Tests are being run in the package namespace, so you can easily call subs.
81  
82 >>> foo()
83 5
84  
85 =head2 Changing result doesn't break testing
86  
87 >>> my $a = [1, 2, 3]
88 >>> $a
89 [1, 2, 3]
90  
91 >>> push(@$a, 4)
92 >>> $a
93 [1, 2, 3, 4]
94  
95 =cut
96  
97 1 ▶sub foo {
Subroutine foo: called CC=1 SCAR=0.0
Pod undocumented
98 1 return 5;
99 }
100  
101 1 1;
« Doctest.pm ↑ Summary