File Coverage

blib/lib/Test/TAPv13.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 46 46 100.0


line stmt bran cond sub pod time code
1 1     1   440 use strict;
  1         2  
  1         97  
2 1     1   5 use warnings;
  1         1  
  1         41  
3             package Test::TAPv13;
4             # git description: v0.001-2-gbb3eefb
5              
6             BEGIN {
7 1     1   23 $Test::TAPv13::AUTHORITY = 'cpan:SCHWIGON';
8             }
9             {
10             $Test::TAPv13::VERSION = '0.002';
11             }
12             # ABSTRACT: provide TAP v13 support to test scripts
13              
14 1     1   4217 use Test::Builder;
  1         21373  
  1         33  
15 1     1   693 use Data::YAML::Writer;
  1         904  
  1         248  
16              
17             sub tap13_version {
18 1     1 1 11 my $out = Test::Builder->new->output;
19 1         774 print $out "TAP version 13\n";
20             }
21              
22             sub tap13_pragma {
23 3     3 1 1841 my ($msg) = @_;
24              
25 3         9 my $tb = Test::Builder->new;
26 3         16 my $out = $tb->output;
27              
28 3         15 print $out $tb->_indent."pragma $msg\n";
29             }
30              
31             sub tap13_yaml {
32 3     3 1 406 my ($data) = @_;
33              
34 3         27 my $writer = Data::YAML::Writer->new;
35 3         14 my $output;
36 3         7 $writer->write($data, \$output);
37              
38 3         624 my $tb = Test::Builder->new;
39 3         18 my $out = $tb->output;
40              
41 3         15 my $indent = $tb->_indent. " ";
42 3         39 $output =~ s/^/$indent/msg;
43 3         31 print $out $output;
44             }
45              
46             sub _installer {
47 1     1   831 &tap13_version;
48 1         22 &Sub::Exporter::default_installer
49             }
50              
51 1         17 use Sub::Exporter { installer => \&Test::TAPv13::_installer },
52             -setup => {
53             exports => [
54             qw( tap13_version
55             tap13_pragma
56             tap13_yaml
57             ),
58             ],
59             groups => {
60             all => [ qw( tap13_version
61             tap13_pragma
62             tap13_yaml
63             )
64             ],
65             },
66 1     1   200072 };
  1         51810  
67              
68             1;
69              
70              
71              
72             =pod
73              
74             =encoding utf-8
75              
76             =head1 NAME
77              
78             Test::TAPv13 - provide TAP v13 support to test scripts
79              
80             =head1 SYNOPSIS
81              
82             use Test::TAPv13 ':all'; # before other Test::* modules
83             use Test::More tests => 2;
84            
85             my $data = { affe => { tiger => 111,
86             birne => "amazing",
87             loewe => [ qw( one two three) ],
88             },
89             zomtec => "here's another one",
90             };
91            
92             ok(1, "hot stuff");
93             tap13_yaml($data);
94             tap13_pragma "+strict";
95             ok(1, "more hot stuff");
96              
97             This would create TAP like this:
98              
99             TAP version 13
100             1..2
101             ok 1 - hot stuff
102             ---
103             affe:
104             birne: amazing
105             loewe:
106             - one
107             - two
108             - three
109             tiger: 111
110             zomtec: 'here''s another one'
111             ...
112             pragma +strict
113             ok 2 - more hot stuff
114              
115             =head2 tap13_yaml($data)
116              
117             For example
118              
119             tap13_yaml($data);
120              
121             prints out an indented YAML block of the data, like this:
122              
123             ---
124             affe:
125             birne: amazing
126             kram:
127             - one
128             - two
129             - three
130             one: 111
131             zomtec: "here's another one"
132             ...
133              
134             To make it meaningful, e.g. in a L, you should do
135             that B an actual test line to which this data block
136             will belong as a child.
137              
138             =head2 tap13_pragma($string)
139              
140             For example
141              
142             tap13_pragma("+strict");
143              
144             prints out a TAP pragma line:
145              
146             pragma +strict
147              
148             You most probably do not want or need this, but anyway, the C<+strict>
149             pragma is part of the TAP v13 specification and makes the TAP parser
150             fail on non-TAP (I) lines.
151              
152             =head2 tap13_version
153              
154             Not to be called directly in your scripts as it is called implicitely
155             as soon you C.
156              
157             Prints out the version statement
158              
159             TAP version 13
160              
161             =head1 ABOUT
162              
163             This module is to utilize TAP version 13 features in your test
164             scripts.
165              
166             TAP, the L, allows
167             some new elements beginning with L
168             13|http://testanything.org/wiki/index.php/TAP_version_13_specification>. The
169             most prominent one is to embed data as indented L
170             blocks|http://testanything.org/wiki/index.php/YAMLish>.
171              
172             This module automatically declares C first in the TAP
173             stream which is needed to tell the TAP::Parser to actually parse those
174             new features. With some utility functions you can then actually
175             include data, etc.
176              
177             =head1 AUTHOR
178              
179             Steffen Schwigon
180              
181             =head1 COPYRIGHT AND LICENSE
182              
183             This software is copyright (c) 2012 by Steffen Schwigon.
184              
185             This is free software; you can redistribute it and/or modify it under
186             the same terms as the Perl 5 programming language system itself.
187              
188             =cut
189              
190              
191             __END__