| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use autodie qw(:all); | ||
| 6 | no indirect ':fatal'; | ||
| 7 | |||
| 8 | use 5.010; | ||
| 9 | use Carp; | ||
| 10 | |||
| 11 | use Getopt::Euclid qw( :vars<opt_> ); | ||
| 12 | use List::MoreUtils qw{firstidx} ; | ||
| 13 | use version ; our $VERSION = qv('1.0.7'); | ||
| 14 | |||
| 15 | use VSGDR::UnitTest::TestSet::Test; | ||
| 16 | use VSGDR::UnitTest::TestSet::Test::TestCondition; | ||
| 17 | use VSGDR::UnitTest::TestSet::Representation; | ||
| 18 | |||
| 19 | use VSGDR::UnitTest::TestSet::Resx; | ||
| 20 | |||
| 21 | use Data::Dumper; | ||
| 22 | |||
| 23 | use IO::File ; | ||
| 24 | #use Smart::Comments; | ||
| 25 | use File::Basename; | ||
| 26 | |||
| 27 | my %ValidParserMakeArgs = ( vb => "NET::VB" | ||
| 28 | , cs => "NET::CS" | ||
| 29 | , xls => "XLS" | ||
| 30 | , xml => "XML" | ||
| 31 | ) ; | ||
| 32 | my %ValidParserMakeArgs2 = ( vb => "NET2::VB" | ||
| 33 | , cs => "NET2::CS" | ||
| 34 | ) ; | ||
| 35 | |||
| 36 | #my @validSuffixes = keys %ValidParserMakeArgs ; | ||
| 37 | my @validSuffixes = map { '.'.$_ } keys %ValidParserMakeArgs ; | ||
| 38 | |||
| 39 | our $opt_infile; | ||
| 40 | |||
| 41 | croak 'no input file' unless defined($opt_infile) ; | ||
| 42 | my $infile; | ||
| 43 | $infile = $opt_infile; | ||
| 44 | |||
| 45 | my($infname, $directories, $insfx) = fileparse($infile , @validSuffixes); | ||
| 46 | croak 'Invalid input file' unless defined $insfx ; | ||
| 47 | $insfx = lc $insfx ; | ||
| 48 | $insfx = substr $insfx,1; | ||
| 49 | #warn Dumper $insfx; | ||
| 50 | |||
| 51 | ### Validate parameters | ||
| 52 | die 'Invalid input file' unless exists $ValidParserMakeArgs{$insfx} ; | ||
| 53 | |||
| 54 | ### Build parsers | ||
| 55 | |||
| 56 | my %Parsers = () ; | ||
| 57 | $Parsers{${insfx}} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs{${insfx}} } ); | ||
| 58 | # if input is in a .net language, add in a .net2 parser to the list | ||
| 59 | if ( firstidx { $_ eq ${insfx} } ['cs','vb'] != -1 ) { | ||
| 60 | $Parsers{"${insfx}2"} = VSGDR::UnitTest::TestSet::Representation->make( { TYPE => $ValidParserMakeArgs2{${insfx}} } ); | ||
| 61 | } | ||
| 62 | |||
| 63 | ### Deserialise tests | ||
| 64 | my $testSet = undef ; | ||
| 65 | eval { | ||
| 66 | $testSet = $Parsers{$insfx}->deserialise($infile); | ||
| 67 | } ; | ||
| 68 | if ( not defined $testSet ) { | ||
| 69 | if ( exists $Parsers{"${insfx}2"}) { | ||
| 70 | eval { | ||
| 71 | $testSet = $Parsers{"${insfx}2"}->deserialise($infile); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | else { | ||
| 75 | croak 'Parsing failed.'; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | my $resxname = $infname . ".resx" ; | ||
| 81 | my $o_resx = VSGDR::UnitTest::TestSet::Resx->new() ; | ||
| 82 | |||
| 83 | ### Deserialise tests scripts | ||
| 84 | $o_resx->deserialise($resxname) ; | ||
| 85 | my $rh_testScripts = $o_resx->scripts() ; | ||
| 86 | #warn Dumper $rh_testScripts ; | ||
| 87 | #exit ; | ||
| 88 | |||
| 89 | |||
| 90 | foreach my $test_action ( sort keys %{$rh_testScripts} ) { ### Dump test action scripts | ||
| 91 | |||
| 92 | my $file = "${test_action}.sql" ; | ||
| 93 | my $data ; | ||
| 94 | my $fh = IO::File->new("> ${file}") ; | ||
| 95 | |||
| 96 | if (defined ${fh} ) { | ||
| 97 | print {${fh}} $rh_testScripts->{$test_action} ; | ||
| 98 | $fh->close; | ||
| 99 | } | ||
| 100 | else { | ||
| 101 | croak "Unable to write to ${file}."; | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | ### End | ||
| 106 | |||
| 107 | exit ; | ||
| 108 | |||
| 109 | END {} | ||
| 110 | |||
| 111 | |||
| 112 | __END__ |