script/splitGDRTests.pl untested

filter: Statementstmt 0.0% 0 / 123 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 155 SCAR 6.9
CC
1
Cov
0%
END
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2
3 use strict;
4 use warnings;
5 use Modern::Perl;
6
7 use autodie qw(:all);
8 no indirect ':fatal';
9
10 use 5.010;
11 use version ; our $VERSION = qv('1.0.6');
12
13 use Carp;
14
15 use VSGDR::UnitTest::TestSet::Test;
16 use VSGDR::UnitTest::TestSet::Test::TestCondition;
17 use VSGDR::UnitTest::TestSet::Representation;
18 use VSGDR::UnitTest::TestSet::Resx;
19
20
21 our $opt_version;
22 our $opt_infile;
23 our $opt_outfile;
24
25 use Getopt::Euclid qw( :vars<opt_> );
26 use List::MoreUtils qw{firstidx} ;
27
28 use Data::Dumper;
29 use File::Basename;
30
31 my %ValidParserMakeArgs = ( vb => "NET::VB"
32 , cs => "NET::CS"
33 , xls => "XLS"
34 , xml => "XML"
35 ) ;
36 my %ValidParserMakeArgs2 = ( vb => "NET2::VB"
37 , cs => "NET2::CS"
38 ) ;
39
40 my @validSuffixes = map { '.'.$_ } keys %ValidParserMakeArgs ;
41
42
43 my $version = $opt_version ;
44
45
46 my($infname, $indirectories, $insfx) = fileparse($opt_infile, @validSuffixes);
47 croak 'Invalid input file' unless defined $insfx ;
48 $insfx = lc $insfx ;
49 $insfx = substr(lc $insfx,1) ;
50 my($outfname, $outdirectories, $outsfx) = fileparse($opt_outfile, @validSuffixes);
51 croak 'Invalid output file' unless defined $outsfx ;
52 $outsfx = lc $outsfx ;
53 $outsfx = substr(lc $outsfx,1) ;
54
55 my %Parsers = () ;
56 $Parsers{${insfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${insfx}} } );
57 # if input is in a .net language, add in a .net2 parser to the list
58 if ( firstidx { $_ eq ${insfx} } ['cs','vb'] != -1 ) {
59 $Parsers{"${insfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${insfx}} } );
60 }
61 # if output is needed in ssdt unit test format add in a .net2 parser to the list
62 if ($version == 1) {
63 $Parsers{${outsfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${outsfx}} } );
64 }
65 else {
66 $Parsers{"${outsfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${outsfx}} } );
67 }
68
69 my $testSet = undef ;
70 eval {
71 $testSet = $Parsers{$insfx}->deserialise($opt_infile);
72 } ;
73 if ( not defined $testSet ) {
74 if ( exists $Parsers{"${insfx}2"}) {
75 eval {
76 $testSet = $Parsers{"${insfx}2"}->deserialise($opt_infile);
77 }
78 }
79 else {
80 croak 'Parsing failed.';
81 }
82 }
83
84
85 my $resxname = $infname . ".resx" ;
86 my $o_resx = VSGDR::UnitTest::TestSet::Resx->new() ;
87 $o_resx->deserialise($resxname) ;
88
89 my $rh_testScripts = $o_resx->scripts() ;
90 my $o_resx_clone = $o_resx->clone() ;
91
92 my $testSet_clone = $testSet->clone();
93 $testSet_clone->tests([]);
94 foreach my $test ( @{ $testSet->tests() } ) {
95
96 my $rx_dyn = ${test}->testName() ;
97 my @script_keys = grep { $_ =~ /^ testInitializeAction|testCleanupAction|${rx_dyn}/x ; } keys %{$rh_testScripts} ;
98
99 my %test_testScripts = () ;
100 map { $test_testScripts{$_} = $$rh_testScripts{$_} } @script_keys ;
101
102 $o_resx_clone->scripts(\%test_testScripts) ;
103 $testSet_clone->className($testSet->className() . '_' . $test->testName() ) ;
104 $testSet_clone->tests([$test]) ;
105
106 if ($version == 1) {
107 $Parsers{$outsfx}->serialise($outfname."_".$test->testName().".".$outsfx, $testSet_clone);
108 }
109 else {
110 $Parsers{"${outsfx}2"}->serialise($outfname."_".$test->testName().".".$outsfx, $testSet_clone);
111 }
112
113 $o_resx_clone->serialise( ${outfname}."_".$test->testName().".resx", ${o_resx_clone} );
114
115 }
116
117
118 exit ;
119
120 END {}
121
122 __DATA__