| 1 | package TAP::Harness::Archive; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use base 'TAP::Harness'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Cwd (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use File::Basename (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use File::Temp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Path (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use File::Find (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Archive::Tar (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use TAP::Parser (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use YAML::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use TAP::Parser::Aggregator (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | =head1 NAME | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | TAP::Harness::Archive - Create an archive of TAP test results | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 3 | our $VERSION = '0.18'; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | use TAP::Harness::Archive; | ||||||||||||||||||||||||||||
| 27 | my $harness = TAP::Harness::Archive->new(\%args); | ||||||||||||||||||||||||||||
| 28 | $harness->runtests(@tests); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | This module is a direct subclass of L<TAP::Harness> and behaves | ||||||||||||||||||||||||||||
| 33 | in exactly the same way except for one detail. In addition to | ||||||||||||||||||||||||||||
| 34 | outputting a running progress of the tests and an ending summary | ||||||||||||||||||||||||||||
| 35 | it can also capture all of the raw TAP from the individual test | ||||||||||||||||||||||||||||
| 36 | files or streams into an archive file (C<.tar> or C<.tar.gz>). | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | =head1 METHODS | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | All methods are exactly the same as our base L<TAP::Harness> except | ||||||||||||||||||||||||||||
| 41 | for the following. | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =head2 new | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | In addition to the options that L<TAP::Harness> allow to this method, | ||||||||||||||||||||||||||||
| 46 | we also allow the following: | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =over | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =item archive | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | This is the name of the archive file to generate. We use L<Archive::Tar> | ||||||||||||||||||||||||||||
| 53 | in the background so we only support C<.tar> and C<.tar.gz> archive file | ||||||||||||||||||||||||||||
| 54 | formats. This can optionally be an existing directory that will have | ||||||||||||||||||||||||||||
| 55 | the TAP archive's contents deposited therein without any file archiving | ||||||||||||||||||||||||||||
| 56 | (no L<Archive::Tar> involved). | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =item extra_files | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | This is an array reference to extra files that you want to include in the TAP | ||||||||||||||||||||||||||||
| 61 | archive but which are not TAP files themselves. This is useful if you want to | ||||||||||||||||||||||||||||
| 62 | include some log files that contain useful information about the test run. | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =item extra_properties | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | This is a hash reference of extra properties that you've collected during your | ||||||||||||||||||||||||||||
| 67 | test run. Some things you might want to include are the Perl version, the system's | ||||||||||||||||||||||||||||
| 68 | architecture, the operating system, etc. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =back | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =cut | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 3 | my (%ARCHIVE_TYPES, @ARCHIVE_EXTENSIONS); | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 3 | %ARCHIVE_TYPES = ( | |||||||||||||||||||||||||||
| 77 | 'tar' => 'tar', | ||||||||||||||||||||||||||||
| 78 | 'tar.gz' => 'tar.gz', | ||||||||||||||||||||||||||||
| 79 | 'tgz' => 'tar.gz', | ||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||
| 81 | 3 | @ARCHIVE_EXTENSIONS = map { ".$_" } keys %ARCHIVE_TYPES; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=14 SCAR=26.5
Pod
documented
| |||||||||||||||||||||||||||||
| 85 | 7 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 86 | 7 | ▶ | $args ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # these can't be passed on to Test::Harness | ||||||||||||||||||||||||||||
| 89 | 7 | my $archive = delete $args->{archive}; | |||||||||||||||||||||||||||
| 90 | 7 | my $extra_files = delete $args->{extra_files}; | |||||||||||||||||||||||||||
| 91 | 7 | my $extra_props = delete $args->{extra_properties}; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 7 | ▶ | $class->_croak("You must provide the name of the archive to create!") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | unless $archive; | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 6 | my $self = $class->SUPER::new($args); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 6 | ▶ | my $is_directory = -d $archive ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 6 | ▶ | if ($is_directory) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 1 | $self->{__archive_is_directory} = $is_directory; | |||||||||||||||||||||||||||
| 101 | 1 | $self->{__archive_tempdir} = $archive; | |||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 5 | my $format = $class->_get_archive_format_from_filename($archive); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # if it's not a format we understand, or it's not a directory | ||||||||||||||||||||||||||||
| 106 | $class->_croak("Archive is not a known format type!") | ||||||||||||||||||||||||||||
| 107 | 5 | ▶ | unless $format && $ARCHIVE_TYPES{$format}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$format and $ARCHIVE_TYPES{$format}
MC/DC50%1/2
$format and $ARCHIVE_TYPES{$format}
$format
$ARCHIVE_TYPES{$format}
Truth table66%2/3
A and B
A= $formatB= $ARCHIVE_TYPES{$format}
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 4 | $self->{__archive_file} = $archive; | |||||||||||||||||||||||||||
| 110 | 4 | $self->{__archive_format} = $format; | |||||||||||||||||||||||||||
| 111 | 4 | $self->{__archive_tempdir} = File::Temp::tempdir(); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # handle any extra files | ||||||||||||||||||||||||||||
| 115 | 5 | ▶ | if($extra_files) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 1 | ▶ | ref $extra_files eq 'ARRAY' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | or $class->_croak("extra_files must be an array reference!"); | ||||||||||||||||||||||||||||
| 118 | 1 | foreach my $file (@$extra_files) { | |||||||||||||||||||||||||||
| 119 | 3 | ▶ | $class->_croak("extra_file $file does not exist!") unless -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 3 | ▶ | $class->_croak("extra_file $file is not readable!") unless -r $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | 1 | $self->{__archive_extra_files} = $extra_files; | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 5 | ▶ | if($extra_props) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1 | ▶ | ref $extra_props eq 'HASH' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | or $class->_croak("extra_properties must be a hash reference!"); | ||||||||||||||||||||||||||||
| 128 | 1 | $self->{__archive_extra_props} = $extra_props; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 5 | return $self; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 5 | ▶ | sub _get_archive_format_from_filename { | ||||||||||||||||||||||||||
|
Subroutine
_get_archive_format_from_filename: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 135 | 5 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # try to guess it if we don't have one | ||||||||||||||||||||||||||||
| 138 | 5 | my (undef, undef, $suffix) = File::Basename::fileparse($filename, @ARCHIVE_EXTENSIONS); | |||||||||||||||||||||||||||
| 139 | 5 | $suffix =~ s/^\.//; | |||||||||||||||||||||||||||
| 140 | 5 | return $ARCHIVE_TYPES{$suffix}; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head2 runtests | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Takes the same arguments as L<TAP::Harness>'s version and returns the | ||||||||||||||||||||||||||||
| 146 | same thing (a L<TAP::Parser::Aggregator> object). The only difference | ||||||||||||||||||||||||||||
| 147 | is that in addition to the normal test running and progress output | ||||||||||||||||||||||||||||
| 148 | we also create the TAP Archive when it's all done. | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 5 | ▶ | sub runtests { | ||||||||||||||||||||||||||
|
Subroutine
runtests: called CC=15 SCAR=27.5
Pod
documented
| |||||||||||||||||||||||||||||
| 153 | 5 | my ($self, @files) = @_; | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # tell TAP::Harness to put the raw tap someplace we can find it later | ||||||||||||||||||||||||||||
| 156 | 5 | my $dir = $self->{__archive_tempdir}; | |||||||||||||||||||||||||||
| 157 | 5 | $ENV{PERL_TEST_HARNESS_DUMP_TAP} = $dir; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # get some meta information about this run | ||||||||||||||||||||||||||||
| 160 | 5 | my %meta = ( | |||||||||||||||||||||||||||
| 161 | file_order => \@files, | ||||||||||||||||||||||||||||
| 162 | start_time => time(), | ||||||||||||||||||||||||||||
| 163 | ); | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 5 | my $aggregator = $self->SUPER::runtests(@files); | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 5 | $meta{stop_time} = time(); | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 5 | my @parsers = $aggregator->parsers; | |||||||||||||||||||||||||||
| 170 | 5 | ▶ | for ( my $i = 0; $i < @parsers; $i++ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | 10 | $parsers[ $i ] = { | |||||||||||||||||||||||||||
| 172 | start_time => $parsers[ $i ]->start_time, | ||||||||||||||||||||||||||||
| 173 | end_time => $parsers[ $i ]->end_time, | ||||||||||||||||||||||||||||
| 174 | description => $files[ $i ], | ||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | 5 | $meta{file_attributes} = \@parsers; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 5 | my $cwd = Cwd::getcwd(); | |||||||||||||||||||||||||||
| 180 | 5 | my $is_dir = $self->{__archive_is_directory}; | |||||||||||||||||||||||||||
| 181 | 5 | my ($archive, $output_file); | |||||||||||||||||||||||||||
| 182 | 5 | ▶ | if( $is_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 1 | $output_file = $self->{__archive_tempdir}; | |||||||||||||||||||||||||||
| 184 | } else { | ||||||||||||||||||||||||||||
| 185 | 4 | $output_file = $self->{__archive_file}; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | # go into the dir so that we can reference files | ||||||||||||||||||||||||||||
| 188 | # relatively and put them in the archive that way | ||||||||||||||||||||||||||||
| 189 | 4 | ▶ | chdir($dir) or $self->_croak("Could not change to directory $dir: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 4 | ▶ | unless (File::Spec->file_name_is_absolute($output_file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | 0 | $output_file = File::Spec->catfile($cwd, $output_file); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # create the archive | ||||||||||||||||||||||||||||
| 196 | 4 | $archive = Archive::Tar->new(); | |||||||||||||||||||||||||||
| 197 | 4 | $archive->add_files($self->_get_all_tap_files); | |||||||||||||||||||||||||||
| 198 | 4 | ▶ | chdir($cwd) or $self->_croak("Could not return to directory $cwd: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | # add in any extra files | ||||||||||||||||||||||||||||
| 202 | 5 | ▶ | if(my $x_files = $self->{__archive_extra_files}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 1 | my @rel_x_files; | |||||||||||||||||||||||||||
| 204 | 1 | foreach my $x_file (@$x_files) { | |||||||||||||||||||||||||||
| 205 | # handle both relative and absolute file names | ||||||||||||||||||||||||||||
| 206 | 3 | my $rel_file; | |||||||||||||||||||||||||||
| 207 | 3 | ▶ | if( File::Spec->file_name_is_absolute($x_file) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | $rel_file = File::Spec->abs2rel($x_file, $cwd); | |||||||||||||||||||||||||||
| 209 | } else { | ||||||||||||||||||||||||||||
| 210 | 3 | $rel_file = $x_file; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | 3 | push(@rel_x_files, $rel_file); | |||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | 1 | ▶ | $archive->add_files(@rel_x_files) unless $is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | 1 | $meta{extra_files} = \@rel_x_files; | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # add any extra_properties to the meta | ||||||||||||||||||||||||||||
| 219 | 5 | ▶ | if(my $extra_props = $self->{__archive_extra_props}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 1 | $meta{extra_properties} = $extra_props; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # create the YAML meta file | ||||||||||||||||||||||||||||
| 224 | 5 | my $yaml = YAML::Tiny->new(); | |||||||||||||||||||||||||||
| 225 | 5 | $yaml->[0] = \%meta; | |||||||||||||||||||||||||||
| 226 | 5 | ▶ | if( $is_dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 227 | 1 | my $meta_file = File::Spec->catfile($output_file, 'meta.yml'); | |||||||||||||||||||||||||||
| 228 | 1 | ▶ | open(my $out, '>', $meta_file) or die "Could not create meta.yml: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | 1 | print $out $yaml->write_string; | |||||||||||||||||||||||||||
| 230 | 1 | close($out); | |||||||||||||||||||||||||||
| 231 | } else { | ||||||||||||||||||||||||||||
| 232 | 4 | $archive->add_data('meta.yml', $yaml->write_string); | |||||||||||||||||||||||||||
| 233 | 4 | ▶ | $archive->write($output_file, $self->{__archive_format} eq 'tar.gz') or die $archive->error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | # be nice and clean up | ||||||||||||||||||||||||||||
| 235 | 4 | File::Path::rmtree($dir); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 5 | ▶ | print "\nTAP Archive created at $output_file\n" unless $self->verbosity < -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 5 | return $aggregator; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 4 | ▶ | sub _get_all_tap_files { | ||||||||||||||||||||||||||
|
Subroutine
_get_all_tap_files: called CC=4 SCAR=15.7
| |||||||||||||||||||||||||||||
| 244 | 4 | my ($self, $dir, $meta) = @_; | |||||||||||||||||||||||||||
| 245 | 4 | ▶ | $dir ||= $self->{__archive_tempdir}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$dir ||= $self->{"__archive_tempdir"}
MC/DC0%0/2
$dir ||= $self->{"__archive_tempdir"}
$dir
$self->{"__archive_tempdir"}
Truth table33%1/3
A ||= B
A= $dirB= $self->{"__archive_tempdir"}
| |||||||||||||||||||||||||||||
| 246 | 4 | my @files; | |||||||||||||||||||||||||||
| 247 | my %x_files; | ||||||||||||||||||||||||||||
| 248 | 4 | ▶ | if($meta && $meta->{extra_files}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$meta and $meta->{"extra_files"}
MC/DC0%0/2
$meta and $meta->{"extra_files"}
$meta
$meta->{"extra_files"}
Truth table33%1/3
A and B
A= $metaB= $meta->{"extra_files"}
| |||||||||||||||||||||||||||||
| 249 | 0 | %x_files = map { $_ => 1 } @{$meta->{extra_files}}; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | File::Find::find( | ||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||
| 254 | no_chdir => 1, | ||||||||||||||||||||||||||||
| 255 | 16 | ▶ | wanted => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||
| 256 | 16 | ▶ | return if /^\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 16 | ▶ | return if -d; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 8 | my $rel_name = File::Spec->abs2rel($_, $dir); | |||||||||||||||||||||||||||
| 259 | 8 | ▶ | return if $rel_name eq 'meta.yml'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 260 | 8 | ▶ | push(@files, $rel_name) unless $x_files{$rel_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | }, | ||||||||||||||||||||||||||||
| 262 | }, | ||||||||||||||||||||||||||||
| 263 | 4 | $dir | |||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||
| 265 | 4 | return @files; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | =head2 aggregator_from_archive | ||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | This class method will return a L<TAP::Parser::Aggregator> object | ||||||||||||||||||||||||||||
| 271 | when given a TAP Archive to open and parse. It's pretty much the reverse | ||||||||||||||||||||||||||||
| 272 | of creating a TAP Archive from using C<new> and C<runtests>. | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | It takes a hash of arguments which are as follows: | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | =over | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | =item archive | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | The path to the archive file. This can also be a directory if you created | ||||||||||||||||||||||||||||
| 281 | the archive as a directory. This is required. | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =item parser_callbacks | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | This is a hash ref containing callbacks for the L<TAP::Parser> objects | ||||||||||||||||||||||||||||
| 286 | that are created while parsing the TAP files. See the L<TAP::Parser> | ||||||||||||||||||||||||||||
| 287 | documentation for details about these callbacks. | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | =item made_parser_callback | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | This callback is executed every time a new L<TAP::Parser> object | ||||||||||||||||||||||||||||
| 292 | is created. It will be passed the new parser object, the name | ||||||||||||||||||||||||||||
| 293 | of the file to be parsed, and also the full (temporary) path of that file. | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | =item meta_yaml_callback | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | This is a subroutine that will be called if we find and parse a YAML | ||||||||||||||||||||||||||||
| 298 | file containing meta information about the test run in the archive. | ||||||||||||||||||||||||||||
| 299 | The structure of the YAML file will be passed in as an argument. | ||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | =back | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | my $aggregator = TAP::Harness::Archive->aggregator_from_archive( | ||||||||||||||||||||||||||||
| 304 | { | ||||||||||||||||||||||||||||
| 305 | archive => 'my_tests.tar.gz', | ||||||||||||||||||||||||||||
| 306 | parser_callbacks => { | ||||||||||||||||||||||||||||
| 307 | plan => sub { warn "Nice to see you plan ahead..." }, | ||||||||||||||||||||||||||||
| 308 | unknown => sub { warn "Your TAP is bad!" }, | ||||||||||||||||||||||||||||
| 309 | }, | ||||||||||||||||||||||||||||
| 310 | made_parser_callback => sub { | ||||||||||||||||||||||||||||
| 311 | my ($parser, $file, $full_path) = @_; | ||||||||||||||||||||||||||||
| 312 | warn "$file is temporarily located at $full_path\n"; | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | ); | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | 5 | ▶ | sub aggregator_from_archive { | ||||||||||||||||||||||||||
|
Subroutine
aggregator_from_archive: called CC=20 SCAR=32.9
Pod
documented
| |||||||||||||||||||||||||||||
| 321 | 5 | my ($class, $args) = @_; | |||||||||||||||||||||||||||
| 322 | 5 | my $meta; | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | my $file = Cwd::abs_path( $args->{archive} ) | ||||||||||||||||||||||||||||
| 325 | 5 | ▶ | or $class->_croak("You must provide the path to the archive!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 5 | my $is_directory = -d $file; | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | # extract the files out into a temporary directory | ||||||||||||||||||||||||||||
| 330 | 5 | ▶ | my $dir = $is_directory ? $file : File::Temp::tempdir(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 5 | my $cwd = Cwd::getcwd(); | |||||||||||||||||||||||||||
| 332 | 5 | ▶ | chdir($dir) or $class->_croak("Could not change to directory $dir: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 5 | my @files; | |||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||
| 335 | 5 | ▶ | Archive::Tar->new()->extract_archive($file) unless $is_directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 336 | 5 | my @tap_files; | |||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | # do we have a meta.yml file in the archive? | ||||||||||||||||||||||||||||
| 339 | 5 | my $yaml_file = File::Spec->catfile($dir, 'meta.yml'); | |||||||||||||||||||||||||||
| 340 | 5 | ▶ | if( -e $yaml_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | # parse it into a structure | ||||||||||||||||||||||||||||
| 343 | 5 | ▶ | if ($YAML::Tiny::VERSION < 1.57) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 0 | $meta = YAML::Tiny->new()->read($yaml_file); | |||||||||||||||||||||||||||
| 345 | 0 | ▶ | die "Could not read YAML $yaml_file: " . YAML::Tiny->errstr if YAML::Tiny->errstr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | } else { | ||||||||||||||||||||||||||||
| 347 | 5 | $meta = eval { | |||||||||||||||||||||||||||
| 348 | 5 | YAML::Tiny->new()->read($yaml_file); | |||||||||||||||||||||||||||
| 349 | }; | ||||||||||||||||||||||||||||
| 350 | 5 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 351 | 0 | die "Could not read YAML $yaml_file: ".$@; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | 5 | ▶ | if($args->{meta_yaml_callback}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 5 | $args->{meta_yaml_callback}->($meta); | |||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||
| 358 | 5 | $meta = $meta->[0]; | |||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 5 | ▶ | if($meta->{file_order} && ref $meta->{file_order} eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$meta->{"file_order"} and ref $meta->{"file_order"} eq "ARRAY"
MC/DC0%0/2
$meta->{"file_order"} and ref $meta->{"file_order"} eq "ARRAY"
$meta->{"file_order"}
ref $meta->{"file_order"} eq "ARRAY"
Truth table33%1/3
A and B
A= $meta->{"file_order"}B= ref $meta->{"file_order"} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 361 | 5 | foreach my $file (@{$meta->{file_order}}) { | |||||||||||||||||||||||||||
| 362 | 10 | ▶ | push(@tap_files, $file) if -e $file; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # if we didn't get the files from the YAML file, just find them all | ||||||||||||||||||||||||||||
| 368 | 5 | ▶ | unless(@tap_files) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | @tap_files = $class->_get_all_tap_files($dir, $meta); | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | # now create the aggregator | ||||||||||||||||||||||||||||
| 373 | 5 | my $aggregator = TAP::Parser::Aggregator->new(); | |||||||||||||||||||||||||||
| 374 | 5 | foreach my $tap_file (@tap_files) { | |||||||||||||||||||||||||||
| 375 | 10 | ▶ | open(my $fh, $tap_file) or die "Could not open $tap_file for reading: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 376 | 10 | my $parser = TAP::Parser->new({source => $fh, callbacks => $args->{parser_callbacks}}); | |||||||||||||||||||||||||||
| 377 | 10 | ▶ | if($args->{made_parser_callback}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | 6 | $args->{made_parser_callback}->($parser, $tap_file, File::Spec->catfile($dir, $tap_file)); | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | 10 | $parser->run; | |||||||||||||||||||||||||||
| 381 | 10 | $aggregator->add($tap_file, $parser); | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | # be nice and clean up | ||||||||||||||||||||||||||||
| 385 | 5 | ▶ | chdir($cwd) or $class->_croak("Could not return to directory $cwd: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 386 | 5 | ▶ | File::Path::rmtree($dir) unless $is_directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 5 | return $aggregator; | |||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||
| 391 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | Michael Peters, C<< <mpeters at plusthree.com> >> | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | =head1 BUGS | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 398 | C<bug-tap-harness-archive at rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 399 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=TAP-Harness-Archive>. | ||||||||||||||||||||||||||||
| 400 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 401 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||
| 405 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | perldoc TAP::Harness::Archive | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | You can also look for information at: | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | =over 4 | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | L<http://annocpan.org/dist/TAP-Harness-Archive> | ||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||
| 417 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | L<http://cpanratings.perl.org/d/TAP-Harness-Archive> | ||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||
| 421 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=TAP-Harness-Archive> | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | L<http://search.cpan.org/dist/TAP-Harness-Archive> | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | =back | ||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||
| 433 | =over | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | =item * A big thanks to Plus Three, LP (L<http://www.plusthree.com>) for sponsoring my work on this module and other open source pursuits. | ||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||
| 437 | =item * Andy Armstrong | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | =back | ||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | Copyright 2007 Michael Peters, all rights reserved. | ||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 446 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | =cut | ||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||
| 450 | 3 | 1; # End of TAP::Harness::Archive | |||||||||||||||||||||||||||