« lib/Perl/ToPerl6/Transformer/BasicTypes/Strings/Interpolation.pm
↑ Summary
lib/Perl/ToPerl6/Transformer/ModuleSpecific/Moose.pm »
| 1 | package Perl::ToPerl6::TestUtils; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 11 | ▶ | use 5.006001; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 11 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 11 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 11 | ▶ | use English qw(-no_match_vars); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 11 | ▶ | use Readonly; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 11 | ▶ | use Exporter 'import'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 11 | ▶ | use File::Path (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 11 | ▶ | use File::Spec (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 11 | ▶ | use File::Spec::Unix (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | 11 | ▶ | use File::Temp (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 11 | ▶ | use File::Find qw( find ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 11 | ▶ | use Perl::ToPerl6; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 11 | ▶ | use Perl::ToPerl6::Config; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 11 | ▶ | use Perl::ToPerl6::Exception::Fatal::Generic qw{ &throw_generic }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 11 | ▶ | use Perl::ToPerl6::Exception::Fatal::Internal qw{ &throw_internal }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | 11 | ▶ | use Perl::ToPerl6::Utils qw{ :severities :data_conversion transformer_long_name }; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 11 | ▶ | use Perl::ToPerl6::TransformerFactory (-test => 1); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 11 | Readonly::Array our @EXPORT_OK => qw( | |||||||||||||||||||
| 26 | ptransform ptransform_with_transformations | ||||||||||||||||||||
| 27 | transform transform_with_transformations | ||||||||||||||||||||
| 28 | ftransform ftransform_with_transformations | ||||||||||||||||||||
| 29 | subtests_in_tree | ||||||||||||||||||||
| 30 | should_skip_author_tests | ||||||||||||||||||||
| 31 | get_author_test_skip_message | ||||||||||||||||||||
| 32 | starting_points_including_examples | ||||||||||||||||||||
| 33 | bundled_transformer_names | ||||||||||||||||||||
| 34 | names_of_transformers_willing_to_work | ||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 38 | # If the user already has an existing perlmogrifyrc file, it will get | ||||||||||||||||||||
| 39 | # in the way of these test. This little tweak to ensures that we | ||||||||||||||||||||
| 40 | # don't find the perlmogrifyrc file. | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 11 | ▶ | sub block_perlmogrifyrc { | ||||||||||||||||||
|
Subroutine
block_perlmogrifyrc: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 43 | 11 | ▶ | no warnings 'redefine'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 44 | 11 | ▶ | *Perl::ToPerl6::UserProfile::_find_profile_path = sub { return }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | 11 | return 1; | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 49 | # ToPerl6 a code snippet using only one transformer. Returns the transformations. | ||||||||||||||||||||
| 50 | # | ||||||||||||||||||||
| 51 | # Also uses a secret escape hatch in $c->transform() so we can get at the | ||||||||||||||||||||
| 52 | # raw PPI::Document object without breaking AUTOLOAD. | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | sub ptransform_with_transformations { | ||||||||||||||||||
|
Subroutine
ptransform_with_transformations: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 55 | 0 | my($transformer, $code_ref, $config_ref) = @_; | |||||||||||||||||||
| 56 | 0 | my $c = Perl::ToPerl6->new( -profile => 'NONE' ); | |||||||||||||||||||
| 57 | 0 | $c->apply_transform(-transformer => $transformer, -config => $config_ref); | |||||||||||||||||||
| 58 | 0 | my $doc; | |||||||||||||||||||
| 59 | 0 | $code_ref = \join("\n",@{$code_ref}); | |||||||||||||||||||
| 60 | 0 | my @rv = $c->transform($code_ref, doc => \$doc); | |||||||||||||||||||
| 61 | 0 | return ($doc, @rv); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 65 | # Mogrifyize a code snippet using only one transformer. Returns the number | ||||||||||||||||||||
| 66 | # of transformations | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | ▶ | sub ptransform { ##no mogrify(ArgUnpacking) | ||||||||||||||||||
|
Subroutine
ptransform: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 69 | 0 | return scalar ptransform_with_transformations(@_); | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 73 | # Mogrifyize a code snippet using a specified config. Returns the transformations. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | ▶ | sub transform_with_transformations { | ||||||||||||||||||
|
Subroutine
transform_with_transformations: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 76 | 0 | my ($code_ref, $config_ref) = @_; | |||||||||||||||||||
| 77 | 0 | my $c = Perl::ToPerl6->new( %{$config_ref} ); | |||||||||||||||||||
| 78 | 0 | return $c->transform($code_ref); | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 82 | # Mogrifyize a code snippet using a specified config. Returns the | ||||||||||||||||||||
| 83 | # number of transformations | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 0 | ▶ | sub transform { ##no mogrify(ArgUnpacking) | ||||||||||||||||||
|
Subroutine
transform: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 86 | 0 | return scalar transform_with_transformations(@_); | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 90 | # Like ptransform_with_transformations, but forces a PPI::Document::File context. | ||||||||||||||||||||
| 91 | # The $filename arg is a Unix-style relative path, like 'Foo/Bar.pm' | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 11 | Readonly::Scalar my $TEMP_FILE_PERMISSIONS => oct 700; | |||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 0 | ▶ | sub ftransform_with_transformations { | ||||||||||||||||||
|
Subroutine
ftransform_with_transformations: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 96 | 0 | my($transformer, $code_ref, $filename, $config_ref) = @_; | |||||||||||||||||||
| 97 | 0 | my $c = Perl::ToPerl6->new( -profile => 'NONE' ); | |||||||||||||||||||
| 98 | 0 | $c->apply_transform(-transformer => $transformer, -config => $config_ref); | |||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | my $dir = File::Temp::tempdir( 'PerlMogrify-tmpXXXXXX', TMPDIR => 1 ); | |||||||||||||||||||
| 101 | 0 | ▶ | $filename ||= 'Temp.pm'; | ||||||||||||||||||
|
Condition0%0/2
$filename ||= "Temp.pm"
MC/DC0%0/1
$filename ||= "Temp.pm"
$filename
Truth table0%0/2
A
A= $filename
| |||||||||||||||||||||
| 102 | 0 | my @fileparts = File::Spec::Unix->splitdir($filename); | |||||||||||||||||||
| 103 | 0 | ▶ | if (@fileparts > 1) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 104 | 0 | my $subdir = File::Spec->catdir($dir, @fileparts[0..$#fileparts-1]); | |||||||||||||||||||
| 105 | 0 | File::Path::mkpath($subdir, 0, $TEMP_FILE_PERMISSIONS); | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | 0 | my $file = File::Spec->catfile($dir, @fileparts); | |||||||||||||||||||
| 108 | 0 | ▶ | if (open my $fh, '>', $file) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 109 | 0 | print {$fh} ${$code_ref}; | |||||||||||||||||||
| 110 | 0 | ▶ | close $fh or throw_generic "unable to close $file: $OS_ERROR"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 111 | } | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | # Use eval so we can clean up before throwing an exception in case of | ||||||||||||||||||||
| 114 | # error. | ||||||||||||||||||||
| 115 | 0 | my @v = eval {$c->transform($file)}; | |||||||||||||||||||
| 116 | 0 | my $err = $EVAL_ERROR; | |||||||||||||||||||
| 117 | 0 | File::Path::rmtree($dir, 0, 1); | |||||||||||||||||||
| 118 | 0 | ▶ | if ($err) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 119 | 0 | throw_generic $err; | |||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | 0 | return @v; | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | #----------------------------------------------------------------------------- | ||||||||||||||||||||
| 125 | # Like ptransform, but forces a PPI::Document::File context. The | ||||||||||||||||||||
| 126 | # $filename arg is a Unix-style relative path, like 'Foo/Bar.pm' | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | 0 | ▶ | sub ftransform { ##no mogrify(ArgUnpacking) | ||||||||||||||||||
|
Subroutine
ftransform: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 129 | 0 | return scalar ftransform_with_transformations(@_); | |||||||||||||||||||
| 130 | } | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | # Note: $include_extras is not documented in the POD because I'm not | ||||||||||||||||||||
| 133 | # committing to the interface yet. | ||||||||||||||||||||
| 134 | 0 | ▶ | sub subtests_in_tree { | ||||||||||||||||||
|
Subroutine
subtests_in_tree: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 135 | 0 | my ($start, $include_extras) = @_; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | my %subtests; | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | find( | ||||||||||||||||||||
| 140 | { | ||||||||||||||||||||
| 141 | 0 | ▶ | wanted => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||
| 142 | 0 | ▶ | return if not -f; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | my ($fileroot) = m{(.+)[.]run\z}xms; | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | 0 | ▶ | return if not $fileroot; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | 0 | my @pathparts = File::Spec->splitdir($fileroot); | |||||||||||||||||||
| 149 | 0 | ▶ | if (@pathparts < 2) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 150 | 0 | throw_internal 'confusing transformer test filename ' . $_; | |||||||||||||||||||
| 151 | } | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | # my $transformer = join q{::}, @pathparts[-2, -1]; | ||||||||||||||||||||
| 154 | 0 | my @remaining_path = @pathparts; | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 0 | ▶ | shift @remaining_path if $remaining_path[0] eq 't'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 157 | 0 | ▶ | shift @remaining_path if $remaining_path[0] eq 'Perl'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 158 | 0 | ▶ | shift @remaining_path if $remaining_path[0] eq 'ToPerl6'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | 0 | my $transformer = join q{::}, @remaining_path; | |||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | 0 | my $globals = _globals_from_file( $_ ); | |||||||||||||||||||
| 162 | 0 | ▶ | if ( my $prerequisites = $globals->{prerequisites} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | 0 | foreach my $prerequisite ( keys %{$prerequisites} ) { | |||||||||||||||||||
| 164 | 0 | ▶ | eval "require $prerequisite; 1" or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | 0 | my @subtests = _subtests_from_file( $_ ); | |||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | ▶ | if ($include_extras) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 171 | 0 | $subtests{$transformer} = | |||||||||||||||||||
| 172 | { subtests => [ @subtests ], globals => $globals }; | ||||||||||||||||||||
| 173 | } | ||||||||||||||||||||
| 174 | else { | ||||||||||||||||||||
| 175 | 0 | $subtests{$transformer} = [ @subtests ]; | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | 0 | return; | |||||||||||||||||||
| 179 | }, | ||||||||||||||||||||
| 180 | 0 | no_chdir => 1, | |||||||||||||||||||
| 181 | }, | ||||||||||||||||||||
| 182 | $start | ||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 0 | return \%subtests; | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | # Answer whether author test should be run. | ||||||||||||||||||||
| 189 | # | ||||||||||||||||||||
| 190 | # Note: this code is duplicated in | ||||||||||||||||||||
| 191 | # t/tlib/Perl/ToPerl6/TestUtilitiesWithMinimalDependencies.pm. | ||||||||||||||||||||
| 192 | # If you change this here, make sure to change it there. | ||||||||||||||||||||
| 193 | |||||||||||||||||||||
| 194 | 0 | ▶ | sub should_skip_author_tests { | ||||||||||||||||||
|
Subroutine
should_skip_author_tests: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 195 | return not $ENV{TEST_AUTHOR_PERL_MOGRIFY} | ||||||||||||||||||||
| 196 | 0 | } | |||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | 0 | ▶ | sub get_author_test_skip_message { | ||||||||||||||||||
|
Subroutine
get_author_test_skip_message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 199 | 0 | return 'Author test. Set $ENV{TEST_AUTHOR_PERL_MOGRIFY} to a true value to run.'; | |||||||||||||||||||
| 200 | } | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | 0 | ▶ | sub starting_points_including_examples { | ||||||||||||||||||
|
Subroutine
starting_points_including_examples: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 204 | 0 | ▶ | return (-e 'blib' ? 'blib' : 'lib', 'examples'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 205 | } | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 0 | ▶ | sub _globals_from_file { | ||||||||||||||||||
|
Subroutine
_globals_from_file: not called CC=9 SCAR=45.0
| |||||||||||||||||||||
| 208 | 0 | my $test_file = shift; | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 0 | my %valid_keys = hashify qw< prerequisites >; | |||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | 0 | ▶ | return if -z $test_file; # Skip if the Transformer has a regular .t file. | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | 0 | my %globals; | |||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | ▶ | open my $handle, '<', $test_file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 217 | or throw_internal "Couldn't open $test_file: $OS_ERROR"; | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | 0 | ▶ | while ( my $line = <$handle> ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 220 | 0 | chomp; | |||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | 0 | ▶ | if ( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 223 | my ($key,$value) = | ||||||||||||||||||||
| 224 | $line =~ m<\A [#][#] [ ] global [ ] (\S+) (?:\s+(.+))? >xms | ||||||||||||||||||||
| 225 | ) { | ||||||||||||||||||||
| 226 | 0 | ▶ | next if not $key; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 227 | 0 | ▶ | if ( not $valid_keys{$key} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 228 | 0 | throw_internal "Unknown global key $key in $test_file"; | |||||||||||||||||||
| 229 | } | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | 0 | ▶ | if ( $key eq 'prerequisites' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 232 | 0 | $value = { hashify( words_from_string($value) ) }; | |||||||||||||||||||
| 233 | } | ||||||||||||||||||||
| 234 | 0 | $globals{$key} = $value; | |||||||||||||||||||
| 235 | } | ||||||||||||||||||||
| 236 | } | ||||||||||||||||||||
| 237 | 0 | ▶ | close $handle or throw_generic "unable to close $test_file: $OS_ERROR"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | 0 | return \%globals; | |||||||||||||||||||
| 240 | } | ||||||||||||||||||||
| 241 | |||||||||||||||||||||
| 242 | # The internal representation of a subtest is just a hash with some | ||||||||||||||||||||
| 243 | # named keys. It could be an object with accessors for safety's sake, | ||||||||||||||||||||
| 244 | # but at this point I don't see why. | ||||||||||||||||||||
| 245 | 0 | ▶ | sub _subtests_from_file { | ||||||||||||||||||
|
Subroutine
_subtests_from_file: not called CC=19 SCAR=59.4
| |||||||||||||||||||||
| 246 | 0 | my $test_file = shift; | |||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | 0 | my %valid_keys = hashify qw( name failures parms TODO error filename optional_modules ); | |||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | 0 | ▶ | return if -z $test_file; # Skip if the Transformer has a regular .t file. | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 251 | |||||||||||||||||||||
| 252 | 0 | ▶ | open my $fh, '<', $test_file | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 253 | or throw_internal "Couldn't open $test_file: $OS_ERROR"; | ||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | 0 | my @subtests; | |||||||||||||||||||
| 256 | |||||||||||||||||||||
| 257 | 0 | my $incode = 0; | |||||||||||||||||||
| 258 | 0 | my $cut_in_code = 0; | |||||||||||||||||||
| 259 | 0 | my $subtest; | |||||||||||||||||||
| 260 | my $lineno; | ||||||||||||||||||||
| 261 | 0 | ▶ | while ( <$fh> ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 262 | 0 | ++$lineno; | |||||||||||||||||||
| 263 | 0 | chomp; | |||||||||||||||||||
| 264 | 0 | my $inheader = /^## name/ .. /^## cut/; | |||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | 0 | my $line = $_; | |||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | 0 | ▶ | if ( $inheader ) { | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 269 | 0 | ▶ | $line =~ m/\A [#]/xms or throw_internal "Code before cut: $test_file"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 270 | 0 | my ($key,$value) = $line =~ m/\A [#][#] [ ] (\S+) (?:\s+(.+))? /xms; | |||||||||||||||||||
| 271 | 0 | ▶ | next if !$key; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 272 | 0 | ▶ | next if $key eq 'cut'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 273 | 0 | ▶ | if ( not $valid_keys{$key} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 274 | 0 | throw_internal "Unknown key $key in $test_file"; | |||||||||||||||||||
| 275 | } | ||||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | 0 | ▶ | if ( $key eq 'name' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 278 | 0 | ▶ | if ( $subtest ) { # Stash any current subtest | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 279 | 0 | push @subtests, _finalize_subtest( $subtest ); | |||||||||||||||||||
| 280 | 0 | undef $subtest; | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | 0 | $subtest->{lineno} = $lineno; | |||||||||||||||||||
| 283 | 0 | $incode = 0; | |||||||||||||||||||
| 284 | 0 | $cut_in_code = 0; | |||||||||||||||||||
| 285 | } | ||||||||||||||||||||
| 286 | 0 | ▶ | if ($incode) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 287 | 0 | throw_internal "Header line found while still in code: $test_file"; | |||||||||||||||||||
| 288 | } | ||||||||||||||||||||
| 289 | 0 | $subtest->{$key} = $value; | |||||||||||||||||||
| 290 | } | ||||||||||||||||||||
| 291 | elsif ( $subtest ) { | ||||||||||||||||||||
| 292 | 0 | $incode = 1; | |||||||||||||||||||
| 293 | 0 | ▶ | $cut_in_code ||= $line =~ m/ \A [#][#] [ ] cut \z /smx; | ||||||||||||||||||
|
Condition0%0/3
$cut_in_code ||= $line =~ / \A [#][#] [ ] cut \z /msx
MC/DC0%0/2
$cut_in_code ||= $line =~ / \A [#][#] [ ] cut \z /msx
$cut_in_code
$line =~ / \A [#][#] [ ] cut \z /msx
Truth table0%0/3
A ||= B
A= $cut_in_codeB= $line =~ / \A [#][#] [ ] cut \z /msx
| |||||||||||||||||||||
| 294 | # Don't start a subtest if we're not in one. | ||||||||||||||||||||
| 295 | # Don't add to the test if we have seen a '## cut'. | ||||||||||||||||||||
| 296 | 0 | ▶ | $cut_in_code or push @{$subtest->{code}}, $line; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 297 | } | ||||||||||||||||||||
| 298 | elsif (@subtests) { | ||||||||||||||||||||
| 299 | ## don't complain if we have not yet hit the first test | ||||||||||||||||||||
| 300 | 0 | throw_internal "Got some code but I'm not in a subtest: $test_file"; | |||||||||||||||||||
| 301 | } | ||||||||||||||||||||
| 302 | } | ||||||||||||||||||||
| 303 | 0 | ▶ | close $fh or throw_generic "unable to close $test_file: $OS_ERROR"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 304 | 0 | ▶ | if ( $subtest ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 305 | 0 | ▶ | if ( $incode ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 306 | 0 | push @subtests, _finalize_subtest( $subtest ); | |||||||||||||||||||
| 307 | } | ||||||||||||||||||||
| 308 | else { | ||||||||||||||||||||
| 309 | 0 | throw_internal "Incomplete subtest in $test_file"; | |||||||||||||||||||
| 310 | } | ||||||||||||||||||||
| 311 | } | ||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | 0 | return @subtests; | |||||||||||||||||||
| 314 | } | ||||||||||||||||||||
| 315 | |||||||||||||||||||||
| 316 | 0 | ▶ | sub _split_subtest { | ||||||||||||||||||
|
Subroutine
_split_subtest: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 317 | 0 | my $code = shift; | |||||||||||||||||||
| 318 | |||||||||||||||||||||
| 319 | 0 | my (@original, @sample); | |||||||||||||||||||
| 320 | 0 | my $original_done; | |||||||||||||||||||
| 321 | 0 | for ( @{ $code } ) { | |||||||||||||||||||
| 322 | 0 | ▶ | if ( /^#-->/ ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 323 | 0 | $original_done = 1; | |||||||||||||||||||
| 324 | 0 | next; | |||||||||||||||||||
| 325 | } | ||||||||||||||||||||
| 326 | elsif ( $original_done ) { | ||||||||||||||||||||
| 327 | 0 | push @sample, $_; | |||||||||||||||||||
| 328 | } | ||||||||||||||||||||
| 329 | else { | ||||||||||||||||||||
| 330 | 0 | push @original, $_; | |||||||||||||||||||
| 331 | } | ||||||||||||||||||||
| 332 | } | ||||||||||||||||||||
| 333 | 0 | return (\@original, \@sample); | |||||||||||||||||||
| 334 | } | ||||||||||||||||||||
| 335 | |||||||||||||||||||||
| 336 | 0 | ▶ | sub _finalize_subtest { | ||||||||||||||||||
|
Subroutine
_finalize_subtest: not called CC=9 SCAR=45.0
| |||||||||||||||||||||
| 337 | 0 | my $subtest = shift; | |||||||||||||||||||
| 338 | |||||||||||||||||||||
| 339 | 0 | ▶ | if ( $subtest->{code} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 340 | 0 | my $code = delete $subtest->{code}; | |||||||||||||||||||
| 341 | 0 | @{$subtest}{qw(original sample)} = _split_subtest($code); | |||||||||||||||||||
| 342 | 0 | delete $subtest->{code}; | |||||||||||||||||||
| 343 | } | ||||||||||||||||||||
| 344 | else { | ||||||||||||||||||||
| 345 | 0 | throw_internal "$subtest->{name} has no code lines"; | |||||||||||||||||||
| 346 | } | ||||||||||||||||||||
| 347 | 0 | ▶ | if ( !defined $subtest->{failures} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 348 | 0 | throw_internal "$subtest->{name} does not specify failures"; | |||||||||||||||||||
| 349 | } | ||||||||||||||||||||
| 350 | 0 | ▶ | if ($subtest->{parms}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 351 | 0 | $subtest->{parms} = eval $subtest->{parms}; | |||||||||||||||||||
| 352 | 0 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 353 | 0 | throw_internal | |||||||||||||||||||
| 354 | "$subtest->{name} has an error in the 'parms' property:\n" | ||||||||||||||||||||
| 355 | . $EVAL_ERROR; | ||||||||||||||||||||
| 356 | } | ||||||||||||||||||||
| 357 | 0 | ▶ | if ('HASH' ne ref $subtest->{parms}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 358 | 0 | throw_internal | |||||||||||||||||||
| 359 | "$subtest->{name} 'parms' did not evaluate to a hashref"; | ||||||||||||||||||||
| 360 | } | ||||||||||||||||||||
| 361 | } else { | ||||||||||||||||||||
| 362 | 0 | $subtest->{parms} = {}; | |||||||||||||||||||
| 363 | } | ||||||||||||||||||||
| 364 | |||||||||||||||||||||
| 365 | 0 | ▶ | if (defined $subtest->{error}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 366 | 0 | ▶ | if ( $subtest->{error} =~ m{ \A / (.*) / \z }xms) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 367 | 0 | $subtest->{error} = eval {qr/$1/}; | |||||||||||||||||||
| 368 | 0 | ▶ | if ($EVAL_ERROR) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 369 | 0 | throw_internal | |||||||||||||||||||
| 370 | "$subtest->{name} 'error' has a malformed regular expression"; | ||||||||||||||||||||
| 371 | } | ||||||||||||||||||||
| 372 | } | ||||||||||||||||||||
| 373 | } | ||||||||||||||||||||
| 374 | |||||||||||||||||||||
| 375 | 0 | return $subtest; | |||||||||||||||||||
| 376 | } | ||||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | 5 | ▶ | sub bundled_transformer_names { | ||||||||||||||||||
|
Subroutine
bundled_transformer_names: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 379 | 5 | require ExtUtils::Manifest; | |||||||||||||||||||
| 380 | 5 | my $manifest = ExtUtils::Manifest::maniread(); | |||||||||||||||||||
| 381 | 5 | my @transformer_paths = map {m{\A lib/(Perl/ToPerl6/Transformer/.*).pm \z}xms} keys %{$manifest}; | |||||||||||||||||||
| 382 | 5 | my @transformers = map { join q{::}, split m{/}xms } @transformer_paths; | |||||||||||||||||||
| 383 | 5 | my @sorted_transformers = sort @transformers; | |||||||||||||||||||
| 384 | 5 | return @sorted_transformers; | |||||||||||||||||||
| 385 | } | ||||||||||||||||||||
| 386 | |||||||||||||||||||||
| 387 | 1 | ▶ | sub names_of_transformers_willing_to_work { | ||||||||||||||||||
|
Subroutine
names_of_transformers_willing_to_work: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 388 | 1 | my %configuration = @_; | |||||||||||||||||||
| 389 | |||||||||||||||||||||
| 390 | 1 | my @transformers_willing_to_work = | |||||||||||||||||||
| 391 | Perl::ToPerl6::Config | ||||||||||||||||||||
| 392 | ->new( %configuration ) | ||||||||||||||||||||
| 393 | ->transformers(); | ||||||||||||||||||||
| 394 | |||||||||||||||||||||
| 395 | 1 | return map { ref } @transformers_willing_to_work; | |||||||||||||||||||
| 396 | } | ||||||||||||||||||||
| 397 | |||||||||||||||||||||
| 398 | 11 | 1; | |||||||||||||||||||
| 399 | |||||||||||||||||||||
| 400 | __END__ | ||||||||||||||||||||