| 1 | #!/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Modern::Perl; | ||
| 6 | use autodie qw(:all); | ||
| 7 | no indirect ':fatal'; | ||
| 8 | use 5.010; | ||
| 9 | |||
| 10 | use version ; our $VERSION = qv('1.0.5'); | ||
| 11 | |||
| 12 | use Carp; | ||
| 13 | |||
| 14 | our $opt_version; | ||
| 15 | our $opt_infile; | ||
| 16 | our $opt_outfile; | ||
| 17 | |||
| 18 | use Getopt::Euclid qw{:vars<opt_>}; | ||
| 19 | use File::Basename; | ||
| 20 | use List::MoreUtils qw{firstidx} ; | ||
| 21 | use Try::Tiny; | ||
| 22 | |||
| 23 | use VSGDR::UnitTest::TestSet::Test; | ||
| 24 | use VSGDR::UnitTest::TestSet::Test::TestCondition; | ||
| 25 | use VSGDR::UnitTest::TestSet::Representation; | ||
| 26 | use VSGDR::UnitTest::TestSet::Resx; | ||
| 27 | |||
| 28 | use Data::Dumper; | ||
| 29 | |||
| 30 | my %ValidParserMakeArgs = ( vb => "NET::VB" | ||
| 31 | , cs => "NET::CS" | ||
| 32 | , xls => "XLS" | ||
| 33 | , xml => "XML" | ||
| 34 | ) ; | ||
| 35 | my %ValidParserMakeArgs2 = ( vb => "NET2::VB" | ||
| 36 | , cs => "NET2::CS" | ||
| 37 | ) ; | ||
| 38 | |||
| 39 | my @validSuffixes = map { '.'.$_ } keys %ValidParserMakeArgs ; | ||
| 40 | |||
| 41 | |||
| 42 | my $version = $opt_version ; | ||
| 43 | |||
| 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 | |||
| 51 | my($outfname, $outdirectories, $outsfx) = fileparse($opt_outfile, @validSuffixes); | ||
| 52 | croak 'Invalid output file' unless defined $outsfx ; | ||
| 53 | $outsfx = lc $outsfx ; | ||
| 54 | $outsfx = substr(lc $outsfx,1) ; | ||
| 55 | |||
| 56 | croak 'Invalid input file' unless exists $ValidParserMakeArgs{$insfx} ; | ||
| 57 | croak 'Invalid output file' unless exists $ValidParserMakeArgs{$outsfx} ; | ||
| 58 | |||
| 59 | my %Parsers = () ; | ||
| 60 | $Parsers{${insfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${insfx}} } ); | ||
| 61 | # if input is in a .net language, add in a .net2 parser to the list | ||
| 62 | if ( firstidx { $_ eq ${insfx} } ['cs','vb'] != -1 ) { | ||
| 63 | warn 'doing it'; | ||
| 64 | $Parsers{"${insfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${insfx}} } ); | ||
| 65 | } | ||
| 66 | # if output is needed in ssdt unit test format add in a .net2 parser to the list | ||
| 67 | if ($version == 1) { | ||
| 68 | $Parsers{${outsfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${outsfx}} } ); | ||
| 69 | } | ||
| 70 | else { | ||
| 71 | $Parsers{"${outsfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${outsfx}} } ); | ||
| 72 | } | ||
| 73 | |||
| 74 | my $testSet = undef ; | ||
| 75 | |||
| 76 | eval { | ||
| 77 | $testSet = $Parsers{$insfx}->deserialise($opt_infile); | ||
| 78 | } ; | ||
| 79 | if ( not defined $testSet ) { | ||
| 80 | if ( exists $Parsers{"${insfx}2"}) { | ||
| 81 | eval { | ||
| 82 | $testSet = $Parsers{"${insfx}2"}->deserialise($opt_infile); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | else { | ||
| 86 | croak 'Parsing failed.'; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | unlink $opt_outfile if -f $opt_outfile ; | ||
| 92 | |||
| 93 | if ($version == 1) { | ||
| 94 | $Parsers{$outsfx}->serialise($opt_outfile,$testSet); | ||
| 95 | } | ||
| 96 | else { | ||
| 97 | $Parsers{"${outsfx}2"}->serialise($opt_outfile,$testSet); | ||
| 98 | } | ||
| 99 | |||
| 100 | exit ; | ||
| 101 | |||
| 102 | END {} | ||
| 103 | |||
| 104 | __END__ |