File Coverage

blib/lib/Test/Dist/Zilla.pm
Criterion Covered Total %
statement 65 65 100.0
branch 6 6 100.0
condition n/a
subroutine 19 19 100.0
pod 1 1 100.0
total 91 91 100.0


line stmt bran cond sub pod time code
1             # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2             #
3             # file: lib/Test/Dist/Zilla.pm
4             #
5             # Copyright © 2015 Van de Bugger
6             #
7             # This file is part of perl-Test-Dist-Zilla.
8             #
9             # perl-Test-Dist-Zilla is free software: you can redistribute it and/or modify it under the terms
10             # of the GNU General Public License as published by the Free Software Foundation, either version
11             # 3 of the License, or (at your option) any later version.
12             #
13             # perl-Test-Dist-Zilla is distributed in the hope that it will be useful, but WITHOUT ANY
14             # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15             # PURPOSE. See the GNU General Public License for more details.
16             #
17             # You should have received a copy of the GNU General Public License along with
18             # perl-Test-Dist-Zilla. If not, see <http://www.gnu.org/licenses/>.
19             #
20             # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21              
22             #pod =head1 SYNOPSIS
23             #pod
24             #pod package Test::Dist::Zilla::Build;
25             #pod
26             #pod use namespace::autoclean;
27             #pod use Test::Routine;
28             #pod use Test::Deep qw{ cmp_deeply };
29             #pod
30             #pod with 'Test::Dist::Zilla';
31             #pod
32             #pod test 'Build' => sub {
33             #pod my ( $self ) = @_;
34             #pod my $expected = $self->expected;
35             #pod $self->build();
36             #pod if ( exists( $expected->{ exception } ) ) {
37             #pod cmp_deeply( $self->exception, $expected->{ exception } );
38             #pod } else {
39             #pod is( $self->exception, undef );
40             #pod };
41             #pod if ( exists( $expected->{ messages } ) ) {
42             #pod cmp_deeply( $self->messages, $expected->{ messages } );
43             #pod };
44             #pod };
45             #pod
46             #pod 1;
47             #pod
48             #pod =head1 DESCRIPTION
49             #pod
50             #pod This is a C<Test::Routine>-based role. It does not provide any test routines, but it establishes
51             #pod infrastructure for writing tests on C<Dist::Zilla> and its plugins. A test written with
52             #pod C<Test::Dist::Zila> does not require external source files (which are usually placed into
53             #pod F<corpus/> directory) — all the source files (including F<dist.ini>) for the test are generated
54             #pod on-the-fly in a temporary directory.
55             #pod
56             #pod The role is not intended to be used directly in tests. Instead, it serves as a base for other more
57             #pod specific roles, for example, C<Test::Dist::Zilla::Build>.
58             #pod
59             #pod =cut
60              
61             package Test::Dist::Zilla;
62              
63 7     7   5980 use namespace::autoclean;
  7         13  
  7         63  
64 7     7   482 use strict;
  7         11  
  7         154  
65 7     7   5238 use utf8;
  7         65  
  7         44  
66 7     7   2842 use version 0.77;
  7         8272  
  7         45  
67 7     7   430 use warnings;
  7         14  
  7         361  
68              
69             # ABSTRACT: Test your Dist::Zilla plugin
70             our $VERSION = 'v0.4.1'; # VERSION
71              
72 7     7   6006 use Dist::Zilla::Tester::DieHard v0.5.0; # Need `release` method.
  7         14672631  
  7         68  
73 7     7   2608 use File::Temp qw{ tempdir };
  7         13  
  7         621  
74 7     7   6695 use Test::DZil qw{ dist_ini };
  7         85916  
  7         63  
75 7     7   1548 use Test::More;
  7         15  
  7         97  
76 7     7   2401 use Test::Routine;
  7         16  
  7         68  
77 7     7   48848 use Try::Tiny;
  7         19  
  7         8447  
