lib/VSGDR/UnitTest/disableGDRTestCondition.pl untested

filter: Statementstmt 0.0% 0 / 185 Branchbran 0.0% 0 / 48 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 253 SCAR 6.9
CC
1
Cov
0%
END
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/bin/perl
2  
3 use strict;
4 use warnings;
5 use 5.010;
6  
7 use version ; our $VERSION = qv('1.1.2');
8  
9 use autodie qw(:all);
10 no indirect ':fatal';
11  
12 use Carp;
13  
14 use VSGDR::UnitTest::TestSet::Test;
15 use VSGDR::UnitTest::TestSet::Test::TestCondition;
16 use VSGDR::UnitTest::TestSet::Representation;
17  
18 use VSGDR::UnitTest::TestSet::Resx;
19  
20 use Getopt::Euclid qw( :vars<opt_> );
21 use List::MoreUtils qw{firstidx} ;
22 use Data::Dumper;
23 #use Smart::Comments ;
24 use File::Basename;
25  
26 my %ValidParserMakeArgs = ( vb => "NET::VB"
27 , cs => "NET::CS"
28 , xls => "XLS"
29 , xml => "XML"
30 ) ;
31 my %ValidParserMakeArgs2 = ( vb => "NET2::VB"
32 , cs => "NET2::CS"
33 ) ;
34  
35  
36 ### get and validate parameters
37  
38 our $opt_infile;
39 our $opt_outfile;
40 our $opt_version;
41 our @opt_enable;
42 our @opt_disable;
43  
44  
45 croak 'no input file' unless defined($opt_infile);
46 croak 'no output file' unless defined($opt_outfile);
47  
48 my $version = $opt_version ;
49  
50 my $inFile = $opt_infile ;
51 my $outFile = $opt_outfile ;
52  
53 (my $inpfx = $inFile) =~ s{^(.*)[.][^.]*$}{$1}smx;
54 (my $insfx = $inFile) =~ s/^.*\.//g;
55 croak 'Invalid input file' unless defined $insfx ;
56 $insfx = lc $insfx ;
57  
58 (my $outpfx = $outFile) =~ s{^(.*)[.][^.]*$}{$1}smx;
59 (my $outsfx = $outFile) =~ s/^.*\.//g;
60 croak 'Invalid output file' unless defined $outsfx ;
61 $outsfx = lc $outsfx ;
62  
63 my $outResxFile = "${outpfx}.resx" ;
64  
65 croak 'Invalid input file' unless exists $ValidParserMakeArgs{$insfx} ;
66 croak 'Invalid output file' unless exists $ValidParserMakeArgs{$outsfx} ;
67  
68 ### check output files can be written to
69 # yes so it's a race-condition anyway
70  
71 croak 'Output resource file cannot be written to' unless -f $outResxFile or ! -e $outResxFile ;
72  
73 ### build parsers
74  
75  
76 my %Parsers = () ;
77 $Parsers{${insfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${insfx}} } );
78 # if input is in a .net language, add in a .net2 parser to the list
79 if ( firstidx { $_ eq ${insfx} } ['cs','vb'] != -1 ) {
80 $Parsers{"${insfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${insfx}} } );
81 }
82 # if output is needed in ssdt unit test format add in a .net2 parser to the list
83 if ($version == 1) {
84 $Parsers{${outsfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${outsfx}} } );
85 }
86 else {
87 $Parsers{"${outsfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${outsfx}} } );
88 }
89  
90 ### build internal representations of input
91  
92 my $o_resx = VSGDR::UnitTest::TestSet::Resx->new() ;
93  
94 my $testSet = undef ;
95 eval {
96 $testSet = $Parsers{$insfx}->deserialise($inFile);
97 } ;
98 if ( not defined $testSet ) {
99 if ( exists $Parsers{"${insfx}2"}) {
100 eval {
101 $testSet = $Parsers{$insfx}->deserialise($inFile);
102 }
103 }
104 else {
105 croak 'Parsing failed.';
106 }
107 }
108  
109  
110 my $resx_data = ''; { $/ = undef ; open (my $aa, "<", "${inpfx}.resx"); $resx_data = <$aa> ; close $aa ;} ;
111 my $rh_testScripts = $o_resx->parse($resx_data) ;
112  
113  
114 my $ra_tests = $testSet->tests() ;
115  
116 ### filter input to output
117  
118  
119 my $newTestSet = VSGDR::UnitTest::TestSet->new( { NAMESPACE => $testSet->nameSpace()
120 , CLASSNAME => $testSet->className()
121 }
122 ) ;
123 $newTestSet->initializeConditions($testSet->initializeConditions()) ;
124 $newTestSet->cleanupConditions($testSet->cleanupConditions()) ;
125 $newTestSet->tests($ra_tests) ;
126  
127 foreach my $re ( @opt_enable) {
128 my $qre = qr{$re} ;
129 foreach my $cond ( @{$newTestSet->initializeConditions()} ) {
130 if ($cond->Name() =~ m{$qre} ) {
131 $cond->conditionEnabled('True') ;
132 say STDERR "Enabled @{[ $cond->conditionName() ]}";
133 }
134 }
135 foreach my $cond ( @{$newTestSet->cleanupConditions()} ) {
136 if ($cond->Name() =~ m{$qre} ) {
137 $cond->conditionEnabled('True') ;
138 say STDERR "Enabled @{[ $cond->conditionName() ]}";
139 }
140 }
141 }
142 foreach my $re ( @opt_disable) {
143 my $qre = qr{$re} ;
144 foreach my $cond ( @{$newTestSet->initializeConditions()} ) {
145 if ($cond->Name() =~ m{$qre} ) {
146 $cond->conditionEnabled('False') ;
147 say STDERR "Disabled @{[ $cond->conditionName() ]}";
148 }
149 }
150 foreach my $cond ( @{$newTestSet->cleanupConditions()} ) {
151 if ($cond->Name() =~ m{$qre} ) {
152 $cond->conditionEnabled('False') ;
153 say STDERR "Disabled @{[ $cond->conditionName() ]}";
154 }
155 }
156 }
157  
158 foreach my $test (@{$newTestSet->tests()}) {
159 foreach my $re ( @opt_enable) {
160 my $qre = qr{$re} ;
161 foreach my $cond ( @{$test->preTest_conditions()} ) {
162 if ($cond->conditionName() =~ m{$qre} ) {
163 $cond->conditionEnabled('True') ;
164 say STDERR "Enabled @{[ $cond->conditionName() ]}";
165 }
166 }
167 foreach my $cond ( @{$test->test_conditions()} ) {
168 if ($cond->conditionName() =~ m{$qre} ) {
169 $cond->conditionEnabled('True') ;
170 say STDERR "Enabled @{[ $cond->conditionName() ]}";
171 }
172 }
173 foreach my $cond ( @{$test->postTest_conditions()} ) {
174 if ($cond->conditionName() =~ m{$qre} ) {
175 $cond->conditionEnabled('True') ;
176 say STDERR "Enabled @{[ $cond->conditionName() ]}";
177 }
178 }
179 }
180 foreach my $re ( @opt_disable) {
181 my $qre = qr{$re} ;
182 foreach my $cond ( @{$test->preTest_conditions()} ) {
183 if ($cond->conditionName() =~ m{$qre} ) {
184 $cond->conditionEnabled('False') ;
185 say STDERR "Disabled @{[ $cond->conditionName() ]}";
186 }
187 }
188 foreach my $cond ( @{$test->test_conditions()} ) {
189 if ($cond->conditionName() =~ m{$qre} ) {
190 $cond->conditionEnabled('False') ;
191 say STDERR "Disabled @{[ $cond->conditionName() ]}";
192 }
193 }
194 foreach my $cond ( @{$test->postTest_conditions()} ) {
195 if ($cond->conditionName() =~ m{$qre} ) {
196 $cond->conditionEnabled('False') ;
197 say STDERR "Disabled @{[ $cond->conditionName() ]}";
198 }
199 }
200 }
201 }
202  
203 unlink $outFile if -f $outFile ;
204  
205 if ($version == 1) {
206 $Parsers{$outsfx}->serialise($outFile,$newTestSet);
207 }
208 else {
209 $Parsers{"${outsfx}2"}->serialise($outFile,$newTestSet);
210 }
211  
212  
213 my $o_resx_clone = $o_resx->clone() ;
214 unlink $outResxFile if -f $outResxFile ;
215 $o_resx_clone->serialise($outResxFile,$o_resx_clone);
216  
217 ### end
218  
219 exit ;
220  
221 END {}
222  
223  
224 __END__