File Coverage

lib/Test/PerlTidy/XTFiles.pm
Criterion Covered Total %
statement 36 36 100.0
branch 10 10 100.0
condition n/a
subroutine 8 8 100.0
pod 0 1 0.0
total 54 55 98.1


line stmt bran cond sub pod time code
1             package Test::PerlTidy::XTFiles;
2              
3 4     4   425444 use 5.006;
  4         35  
4 4     4   16 use strict;
  4         7  
  4         68  
5 4     4   15 use warnings;
  4         10  
  4         205  
6              
7             our $VERSION = '0.001';
8              
9 4     4   1649 use Class::Tiny 1 qw(perltidyrc mute);
  4         5929  
  4         15  
10              
11 4     4   1090 use Test::Builder ();
  4         7  
  4         45  
12 4     4   1182 use Test::PerlTidy ();
  4         724894  
  4         94  
13 4     4   1596 use Test::XTFiles ();
  4         52752  
  4         632  
14              
15             my $TEST = Test::Builder->new;
16              
17             # - Do not use subtests because subtests cannot be tested with
18             # Test::Builder:Tester.
19             # - Do not use a plan because a method that sets a plan cannot be tested
20             # with Test::Builder:Tester.
21              
22             sub all_files_ok {
23 4     4 0 17650 my ($self) = @_;
24              
25 4         21 my @files = Test::XTFiles->new->all_perl_files;
26 4 100       11383 if ( !@files ) {
27 1         15 $TEST->skip_all("No files found\n");
28 1         12 return 1;
29             }
30              
31 3 100       74 local $Test::PerlTidy::MUTE = $self->mute ? 1 : 0;
32              
33 3 100       56 my @perltidyrc = ( defined $self->perltidyrc ? $self->perltidyrc : () );
34              
35 3         29 my $rc = 1;
36 3         7 for my $file (@files) {
37 6         14 my $tidy = Test::PerlTidy::is_file_tidy( $file, @perltidyrc );
38 6         43 $TEST->ok( $tidy, $file );
39 6 100       1871 if ( !$tidy ) {
40 1         3 $rc = 0;
41             }
42             }
43              
44 3         9 $TEST->done_testing;
45              
46 3 100       18 return 1 if $rc;
47 1         15 return;
48             }
49              
50             1;
51              
52             __END__
53              
54             =pod
55              
56             =encoding UTF-8
57              
58             =head1 NAME
59              
60             Test::PerlTidy::XTFiles - XT::Files interface for Test::PerlTidy
61              
62             =head1 VERSION
63              
64             Version 0.001
65              
66             =head1 SYNOPSIS
67              
68             use Test::PerlTidy::XTFiles;
69             Test::PerlTidy::XTFiles->new->all_files_ok;
70              
71             =head1 DESCRIPTION
72              
73             Adds support for the L<XT::Files> interface to L<Test::PerlTidy>.
74              
75             =head1 USAGE
76              
77             =head2 new( [ ARGS ] )
78              
79             Returns a new C<Test::PerlTidy::XTFiles> instance. C<new> takes an optional
80             hash or list with its arguments.
81              
82             Test::Pod::Links->new(
83             mute => 1,
84             perltidyrc => 'the_perltidyrc_file_to_use',
85             );
86              
87             The following arguments are supported:
88              
89             =head3 mute (optional)
90              
91             By default, L<Test::PerlTidy> will output diagnostics about any errors
92             reported by perltidy, as well as any actual differences found between the
93             pre-tidied and post-tidied files. Set C<mute> to a true value to turn off
94             that diagnostic output.
95              
96             Internally, we set the localized C<$Test::PerlTidy::MUTE> package variable,
97             depending on this value.
98              
99             =head3 perltidyrc (optional)
100              
101             The C<perltidy> argument can be used to specify a specific F<.perltidyrc>
102             config file.
103              
104             =head2 all_file_ok
105              
106             Calls the C<all_perl_files> method of L<Test::XTFiles> to get all the files to
107             be tested. All files will be checked by calling C<is_file_tidy> from
108             L<Test::PerlTidy>.
109              
110             It calls C<done_testing> or C<skip_all> so you can't have already called
111             C<plan>.
112              
113             C<all_files_ok> returns something I<true> if all files test ok and I<false>
114             otherwise.
115              
116             Please see L<XT::Files> for how to configure the files to be checked.
117              
118             =head1 EXAMPLES
119              
120             =head2 Example 1 Default usage
121              
122             Check all the files returned by L<XT::Files> with L<Test::PerlTidy>.
123              
124             use 5.006;
125             use strict;
126             use warnings;
127              
128             use Test::PerlTidy::XTFiles;
129              
130             Test::PerlTidy::XTFiles->new->all_files_ok;
131              
132             =head2 Example 2 Check non-default directories or files
133              
134             Use the same test file as in Example 1 and create a F<.xtfilesrc> config
135             file in the root directory of your distribution.
136              
137             [Dirs]
138             module = lib
139             module = tools
140             module = corpus/hello
141              
142             [Files]
143             module = corpus/world.pm
144              
145             =head1 SEE ALSO
146              
147             L<Test::More>, L<Test::PerlTidy>, L<XT::Files>
148              
149             =head1 SUPPORT
150              
151             =head2 Bugs / Feature Requests
152              
153             Please report any bugs or feature requests through the issue tracker
154             at L<https://github.com/skirmess/Test-PerlTidy-XTFiles/issues>.
155             You will be notified automatically of any progress on your issue.
156              
157             =head2 Source Code
158              
159             This is open source software. The code repository is available for
160             public review and contribution under the terms of the license.
161              
162             L<https://github.com/skirmess/Test-PerlTidy-XTFiles>
163              
164             git clone https://github.com/skirmess/Test-PerlTidy-XTFiles.git
165              
166             =head1 AUTHOR
167              
168             Sven Kirmess <sven.kirmess@kzone.ch>
169              
170             =head1 COPYRIGHT AND LICENSE
171              
172             This software is Copyright (c) 2019 by Sven Kirmess.
173              
174             This is free software, licensed under:
175              
176             The (two-clause) FreeBSD License
177              
178             =cut
179              
180             # vim: ts=4 sts=4 sw=4 et: syntax=perl