78              
79             # REQUIRE: Software::License::Perl_5
80             # REQUIRE: Moose 2.0800
81             # ^ Test will likely fail with older Moose.
82             # Starting from 2.0800 "Roles can now override methods from other roles…".
83              
84             # --------------------------------------------------------------------------------------------------
85              
86             #pod =attr C<dist>
87             #pod
88             #pod Hash of distribution options: C<name>, C<version> C<abstract>, etc. to write to the test's
89             #pod F<dist.ini>. This attribute is passed to C<dist_ini> as C<\%root_config> argument, see
90             #pod L<Test::DZil/"dist_ini">.
91             #pod
92             #pod C<HashRef>. Default value can be overridden by defining C<_build_dist> builder.
93             #pod
94             #pod Examples:
95             #pod
96             #pod sub _build_dist { {
97             #pod name => 'Assa',
98             #pod version => '0.007',
99             #pod author => 'John Doe',
100             #pod ...
101             #pod } };
102             #pod
103             #pod run_me {
104             #pod dist => {
105             #pod name => 'Assa',
106             #pod version => '0.007',
107             #pod author => 'John Doe',
108             #pod ...
109             #pod },
110             #pod ...
111             #pod };
112             #pod
113             #pod TODO: Merge specified keys into default?
114             #pod
115             #pod =cut
116              
117             has dist => (
118             isa => 'HashRef',
119             is => 'ro',
120             lazy => 1,
121             builder => '_build_dist',
122             );
123              
124             sub _build_dist {
125             return {
126 18     18   814 name => 'Dummy',
127             version => '0.003',
128             abstract => 'Dummy abstract',
129             author => 'John Doe',
130             license => 'Perl_5',
131             copyright_holder => 'John Doe',
132             copyright_year => '2007',
133             };
134             };
135              
136             # --------------------------------------------------------------------------------------------------
137              
138             #pod =attr C<plugins>
139             #pod
140             #pod Plugin configuration to write to the test's F<dist.ini>. Attribute is passed to C<dist_ini> as
141             #pod C<@plugins> argument, see L<Test::DZil/"dist_ini">.
142             #pod
143             #pod C<ArrayRef>, optional. Default value is empty array (i. e. no plugins), it can be overridden by
144             #pod defining C<_build_plugins> builder.
145             #pod
146             #pod Examples:
147             #pod
148             #pod sub _build_plugin { [
149             #pod 'GatherDir',
150             #pod 'Manifest',
151             #pod 'MetaJSON',
152             #pod ] };
153             #pod
154             #pod run_me {
155             #pod plugins => [
156             #pod 'GatherDir',
157             #pod [ 'PodWeaver' => {
158             #pod 'replacer' => 'replace_with_comment',
159             #pod } ],
160             #pod ],
161             #pod ...
162             #pod };
163             #pod
164             #pod =cut
165              
166             has plugins => (
167             is => 'ro',
168             isa => 'ArrayRef',
169             lazy => 1,
170             builder => '_build_plugins',
171             );
172              
173             sub _build_plugins {
174 8     8   293 return [];
175             };
176              
177             # --------------------------------------------------------------------------------------------------
178              
179             #pod =attr C<files>
180             #pod
181             #pod Hash of source files to add to the test's distribution source. Keys are file names, values are file
182             #pod contents. A file content may be specified by a (possibly multi-line) string or by array of lines
183             #pod (newlines are optional and will be appended if missed).
184             #pod
185             #pod Note: Explicitly specified F<dist.ini> file overrides C<dist> and C<plugins> attributes.
186             #pod
187             #pod C<HashRef>, optional, default value is empty hash (i. e. no files).
188             #pod
189             #pod Examples:
190             #pod
191             #pod sub _build_files { {
192             #pod 'lib/Assa.pm' => [
193             #pod 'package Assa;',
194             #pod '# VERSION',
195             #pod '1;',
196             #pod ],
197             #pod 'Changes' => "Release history for Dist-Zilla-Plugin-Assa\n\n",
198             #pod 'MANIFEST' => "lib/Assa.pm\nChanges\nMANIFEST\n",
199             #pod } };
200             #pod
201             #pod run_me {
202             #pod files => {
203             #pod 'lib/Assa.pod' => [ ... ],
204             #pod ...
205             #pod },
206             #pod ...
207             #pod };
208             #pod
209             #pod =cut
210              
211             has files => (
212             is => 'ro',
213             isa => 'HashRef[Str|ArrayRef]',
214             lazy => 1,
215             builder => '_build_files',
216             );
217              
218             sub _build_files {
219 8     8   298 return {};
220             };
221              
222             # --------------------------------------------------------------------------------------------------
223              
224             #pod =attr C<tzil>
225             #pod
226             #pod Test-enabled C<Dist::Zilla> instance (or C<DieHard> "survivor" object, if C<Dist::Zilla>
227             #pod constructing fails).
228             #pod
229             #pod By default C<Dist::Zilla> instance is created by calling C<< Builder->from_config( ... ) >> with
230             #pod appropriate arguments. Thanks to C<Dist::Zilla::Tester::DieHard>, it is never dies even if
231             #pod constructing fails, so C<< $self->tzil->log_message >> returns the log messages in anyway.
232             #pod
233             #pod Note: Avoid calling C<build> on C<tzil>:
234             #pod
235             #pod $self->tzil->build();
236             #pod
237             #pod Call C<build> directly on C<$self> instead:
238             #pod
239             #pod $self->build();
240             #pod
241             #pod See C<build> method description for difference.
242             #pod
243             #pod Examples:
244             #pod
245             #pod use Path::Tiny;
246             #pod tests 'Check META.json' => sub {
247             #pod my ( $self ) = @_;
248             #pod if ( $self->exception ) {
249             #pod plan skip_all => 'exception occurred';
250             #pod };
251             #pod my $built_in = path( $self->tzil->built_in );
252             #pod my $json = $built_in->child( 'META.json' )->slurp;
253             #pod cmp_deeply( $json, $self->expected->{ json } );
254             #pod };
255             #pod
256             #pod =cut
257              
258             has tzil => (
259             is => 'ro',
260             isa => 'Object',
261             lazy => 1,
262             builder => '_build_tzil',
263             init_arg => undef,
264             handles => [ qw{ build release } ],
265             );
266              
267             sub _build_tzil {
268 18     18   43 my ( $self ) = @_;
269 18         717 my $files = $self->files;
270             return Builder->from_config(
271             { dist_root => tempdir( CLEANUP => 1 ) },
272             {
273             add_files => {
274             'source/dist.ini' => dist_ini(
275             $self->dist,
276 18         767 @{ $self->plugins },
277             ),
278             map(
279 18         107 { (
280             "source/$_" =>
281             ref ( $files->{ $_ } ) ? (
282             join(
283             '',
284             map(
285 23         78 { ( my $r = $_ ) =~ s{(?<!\n)\z}{\n}x; $r }
  23         111  
286 6         14 @{ $files->{ $_ } }
287             )
288             )
289             ) : (
290 14 100       901 $files->{ $_ }
291             )
292             ) }
293             keys( %$files ),
294             ),
295             },
296             },
297             );
298             };
299              
300             # --------------------------------------------------------------------------------------------------
301              
302             #pod =method C<build>
303             #pod
304             #pod The method calls same-name method on C<tzil>, catches exception if any thrown, and saves the caught
305             #pod exception in C<exception> attribute for further analysis.
306             #pod
307             #pod Avoid calling C<build> on C<tzil> — some tests may rely on C<build> method modifiers, which are
308             #pod applicable to C<< $self->build() >> but not to C<< $self->tzil->build() >>.
309             #pod
310             #pod Examples:
311             #pod
312             #pod test 'Build' => sub {
313             #pod my ( $self ) = @_;
314             #pod $self->build();
315             #pod ...
316             #pod };
317             #pod
318             #pod =cut
319              
320             around [ qw{ build release } ] => sub {
321             my ( $orig, $self, @args ) = @_;
322             my $ret;
323             try {
324             $ret = $self->$orig( @args );
325             } catch {
326             $self->_set_exception( $_ );
327             };
328             return $ret;
329             };
330              
331             # --------------------------------------------------------------------------------------------------
332              
333             #pod =attr C<exception>
334             #pod
335             #pod Exception occurred during build, or C<undef> is no exception were occurred.
336             #pod
337             #pod test 'Post-build' => sub {
338             #pod my ( $self ) = @_;
339             #pod if ( $self->exception ) {
340             #pod plan skip_all => 'exception thrown';
341             #pod };
342             #pod ...
343             #pod };
344             #pod
345             #pod =cut
346              
347             has exception => (
348             is => 'ro',
349             writer => '_set_exception',
350             init_arg => undef,
351             );
352              
353             # --------------------------------------------------------------------------------------------------
354              
355             #pod =attr C<expected>
356             #pod
357             #pod A hash of expected outcomes. C<Test::Dist::Zilla> itself does use this attribute, but more specific
358             #pod roles may do. For example, C<Test::Dizt::Zilla::Build> uses C<exception> and C<messages> keys,
359             #pod C<Test::Dizt::Zilla::BuiltFiles> uses C<files> key.
360             #pod
361             #pod C<HashRef>, required.
362             #pod
363             #pod Examples:
364             #pod
365             #pod run_me {
366             #pod ...,
367             #pod expected => {
368             #pod exception => "Aborting...\n",
369             #pod messages => [
370             #pod '[Plugin] Oops, something goes wrong...',
371             #pod ],
372             #pod },
373             #pod };
374             #pod
375             #pod =cut
376              
377             has expected => (
378             is => 'ro',
379             isa => 'HashRef',
380             required => 1,
381             );
382              
383             # --------------------------------------------------------------------------------------------------
384              
385             #pod =method C<messages>
386             #pod
387             #pod This method is assumed to return C<ArrayRef> of C<Dist::Zilla> log messages. It may be complete log
388             #pod as it is or not — the method may filter out and/or edit actual messages to make them more suitable
389             #pod for comparing with expected messages.
390             #pod
391             #pod Default implementation filters the actual messages with the C<message_filter> (if it is defined).
392             #pod If default behaviour is not suitable, the method can be overridden.
393             #pod
394             #pod Examples:
395             #pod
396             #pod cmp_deeply( $self->messages, $self->expected->{ messages } );
397             #pod
398             #pod =cut
399              
400             sub messages {
401 10     10 1 1414 my ( $self ) = @_;
402 10         23 my @messages = @{ $self->tzil->log_messages };
  10         474  
403 10 100       1341 if ( my $filter = $self->message_filter ) {
404 3         25 @messages = $filter->( @messages );
405             };
406 10         136 return \@messages;
407             };
408              
409             # --------------------------------------------------------------------------------------------------
410              
411             #pod =attr C<message_filter>
412             #pod
413             #pod If C<message_filter> is defined, it is used by the default C<messages> implementation to filter the
414             #pod actual log messages. C<message_filter> function is called once with list of all the log messages.
415             #pod The function is expected to return a list of messages (possibly, grepped and/or edited).
416             #pod
417             #pod Note: C<message_filter> is a function, not method — C<messages> method does not pass C<$self>
418             #pod reference to the C<message_filter>.
419             #pod
420             #pod If C<messages> method is overridden, the attribute may be used or ignored — it depends on new
421             #pod C<messages> implementation.
422             #pod
423             #pod C<Maybe[CodeRef]>, optional. There is no default message filter — C<messages> method returns all
424             #pod the messages intact. Default message filter may be set by defining C<_build_message_filter>
425             #pod builder.
426             #pod
427             #pod Examples:
428             #pod
429             #pod Pass messages only from C<Manifest> plugin and filter out all other messages:
430             #pod
431             #pod sub _build_message_filter {
432             #pod sub { grep( { $_ =~ m{^\[Manifest\] } ) @_ ) };
433             #pod };
434             #pod
435             #pod Drop plugin names from messages:
436             #pod
437             #pod run_me {
438             #pod message_filter => sub { map( { $_ =~ s{^\[.*?\] }{}r ) @_ ) },
439             #pod ...
440             #pod };
441             #pod
442             #pod =cut
443              
444             has message_filter => (
445             is => 'ro',
446             isa => 'Maybe[CodeRef]',
447             lazy => 1,
448             builder => '_build_message_filter',
449             );
450              
451             sub _build_message_filter {
452 7     7   318 return undef; ## no critic ( ProhibitExplicitReturnUndef )
453             };
454              
455             # --------------------------------------------------------------------------------------------------
456              
457             has _annotation => (
458             is => 'ro',
459             isa => 'Str',
460             default => '',
461             );
462              
463             after run_test => sub {
464             my ( $self ) = @_;
465             my $tb = Test::Builder->new();
466             if ( not $tb->is_passing and $self->_annotation ne '' ) {
467             ( my $annotation = $self->_annotation ) =~ s{^}{| }gmx;
468             $tb->diag( $annotation );
469             $self->{ _annotation } = '';
470             };
471             };
472              
473             # --------------------------------------------------------------------------------------------------
474              
475             sub _anno_line {
476 29     29   231 my ( $self, $line ) = @_;
477 29         142 $line =~ s{(?<!\n)\z}{\n}x;
478 29         100 $self->{ _annotation } .= $line;
479 29         75 return;
480             };
481              
482             # --------------------------------------------------------------------------------------------------
483              
484             sub _anno_text {
485 8     8   1957 my ( $self, $heading, @lines ) = @_;
486 8         30 my $width = length( @lines + 0 );
487 8 100       43 if ( @lines ) {
488 6         71 $self->_anno_line( sprintf( '%s:', $heading ) );
489 6         14 my $n = 0;
490 6         22 for my $line ( @lines ) {
491 17         26 ++ $n;
492 17         153 $self->_anno_line( sprintf( " %*d: %s", $width, $n, $line ) );
493             };
494             } else {
495 2         17 $self->_anno_line( sprintf( '%s: %s', $heading, '(empty)' ) );
496             };
497 8         33 return;
498             };
499              
500             # --------------------------------------------------------------------------------------------------
501              
502             1;
503              
504             # --------------------------------------------------------------------------------------------------
505              
506             #pod =head1 SEE ALSO
507             #pod
508             #pod =for :list
509             #pod = L<Test::Dist::Zilla::Build>
510             #pod = L<Test::Routine>
511             #pod = L<Dist::Zilla>
512             #pod = L<Dist::Zilla::Tester::DieHard>
513             #pod = L<Test::DZil/"dist_ini">
514             #pod
515             #pod =head1 COPYRIGHT AND LICENSE
516             #pod
517             #pod Copyright (C) 2015 Van de Bugger
518             #pod
519             #pod License GPLv3+: The GNU General Public License version 3 or later
520             #pod <http://www.gnu.org/licenses/gpl-3.0.txt>.
521             #pod
522             #pod This is free software: you are free to change and redistribute it. There is
523             #pod NO WARRANTY, to the extent permitted by law.
524             #pod
525             #pod
526             #pod =cut
527              
528             # end of file #
529              
530             __END__
531              
532             =pod
533              
534             =encoding UTF-8
535              
536             =head1 NAME
537              
538             Test::Dist::Zilla - Test your Dist::Zilla plugin
539              
540             =head1 VERSION
541              
542             Version v0.4.1, released on 2015-10-29 22:06 UTC.
543              
544             =head1 SYNOPSIS
545              
546             package Test::Dist::Zilla::Build;
547              
548             use namespace::autoclean;
549             use Test::Routine;
550             use Test::Deep qw{ cmp_deeply };
551              
552             with 'Test::Dist::Zilla';
553              
554             test 'Build' => sub {
555             my ( $self ) = @_;
556             my $expected = $self->expected;
557             $self->build();
558             if ( exists( $expected->{ exception } ) ) {
559             cmp_deeply( $self->exception, $expected->{ exception } );
560             } else {
561             is( $self->exception, undef );
562             };
563             if ( exists( $expected->{ messages } ) ) {
564             cmp_deeply( $self->messages, $expected->{ messages } );
565             };
566             };
567              
568             1;
569              
570             =head1 DESCRIPTION
571              
572             This is a C<Test::Routine>-based role. It does not provide any test routines, but it establishes
573             infrastructure for writing tests on C<Dist::Zilla> and its plugins. A test written with
574             C<Test::Dist::Zila> does not require external source files (which are usually placed into
575             F<corpus/> directory) — all the source files (including F<dist.ini>) for the test are generated
576             on-the-fly in a temporary directory.
577              
578             The role is not intended to be used directly in tests. Instead, it serves as a base for other more
579             specific roles, for example, C<Test::Dist::Zilla::Build>.
580              
581             =head1 OBJECT ATTRIBUTES
582              
583             =head2 C<dist>
584              
585             Hash of distribution options: C<name>, C<version> C<abstract>, etc. to write to the test's
586             F<dist.ini>. This attribute is passed to C<dist_ini> as C<\%root_config> argument, see
587             L<Test::DZil/"dist_ini">.
588              
589             C<HashRef>. Default value can be overridden by defining C<_build_dist> builder.
590              
591             Examples:
592              
593             sub _build_dist { {
594             name => 'Assa',
595             version => '0.007',
596             author => 'John Doe',
597             ...
598             } };
599              
600             run_me {
601             dist => {
602             name => 'Assa',
603             version => '0.007',
604             author => 'John Doe',
605             ...
606             },
607             ...
608             };
609              
610             TODO: Merge specified keys into default?
611              
612             =head2 C<plugins>
613              
614             Plugin configuration to write to the test's F<dist.ini>. Attribute is passed to C<dist_ini> as
615             C<@plugins> argument, see L<Test::DZil/"dist_ini">.
616              
617             C<ArrayRef>, optional. Default value is empty array (i. e. no plugins), it can be overridden by
618             defining C<_build_plugins> builder.
619              
620             Examples:
621              
622             sub _build_plugin { [
623             'GatherDir',
624             'Manifest',
625             'MetaJSON',
626             ] };
627              
628             run_me {
629             plugins => [
630             'GatherDir',
631             [ 'PodWeaver' => {
632             'replacer' => 'replace_with_comment',
633             } ],
634             ],
635             ...
636             };
637              
638             =head2 C<files>
639              
640             Hash of source files to add to the test's distribution source. Keys are file names, values are file
641             contents. A file content may be specified by a (possibly multi-line) string or by array of lines
642             (newlines are optional and will be appended if missed).
643              
644             Note: Explicitly specified F<dist.ini> file overrides C<dist> and C<plugins> attributes.
645              
646             C<HashRef>, optional, default value is empty hash (i. e. no files).
647              
648             Examples:
649              
650             sub _build_files { {
651             'lib/Assa.pm' => [
652             'package Assa;',
653             '# VERSION',
654             '1;',
655             ],
656             'Changes' => "Release history for Dist-Zilla-Plugin-Assa\n\n",
657             'MANIFEST' => "lib/Assa.pm\nChanges\nMANIFEST\n",
658             } };
659              
660             run_me {
661             files => {
662             'lib/Assa.pod' => [ ... ],
663             ...
664             },
665             ...
666             };
667              
668             =head2 C<tzil>
669              
670             Test-enabled C<Dist::Zilla> instance (or C<DieHard> "survivor" object, if C<Dist::Zilla>
671             constructing fails).
672              
673             By default C<Dist::Zilla> instance is created by calling C<< Builder->from_config( ... ) >> with
674             appropriate arguments. Thanks to C<Dist::Zilla::Tester::DieHard>, it is never dies even if
675             constructing fails, so C<< $self->tzil->log_message >> returns the log messages in anyway.
676              
677             Note: Avoid calling C<build> on C<tzil>:
678              
679             $self->tzil->build();
680              
681             Call C<build> directly on C<$self> instead:
682              
683             $self->build();
684              
685             See C<build> method description for difference.
686              
687             Examples:
688              
689             use Path::Tiny;
690             tests 'Check META.json' => sub {
691             my ( $self ) = @_;
692             if ( $self->exception ) {
693             plan skip_all => 'exception occurred';
694             };
695             my $built_in = path( $self->tzil->built_in );
696             my $json = $built_in->child( 'META.json' )->slurp;
697             cmp_deeply( $json, $self->expected->{ json } );
698             };
699              
700             =head2 C<exception>
701              
702             Exception occurred during build, or C<undef> is no exception were occurred.
703              
704             test 'Post-build' => sub {
705             my ( $self ) = @_;
706             if ( $self->exception ) {
707             plan skip_all => 'exception thrown';
708             };
709             ...
710             };
711              
712             =head2 C<expected>
713              
714             A hash of expected outcomes. C<Test::Dist::Zilla> itself does use this attribute, but more specific
715             roles may do. For example, C<Test::Dizt::Zilla::Build> uses C<exception> and C<messages> keys,
716             C<Test::Dizt::Zilla::BuiltFiles> uses C<files> key.
717              
718             C<HashRef>, required.
719              
720             Examples:
721              
722             run_me {
723             ...,
724             expected => {
725             exception => "Aborting...\n",
726             messages => [
727             '[Plugin] Oops, something goes wrong...',
728             ],
729             },
730             };
731              
732             =head2 C<message_filter>
733              
734             If C<message_filter> is defined, it is used by the default C<messages> implementation to filter the
735             actual log messages. C<message_filter> function is called once with list of all the log messages.
736             The function is expected to return a list of messages (possibly, grepped and/or edited).
737              
738             Note: C<message_filter> is a function, not method — C<messages> method does not pass C<$self>
739             reference to the C<message_filter>.
740              
741             If C<messages> method is overridden, the attribute may be used or ignored — it depends on new
742             C<messages> implementation.
743              
744             C<Maybe[CodeRef]>, optional. There is no default message filter — C<messages> method returns all
745             the messages intact. Default message filter may be set by defining C<_build_message_filter>
746             builder.
747              
748             Examples:
749              
750             Pass messages only from C<Manifest> plugin and filter out all other messages:
751              
752             sub _build_message_filter {
753             sub { grep( { $_ =~ m{^\[Manifest\] } ) @_ ) };
754             };
755              
756             Drop plugin names from messages:
757              
758             run_me {
759             message_filter => sub { map( { $_ =~ s{^\[.*?\] }{}r ) @_ ) },
760             ...
761             };
762              
763             =head1 OBJECT METHODS
764              
765             =head2 C<build>
766              
767             The method calls same-name method on C<tzil>, catches exception if any thrown, and saves the caught
768             exception in C<exception> attribute for further analysis.
769              
770             Avoid calling C<build> on C<tzil> — some tests may rely on C<build> method modifiers, which are
771             applicable to C<< $self->build() >> but not to C<< $self->tzil->build() >>.
772              
773             Examples:
774              
775             test 'Build' => sub {
776             my ( $self ) = @_;
777             $self->build();
778             ...
779             };
780              
781             =head2 C<messages>
782              
783             This method is assumed to return C<ArrayRef> of C<Dist::Zilla> log messages. It may be complete log
784             as it is or not — the method may filter out and/or edit actual messages to make them more suitable
785             for comparing with expected messages.
786              
787             Default implementation filters the actual messages with the C<message_filter> (if it is defined).
788             If default behaviour is not suitable, the method can be overridden.
789              
790             Examples:
791              
792             cmp_deeply( $self->messages, $self->expected->{ messages } );
793              
794             =head1 SEE ALSO
795              
796             =over 4
797              
798             =item L<Test::Dist::Zilla::Build>
799              
800             =item L<Test::Routine>
801              
802             =item L<Dist::Zilla>
803              
804             =item L<Dist::Zilla::Tester::DieHard>
805              
806             =item L<Test::DZil/"dist_ini">
807              
808             =back
809              
810             =head1 AUTHOR
811              
812             Van de Bugger <van.de.bugger@gmail.com>
813              
814             =head1 COPYRIGHT AND LICENSE
815              
816             Copyright (C) 2015 Van de Bugger
817              
818             License GPLv3+: The GNU General Public License version 3 or later
819             <http://www.gnu.org/licenses/gpl-3.0.txt>.
820              
821             This is free software: you are free to change and redistribute it. There is
822             NO WARRANTY, to the extent permitted by law.
823              
824             =cut