| 1 | #!/usr/bin/perl | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use TAP::Parser; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use TAP::Parser::Aggregator; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use TAP::Formatter::JUnit; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use Getopt::Long; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use Pod::Usage; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use IO::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use File::Slurp qw(slurp); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | ############################################################################### | ||||||||||||||||||||
| 14 | # Read in our command line options. | ||||||||||||||||||||
| 15 | 2 | my ($help, $man); | |||||||||||||||||||
| 16 | 2 | my $name; | |||||||||||||||||||
| 17 | 2 | my $verbose; | |||||||||||||||||||
| 18 | 2 | my $suffix = '.xml'; | |||||||||||||||||||
| 19 | 2 | ▶ | GetOptions( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 'suffix=s' => \$suffix, | ||||||||||||||||||||
| 21 | 'verbose' => \$verbose, | ||||||||||||||||||||
| 22 | 'name|junit_name=s' => \$name, | ||||||||||||||||||||
| 23 | 'help|?' => \$help, | ||||||||||||||||||||
| 24 | 'man' => \$man, | ||||||||||||||||||||
| 25 | ) || pod2usage(1); | ||||||||||||||||||||
| 26 | 2 | ▶ | pod2usage(1) if ($help); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | 2 | ▶ | pod2usage( -exitstatus=>0, -verbose=>2 ) if ($man); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | ############################################################################### | ||||||||||||||||||||
| 30 | # Get the names of all of the TAP files we're supposed to convert. | ||||||||||||||||||||
| 31 | 2 | my @tap_files = @ARGV; | |||||||||||||||||||
| 32 | 2 | ▶ | pod2usage(1) unless (@tap_files); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | ############################################################################### | ||||||||||||||||||||
| 35 | # Convert all of the TAP files to JUnit. | ||||||||||||||||||||
| 36 | 2 | foreach my $file (@tap_files) { | |||||||||||||||||||
| 37 | 2 | verbose( "converting TAP to JUnit: $file" ); | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | # Slurp in the TAP. | ||||||||||||||||||||
| 40 | my $tap = ($file eq '-') | ||||||||||||||||||||
| 41 | 2 | ▶ | ? do { local $/; <STDIN>; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | : slurp($file); | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | # Open up a FH for where we're going to dump the JUnit | ||||||||||||||||||||
| 45 | 2 | my $fout; | |||||||||||||||||||
| 46 | 2 | ▶ | if ($file eq '-') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | 0 | open $fout, '>&STDOUT' | |||||||||||||||||||
| 48 | || die "can't dup STDOUT; $!\n"; | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||
| 51 | 2 | my $junit_file = "${file}${suffix}"; | |||||||||||||||||||
| 52 | 2 | ▶ | $fout = IO::File->new( $junit_file, '>' ) | ||||||||||||||||||
|
Condition50%1/2
'IO::File'->new($junit_file, '>') || die("can't open '${junit_file}' for writing; $!")
MC/DC0%0/1
'IO::File'->new($junit_file, '>') || die("can't open '${junit_file}' for writing; $!")
'IO::File'->new($junit_file, '>')
Truth table50%1/2
A
A= 'IO::File'->new($junit_file, '>')
| |||||||||||||||||||||
| 53 | || die "can't open '$junit_file' for writing; $!"; | ||||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | # Name the test; if one wasn't provided, name it after the file itself. | ||||||||||||||||||||
| 57 | 2 | ▶ | my $test_name = $name || $file; | ||||||||||||||||||
|
Condition66%2/3
$name || $file
MC/DC0%0/2
$name || $file
$name
$file
Truth table66%2/3
A || B
A= $nameB= $file
| |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # Convert the TAP to JUnit | ||||||||||||||||||||
| 60 | 2 | eval { | |||||||||||||||||||
| 61 | # Create the TAP formatter, aggregator, and parser that we're going to | ||||||||||||||||||||
| 62 | # use to convert the TAP to JUnit. | ||||||||||||||||||||
| 63 | 2 | my $formatter = TAP::Formatter::JUnit->new( { stdout => $fout } ); | |||||||||||||||||||
| 64 | 2 | my $aggregator = TAP::Parser::Aggregator->new(); | |||||||||||||||||||
| 65 | 2 | my $parser = TAP::Parser->new( { tap => $tap } ); | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # Parse all of the TAP in this file. | ||||||||||||||||||||
| 68 | 2 | $aggregator->start(); | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 2 | my $session = $formatter->open_test($test_name, $parser); | |||||||||||||||||||
| 71 | 2 | ▶ | while (my $result = $parser->next()) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | 12 | $session->result($result); | |||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 2 | $session->close_test(); | |||||||||||||||||||
| 75 | 2 | $aggregator->add($file, $parser); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 2 | $aggregator->stop(); | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | # Summarize the results (in JUnit) | ||||||||||||||||||||
| 80 | 2 | $formatter->summary; | |||||||||||||||||||
| 81 | }; | ||||||||||||||||||||
| 82 | 2 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 83 | 0 | warn $@; | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 2 | $fout->close(); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | ############################################################################### | ||||||||||||||||||||
| 90 | # All done; exit peacefully. | ||||||||||||||||||||
| 91 | 2 | exit; | |||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | sub verbose { | ||||||||||||||||||||
| 94 | 2 | ▶ | print "$_[0]\n" if ($verbose); | ||||||||||||||||||
|
Subroutine
verbose: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head1 NAME | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | tap2junit - Converts TAP output to JUnit | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =head1 SYNOPSIS | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | tap2junit [options] <filename> <filename> ... | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Options: | ||||||||||||||||||||
| 107 | --suffix <suffix> Suffix for JUnit output files (default ".xml") | ||||||||||||||||||||
| 108 | --verbose Display verbose status during conversion | ||||||||||||||||||||
| 109 | --name <name> Provide explicit name for the JUnit test | ||||||||||||||||||||
| 110 | --help/-? Display brief help message | ||||||||||||||||||||
| 111 | --man Display full documentation | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head1 DESCRIPTION | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | C<tap2junit> converts TAP output to JUnit. | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | Give it a list of files containing TAP results and it will create a series of | ||||||||||||||||||||
| 118 | F<????.junit.xml> output files containing the JUnit representations of that TAP | ||||||||||||||||||||
| 119 | contained in the files. | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | If you specify F<-> as the filename, C<tap2junit> will read from STDIN and write | ||||||||||||||||||||
| 122 | to STDOUT. You may also want to use the C<--name> option to name the test | ||||||||||||||||||||
| 123 | explicitly (as the default name of "-" isn't going to make much sense). | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =head1 OPTIONS | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =over | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =item B<--suffix E<lt>suffixE<gt>> | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | Specifies the suffix which is appended to all of the input files, in order to | ||||||||||||||||||||
| 132 | generate the filename for the JUnit XML file that is being output. | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | If you want to live dangerously and over-write your original TAP files, you can | ||||||||||||||||||||
| 135 | set this to "" and your original TAP files will be over-written. | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Defaults to F<.xml> | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =item B<--verbose> | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | Display verbose status information during the conversion (telling you which TAP | ||||||||||||||||||||
| 142 | file its working on). | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | =item B<--name E<lt>nameE<gt>> | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Specifies an explicit name for the JUnit test. If no name is provided, a | ||||||||||||||||||||
| 147 | default name will be constructed based on the full path of the TAP file being | ||||||||||||||||||||
| 148 | processed. | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | This option has also been aliased as C<--junit_name> to provide compatibility | ||||||||||||||||||||
| 151 | with a patch from Joe McMahon. | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =item B<--help/-?> | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | Display brief help message. | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | =item B<--man> | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | Displays the full documentation. | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | =back | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | =head1 AUTHOR | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | Graham TerMarsch <cpan@howlingfrog.com> | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | =head1 COPYRIGHT | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | Copyright 2008-2010, Graham TerMarsch. All Rights Reserved. | ||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | This is free software; you can redistribute it and/or modify it under the same | ||||||||||||||||||||
| 172 | terms as Perl itself. | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =head1 SEE ALSO | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | L<TAP::Formatter::JUnit>. | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | =cut | ||||||||||||||||||||