« lib/VSGDR/UnitTest/TestSet/Resx.pm
↑ Summary
lib/VSGDR/UnitTest/TestSet/Test/TestCondition/ScalarValue.pm »
| 1 | package VSGDR::UnitTest::TestSet::Representation::NET2::VB; | ||
| 2 | |||
| 3 | use 5.010; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | |||
| 8 | #our \$VERSION = '1.00'; | ||
| 9 | |||
| 10 | |||
| 11 | use parent qw(VSGDR::UnitTest::TestSet::Representation::NET2) ; | ||
| 12 | |||
| 13 | #TODO 1. Add support for test method attributes eg new vs2010 exceptions ala : -[ExpectedSqlException(MessageNumber = nnnnn, Severity = x, MatchFirstError = false, State = y)] | ||
| 14 | #TODO 2. Add checking support in the parser, etc that the bits of code we don't care about match our expectations. Otherwise we risk screwing non-standard test classes | ||
| 15 | #TODO 3: If a condition has the same name as a test ( ie like the prefix of a test action, the check to determine resource or test condition fails. We've strengthened it, but it might not ultimately be fixable. | ||
| 16 | #TODO 4: Noticed that VS2010 generated tests update some functions to have empty trailing () as for C#. Need to pick this up as an optional parse element. | ||
| 17 | |||
| 18 | use Data::Dumper ; | ||
| 19 | use Carp ; | ||
| 20 | use Parse::RecDescent; | ||
| 21 | |||
| 22 | use VSGDR::UnitTest::TestSet; | ||
| 23 | use VSGDR::UnitTest::TestSet::Test; | ||
| 24 | use VSGDR::UnitTest::TestSet::Representation; | ||
| 25 | use VSGDR::UnitTest::TestSet::Representation::NET2; | ||
| 26 | |||
| 27 | #my %Globals ; ## temp | ||
| 28 | |||
| 29 | #use Smart::Comments ; | ||
| 30 | |||
| 31 | #use re 'debug'; | ||
| 32 | |||
| 33 | #$::RD_HINT=1; | ||
| 34 | #$::RD_AUTOACTION=q { [@item] }; | ||
| 35 | #$::RD_TRACE = 1; | ||
| 36 | #$::RD_WARN =1; | ||
| 37 | #$::RD_NO_HITEM =1; | ||
| 38 | |||
| 39 | |||
| 40 | |||
| 41 | #$::RD_HINT=1; | ||
| 42 | $::RD_AUTOACTION=q { [@item] }; | ||
| 43 | #$::RD_TRACE = 1; | ||
| 44 | #$::RD_WARN =1; | ||
| 45 | |||
| 46 | my $grammar_pass1 = q{ | ||
| 47 | |||
| 48 | { my %testConditions = () ; | ||
| 49 | my %testConditions_2 = () ; | ||
| 50 | my %resources = () ; | ||
| 51 | $resources{CONDITIONS} = () ; | ||
| 52 | my %TESTACTIONS = () ; | ||
| 53 | my %actions = () ; | ||
| 54 | my %globals = () ; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | start: m{(?>\A.*? (?=Public \s Class) )}sx { %testConditions = () ; | ||
| 59 | %testConditions_2 = () ; | ||
| 60 | %resources = () ; | ||
| 61 | $resources{CONDITIONS} = () ; | ||
| 62 | %TESTACTIONS = () ; | ||
| 63 | %actions = () ; | ||
| 64 | %globals = () ; | ||
| 65 | |||
| 66 | #VSGDR::UnitTest::TestSet::Dump(@_) ; | ||
| 67 | } | ||
| 68 | class | ||
| 69 | |||
| 70 | m{(?>.*?(?=\<TestMethod\(\)\>))}sx | ||
| 71 | |||
| 72 | testmethod(s) | ||
| 73 | |||
| 74 | |||
| 75 | m{ .* (?= \z ) }xsm | ||
| 76 | |||
| 77 | m{ \z }sx { $return = { GLOBALS => \%globals, RESOURCES => \%resources, ACTIONS => \%actions, TESTCONDITIONS => \%testConditions, TESTCONDITIONS_DETAILS => \%testConditions_2, TESTACTIONS => \%TESTACTIONS } ; | ||
| 78 | } | ||
| 79 | |||
| 80 | |||
| 81 | class_name: m{\w++}sx { $globals{CLASSNAME} = $item[1]; $globals{NAMESPACE} = $globals{CLASSNAME} ; $globals{CLEANUPACTION} = 'testCleanupAction'; $globals{INITIALIZEACTION} = 'testInitializeAction' ; | ||
| 82 | [@item] ; | ||
| 83 | } | ||
| 84 | class: /Public Class / class_name | ||
| 85 | |||
| 86 | |||
| 87 | |||
| 88 | testmethodname: m{\w++}sx { $globals{TESTS}{$item[1]}{NAME} = $item[1]; | ||
| 89 | [@item] ; | ||
| 90 | } | ||
| 91 | testdata_name: m{\w++}sx { if ( defined $arg[0] and $arg[0] ne '' ) { $globals{TESTS}{$arg[0]}{ACTION} = $item[1] } ; | ||
| 92 | [@item] ; | ||
| 93 | } | ||
| 94 | |||
| 95 | testdata: /Dim testActions As SqlDatabaseTestActions = Me\./ testdata_name[ $arg[0] ] | ||
| 96 | |||
| 97 | testmethod: /\<TestMethod\(\)\>\s+Public\s+Sub/ testmethodname /\(\)/ testdata[ $item[2][1] ] /.*?(?=(?:\<TestMethod\(\)\>)|(?:End Class))/s | ||
| 98 | |||
| 99 | |||
| 100 | }; | ||
| 101 | |||
| 102 | |||
| 103 | my $grammar_pass2 = q{ | ||
| 104 | |||
| 105 | { my %testConditions = () ; | ||
| 106 | my %testConditions_2 = () ; | ||
| 107 | my %resources = () ; | ||
| 108 | $resources{CONDITIONS} = () ; | ||
| 109 | my %TESTACTIONS = () ; | ||
| 110 | my %actions = () ; | ||
| 111 | my %globals = () ; | ||
| 112 | } | ||
| 113 | |||
| 114 | |||
| 115 | start: m{(?>\A.*? (?=Public \s Class) )}sx { %testConditions = () ; | ||
| 116 | %testConditions_2 = () ; | ||
| 117 | %resources = () ; | ||
| 118 | $resources{CONDITIONS} = () ; | ||
| 119 | %TESTACTIONS = () ; | ||
| 120 | %actions = () ; | ||
| 121 | %globals = %{$arg[0]} ; | ||
| 122 | } | ||
| 123 | class | ||
| 124 | |||
| 125 | # m{(?>.*?(?=\<TestMethod\(\)\>))}sx | ||
| 126 | |||
| 127 | #testmethod(s) | ||
| 128 | |||
| 129 | m{(?> .*? (?:Private \s+ Sub \s+ InitializeComponent\(\) \s+ ) )}sx | ||
| 130 | |||
| 131 | condition_or_testaction(s) | ||
| 132 | |||
| 133 | m{.*?(?=\s*[''])}s | ||
| 134 | |||
| 135 | resource_test_action(s) | ||
| 136 | |||
| 137 | m{ .* (?= \z ) }xsm | ||
| 138 | |||
| 139 | m{ \z }sx { $return = { GLOBALS => \%globals, RESOURCES => \%resources, ACTIONS => \%actions, TESTCONDITIONS => \%testConditions, TESTCONDITIONS_DETAILS => \%testConditions_2, TESTACTIONS => \%TESTACTIONS } ; | ||
| 140 | } | ||
| 141 | |||
| 142 | |||
| 143 | condition_or_testaction: condition | testaction | resourcemanager | ||
| 144 | testaction: /Dim/ m{\w++}sx /As/ /Microsoft\.Data\.Tools\.Schema\.Sql\.UnitTesting\.SqlDatabaseTestAction/ | ||
| 145 | resourcemanager: /Dim/ m{\w++}sx /As/ /System\.ComponentModel\.ComponentResourceManager/ /=/ /New/ /System\.ComponentModel\.ComponentResourceManager\(GetType\(\w++\)\)/ | ||
| 146 | |||
| 147 | |||
| 148 | resource_test_action: resource | test | action | ||
| 149 | |||
| 150 | class_name: m{\w++}sx { $globals{CLASSNAME} = $item[1]; $globals{NAMESPACE} = $globals{CLASSNAME} ; $globals{CLEANUPACTION} = 'testCleanupAction'; $globals{INITIALIZEACTION} = 'testInitializeAction' ; | ||
| 151 | [@item] ; | ||
| 152 | } | ||
| 153 | class: /Public Class / class_name | ||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | testmethodname: m{\w++}sx { $globals{TESTS}{$item[1]}{NAME} = $item[1]; | ||
| 158 | [@item] ; | ||
| 159 | } | ||
| 160 | testdata_name: m{\w++}sx { if ( defined $arg[0] and $arg[0] ne '' ) { $globals{TESTS}{$arg[0]}{ACTION} = $item[1] } ; | ||
| 161 | [@item] ; | ||
| 162 | } | ||
| 163 | |||
| 164 | testdata: /Dim testActions As SqlDatabaseTestActions = Me\./ testdata_name[ $arg[0] ] | ||
| 165 | |||
| 166 | testmethod: /\<TestMethod\(\)\>\s+Public\s+Sub/ testmethodname /\(\)/ testdata[ $item[2][1] ] /.*?(?=(?:\<TestMethod\(\)\>)|(?:#Region "Designer support code"))/s | ||
| 167 | |||
| 168 | |||
| 169 | condition_type: m{\w++}sx | ||
| 170 | condition_name: m{\w++}sx | ||
| 171 | condition: /Dim/ condition_name /As/ /Microsoft\.Data\.Tools\.Schema\.Sql\.UnitTesting\.Conditions\./ condition_type | ||
| 172 | { $testConditions{$item[2][1]} = $item[5][1]; | ||
| 173 | [@item] ; | ||
| 174 | } | ||
| 175 | |||
| 176 | test_comment: m{\s*'[^']*'[^']*['']\s*} | ||
| 177 | testname: m{\w++}sx | ||
| 178 | testproperty: /ColumnNumber|Enabled|ExpectedValue|Name|NullExpected|ResultSet|RowNumber|RowCount|ExecutionTime|Checksum|Verbose/ | ||
| 179 | |||
| 180 | testvalue_string: / (?: \"(?:(?:[\\\\][\"])|(?:[^\"]))*?\" )/x | ||
| 181 | { #VSGDR::UnitTest::TestSet::Dump(@item) ; | ||
| 182 | $item[1] ; | ||
| 183 | } | ||
| 184 | testvalue: testvalue_string | ||
| 185 | | /System\.TimeSpan\.Parse\("[\d:]*"\)/x | ||
| 186 | | /(?: \w+ ) /x | ||
| 187 | |||
| 188 | test_element: testname /\./ testproperty /=/ testvalue | ||
| 189 | { $testConditions_2{$item[1][1]}{$item[3][1]} = $item[5][1]; | ||
| 190 | [@item] ; | ||
| 191 | } | ||
| 192 | test_element: /resources\.ApplyResources\(\w+,/ testvalue_string /\)/ | ||
| 193 | { [@item] ; | ||
| 194 | } | ||
| 195 | test: test_comment test_element(s) | ||
| 196 | |||
| 197 | |||
| 198 | action_comment: m{\s*'[^']*'[^']*['']\s*} | ||
| 199 | action_type: /PosttestAction|PretestAction|TestAction/ | ||
| 200 | action_name: m{\w++}sx | ||
| 201 | action_element: /Me\./ testdata_name /\./ action_type /=/ action_name | ||
| 202 | { $actions{$item[2][1]}{$item[4][1]}=$item[6][1]; | ||
| 203 | my $testAction = $item[2][1] ; | ||
| 204 | my $testActionDataValue = $item[6][1] ; | ||
| 205 | $testActionDataValue =~ s{ _ (?: PosttestAction|PretestAction|TestAction ) }{}x; | ||
| 206 | $TESTACTIONS{$testActionDataValue} = $testAction if $testActionDataValue !~ m{\A nothing \z}ix ; | ||
| 207 | [@item] ; | ||
| 208 | } | ||
| 209 | |||
| 210 | action: action_comment action_element(s) | ||
| 211 | |||
| 212 | resource_comment: m{\s*'[^']*'[^']*['']\s*} | ||
| 213 | resource_name: m{\w++}sx | ||
| 214 | resource_name_string: m{"\w++"}sx | ||
| 215 | resource_element: /resources\.ApplyResources\(/ resource_name /,/ resource_name_string /\)/ | ||
| 216 | |||
| 217 | # reject this parse if it doesn't apply to some testaction resource. | ||
| 218 | # relies on us being able to parse the test name first !!!!!!! | ||
| 219 | # if we don't do this then the test condition resource can get mixed up with it | ||
| 220 | # leading to early parse condition 2 termination | ||
| 221 | # at fault is the optionality of resource_condition below. | ||
| 222 | # viz resource_condition(s?) | ||
| 223 | # | ||
| 224 | # BUT ** If a condition has the same name as a test ( ie like the prefix of a test action, | ||
| 225 | # the check to determine resource or test condition fails. | ||
| 226 | # We've strengthened it, but it might not ultimately be fixable. | ||
| 227 | # A better way may be to check the final element of $item[2][1] | ||
| 228 | # to see if it is TestAction/PretestAction/PostTestaction, AFAIK | ||
| 229 | # this can't be meddled with by the user. However somefool might name a test or | ||
| 230 | # condition TestAction etc, so it still isn't fool-proof in isolation. | ||
| 231 | |||
| 232 | { my $x = $item[2][1] ; | ||
| 233 | $x =~ s/[_][^_]*$// ; | ||
| 234 | #VSGDR::UnitTest::TestSet::Dump(@item) ; | ||
| 235 | #VSGDR::UnitTest::TestSet::Dump($x) ; | ||
| 236 | if ( exists($testConditions{$x}) && ! exists($globals{TESTS}{$x})) { | ||
| 237 | undef ; | ||
| 238 | } | ||
| 239 | else { | ||
| 240 | $resources{$item[2][1]}=1; | ||
| 241 | [@item] ; | ||
| 242 | } | ||
| 243 | } | ||
| 244 | |||
| 245 | resource_condition: resource_name /\.Conditions\.Add\(/ condition_name /\)/ | ||
| 246 | { push (@{$resources{CONDITIONS}{$item[1][1]}},$item[3][1]); | ||
| 247 | [@item] ; | ||
| 248 | } | ||
| 249 | resource: resource_comment resource_condition(s?) resource_element | ||
| 250 | |||
| 251 | }; | ||
| 252 | |||
| 253 | |||
| 254 | sub _init { | ||
| 255 | |||
| 256 | local $_ = undef ; | ||
| 257 | |||
| 258 | my $self = shift ; | ||
| 259 | my $class = ref($self) || $self ; | ||
| 260 | my $ref = shift or croak "no arg"; | ||
| 261 | |||
| 262 | my $parser1 = new Parse::RecDescent($grammar_pass1); | ||
| 263 | my $parser2 = new Parse::RecDescent($grammar_pass2); | ||
| 264 | $self->{PARSER1} = $parser1 ; | ||
| 265 | $self->{PARSER2} = $parser2 ; | ||
| 266 | # $self->{PARSER} = \&VSGDR::UnitTest::TestSet::Representation::NET2::VB ; | ||
| 267 | |||
| 268 | return ; | ||
| 269 | |||
| 270 | } | ||
| 271 | |||
| 272 | sub representationType { | ||
| 273 | local $_ = undef; | ||
| 274 | my $self = shift or croak 'no self'; | ||
| 275 | return 'VB' ; | ||
| 276 | } | ||
| 277 | |||
| 278 | |||
| 279 | # ** ######################################################################################## | ||
| 280 | |||
| 281 | sub trim { | ||
| 282 | local $_ = undef; | ||
| 283 | my $self = shift or croak 'no self'; | ||
| 284 | my $code = shift or croak 'no code' ; | ||
| 285 | # | ||
| 286 | # $code =~ s/\A.*?Public Class/Public Class/ms; | ||
| 287 | $code =~ s{" \s? & \s _\s*"}{}msgx; # join split strings | ||
| 288 | $code =~ s{resources\.GetString\(("[^""]*?")\)}{$1}msgx; # strip out usage of resources.GetString() and just keep the string | ||
| 289 | |||
| 290 | # $code =~ s{ Dim\s+[\w]+\s+As\s+ # strip out variable declarations that we aren't interested in | ||
| 291 | # (?: | ||
| 292 | # (?: Microsoft\.Data\.Schema\.UnitTesting\.DatabaseTestAction) | ||
| 293 | # | (?: System\.ComponentModel\.ComponentResourceManager\s+=\s+New\s+System\.ComponentModel\.ComponentResourceManager\(GetType\([\w]+\)\)) | ||
| 294 | # ) | ||
| 295 | # }{}msgx ; | ||
| 296 | |||
| 297 | # $code =~ s{Microsoft\.Data\.Schema\.UnitTesting\.Conditions} | ||
| 298 | # {MS\.D\.S\.UT\.C}msgx; # shorten file | ||
| 299 | |||
| 300 | |||
| 301 | # $code =~ s/End\sSub\s+#End\sRegion\s+#Region\s"Additional\stest\sattributes".*\z//ms; | ||
| 302 | #warn Dumper $code ; | ||
| 303 | return $code ; | ||
| 304 | } | ||
| 305 | |||
| 306 | # ** ######################################################################################## | ||
| 307 | |||
| 308 | ## -- ** --- | ||
| 309 | |||
| 310 | |||
| 311 | sub declareVariable { | ||
| 312 | local $_ = undef; | ||
| 313 | my $self = shift or croak 'no self' ; | ||
| 314 | my $type = shift or croak 'no type' ; # $condition->conditionName() | ||
| 315 | my $var = shift or croak 'no var' ; # $condition->conditionName() | ||
| 316 | my $res = "" ; | ||
| 317 | $res .= "Dim " . $var . " As " . $type ; | ||
| 318 | return $res; | ||
| 319 | } | ||
| 320 | |||
| 321 | sub declareAndCreateVariable { | ||
| 322 | local $_ = undef; | ||
| 323 | my $self = shift or croak 'no self' ; | ||
| 324 | my $type = shift or croak 'no type' ; | ||
| 325 | my $var = shift or croak 'no var' ; | ||
| 326 | my $constructor = shift or croak 'no $constructor' ; | ||
| 327 | my $res = "" ; | ||
| 328 | $res .= "Dim" . " " . $var . " As " . $type . " = " . $self->newKeyWord() . " " . $constructor ; | ||
| 329 | return $res; | ||
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | |||
| 334 | |||
| 335 | |||
| 336 | # ** #################################################################### | ||
| 337 | |||
| 338 | sub icHeader { | ||
| 339 | |||
| 340 | local $_ = undef; | ||
| 341 | my $self = shift or croak 'no self' ; | ||
| 342 | |||
| 343 | return <<"EOF"; | ||
| 344 | |||
| 345 | #Region "Designer support code" | ||
| 346 | |||
| 347 | 'NOTE: The following procedure is required by the Designer | ||
| 348 | 'It can be modified using the Designer. | ||
| 349 | 'Do not modify it using the code editor. | ||
| 350 | <System.Diagnostics.DebuggerStepThrough()> _ | ||
| 351 | Private Sub InitializeComponent() | ||
| 352 | EOF | ||
| 353 | #' | ||
| 354 | } | ||
| 355 | |||
| 356 | |||
| 357 | sub icFooter { | ||
| 358 | |||
| 359 | local $_ = undef; | ||
| 360 | my $self = shift or croak 'no self' ; | ||
| 361 | |||
| 362 | return <<"EOF"; | ||
| 363 | |||
| 364 | End Sub | ||
| 365 | |||
| 366 | #End Region | ||
| 367 | |||
| 368 | EOF | ||
| 369 | } | ||
| 370 | |||
| 371 | |||
| 372 | |||
| 373 | sub Tests { | ||
| 374 | |||
| 375 | local $_ = undef ; | ||
| 376 | |||
| 377 | my $self = shift or croak 'no self' ; | ||
| 378 | my $ra_tests = shift or croak 'no tests' ; | ||
| 379 | my @tests = @$ra_tests ; | ||
| 380 | |||
| 381 | my $p1 = ' '; | ||
| 382 | my $p2 = ' '; | ||
| 383 | my $p3 = ' '; | ||
| 384 | my $res = "" ; | ||
| 385 | |||
| 386 | foreach my $test ( @tests) { | ||
| 387 | |||
| 388 | $res .= "${p1}<TestMethod()>\n"; | ||
| 389 | $res .= "${p1}Public Sub ".$test->testName()."()\n"; | ||
| 390 | $res .= "${p2}Dim testActions As SqlDatabaseTestActions = Me.".$test->testActionDataName()."\n"; | ||
| 391 | |||
| 392 | $res .= $self->Lang_testsection('pre-test','PretestAction','pretestResults','Executing pre-test script...','PrivilegedContext') ; | ||
| 393 | $res .= $self->Lang_testsection('test','TestAction','testResults','Executing test script...','ExecutionContext') ; | ||
| 394 | $res .= $self->Lang_testsection('post-test','PosttestAction','posttestResults','Executing post-test script...','PrivilegedContext') ; | ||
| 395 | |||
| 396 | $res .= "${p1}End Sub\n"; | ||
| 397 | $res .= "\n"; | ||
| 398 | |||
| 399 | } | ||
| 400 | |||
| 401 | return $res; | ||
| 402 | } | ||
| 403 | |||
| 404 | |||
| 405 | sub Lang_testsection { | ||
| 406 | |||
| 407 | local $_ = undef ; | ||
| 408 | |||
| 409 | my $self = shift or croak 'no self' ; | ||
| 410 | my $arg1 = shift or croak 'no comment'; | ||
| 411 | my $arg2 = shift or croak 'no method'; | ||
| 412 | my $arg3 = shift or croak 'no results'; | ||
| 413 | my $arg4 = shift or croak 'no text'; | ||
| 414 | my $arg5 = shift or croak 'no context'; | ||
| 415 | |||
| 416 | my $p1 = ' '; | ||
| 417 | my $p2 = ' '; | ||
| 418 | my $p3 = ' '; | ||
| 419 | my $res = "" ; | ||
| 420 | |||
| 421 | #print Dumper ${arg2} ; | ||
| 422 | |||
| 423 | $res .= "${p2}'Execute the ${arg1} script\n"; | ||
| 424 | $res .= "${p2}'\n"; | ||
| 425 | |||
| 426 | $res .= "${p2}System.Diagnostics.Trace.WriteLineIf(testActions.".${arg2}." IsNot Nothing, \"${arg4}\")\n"; | ||
| 427 | $res .= "${p2}Dim ".${arg3}."() As SqlExecutionResult = TestService.Execute(Me.".${arg5}.", Me.PrivilegedContext, testActions.".${arg2}.")\n"; | ||
| 428 | |||
| 429 | return $res ; | ||
| 430 | |||
| 431 | } | ||
| 432 | |||
| 433 | # ** ###################################################################################### | ||
| 434 | |||
| 435 | |||
| 436 | sub Header { | ||
| 437 | |||
| 438 | local $_ = undef ; | ||
| 439 | my $self = shift or croak 'no self' ; | ||
| 440 | my $namespace = shift or croak "No namespace supplied" ; | ||
| 441 | my $class = shift or croak "No Class" ; | ||
| 442 | |||
| 443 | |||
| 444 | return <<"EOF"; | ||
| 445 | Imports System | ||
| 446 | Imports System.Collections.Generic | ||
| 447 | Imports System.Text | ||
| 448 | Imports Microsoft.Data.Tools.Schema.Sql.UnitTesting | ||
| 449 | Imports Microsoft.Data.Tools.Schema.Sql.UnitTesting.Conditions | ||
| 450 | Imports Microsoft.VisualStudio.TestTools.UnitTesting | ||
| 451 | |||
| 452 | <TestClass()> | ||
| 453 | Public Class ${class} | ||
| 454 | Inherits SqlDatabaseTestClass | ||
| 455 | |||
| 456 | Sub New() | ||
| 457 | InitializeComponent() | ||
| 458 | End Sub | ||
| 459 | |||
| 460 | <TestInitialize()> | ||
| 461 | Public Sub TestInitialize() | ||
| 462 | InitializeTest() | ||
| 463 | End Sub | ||
| 464 | |||
| 465 | <TestCleanup()> | ||
| 466 | Public Sub TestCleanup() | ||
| 467 | CleanupTest() | ||
| 468 | End Sub | ||
| 469 | |||
| 470 | EOF | ||
| 471 | |||
| 472 | } | ||
| 473 | |||
| 474 | |||
| 475 | sub Footer { | ||
| 476 | |||
| 477 | local $_ = undef ; | ||
| 478 | my $self = shift or croak 'no self' ; | ||
| 479 | my $ra_tests = shift or croak 'no tests' ; | ||
| 480 | my @tests = @$ra_tests ; | ||
| 481 | |||
| 482 | my $p1 = ' '; | ||
| 483 | my $p2 = ' '; | ||
| 484 | my $res = "" ; | ||
| 485 | |||
| 486 | foreach my $test (@tests) { | ||
| 487 | $res .= "${p2}Private " . $test->testActionDataName() . " As SqlDatabaseTestActions\n"; | ||
| 488 | } | ||
| 489 | |||
| 490 | return <<"EOF"; | ||
| 491 | |||
| 492 | #Region "Additional test attributes" | ||
| 493 | ' | ||
| 494 | ' You can use the following additional attributes as you write your tests: | ||
| 495 | ' | ||
| 496 | ' Use ClassInitialize to run code before running the first test in the class | ||
| 497 | ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext) | ||
| 498 | ' End Sub | ||
| 499 | ' | ||
| 500 | ' Use ClassCleanup to run code after all tests in a class have run | ||
| 501 | ' <ClassCleanup()> Public Shared Sub MyClassCleanup() | ||
| 502 | ' End Sub | ||
| 503 | ' | ||
| 504 | #End Region | ||
| 505 | |||
| 506 | ${res} | ||
| 507 | End Class | ||
| 508 | |||
| 509 | EOF | ||
| 510 | #' | ||
| 511 | |||
| 512 | } | ||
| 513 | |||
| 514 | |||
| 515 | sub typeExtractor { | ||
| 516 | my $self = shift or croak 'no self' ; | ||
| 517 | return "GetType" | ||
| 518 | } | ||
| 519 | |||
| 520 | sub newKeyWord { | ||
| 521 | my $self = shift or croak 'no self' ; | ||
| 522 | return "New" ; | ||
| 523 | } | ||
| 524 | sub selfKeyWord { | ||
| 525 | my $self = shift or croak 'no self' ; | ||
| 526 | return "Me" ; | ||
| 527 | } | ||
| 528 | sub functionOpenDelimiter { | ||
| 529 | my $self = shift or croak 'no self' ; | ||
| 530 | return "" ; | ||
| 531 | } | ||
| 532 | sub functionCloseDelimiter { | ||
| 533 | my $self = shift or croak 'no self' ; | ||
| 534 | return "" ; | ||
| 535 | } | ||
| 536 | |||
| 537 | sub functionDelimiters { | ||
| 538 | my $self = shift or croak 'no self' ; | ||
| 539 | return "" ; | ||
| 540 | } | ||
| 541 | sub lineTerminator { | ||
| 542 | my $self = shift or croak 'no self' ; | ||
| 543 | return "" ; | ||
| 544 | } | ||
| 545 | |||
| 546 | sub quoteChars { | ||
| 547 | my $self = shift or croak 'no self' ; | ||
| 548 | return "'" ; | ||
| 549 | } | ||
| 550 | sub true { | ||
| 551 | my $self = shift or croak 'no self' ; | ||
| 552 | return 'True' ; | ||
| 553 | } | ||
| 554 | sub false { | ||
| 555 | my $self = shift or croak 'no self' ; | ||
| 556 | return 'False' ; | ||
| 557 | } | ||
| 558 | sub null { | ||
| 559 | my $self = shift or croak 'no self' ; | ||
| 560 | return 'Nothing' ; | ||
| 561 | } | ||
| 562 | |||
| 563 | sub convertKeyWord { | ||
| 564 | my $self = shift or croak 'no self' ; | ||
| 565 | my $KW = shift ; | ||
| 566 | croak 'No key word' if not defined ($KW) ; | ||
| 567 | |||
| 568 | return 'True' if $KW =~ m{^true$}ix ; | ||
| 569 | return 'False' if $KW =~ m{^false$}ix ; | ||
| 570 | return 'Nothing' if $KW =~ m{^(?:"nothing"|nothing|null)$}ix ; | ||
| 571 | return $KW ; # otherwise | ||
| 572 | |||
| 573 | } | ||
| 574 | |||
| 575 | |||
| 576 | sub start { | ||
| 577 | |||
| 578 | #warn Dumper @_ ; | ||
| 579 | ### Start | ||
| 580 | my $self = shift or croak 'no self' ; | ||
| 581 | my $code = shift ; | ||
| 582 | croak 'no code' if ! defined $code ; | ||
| 583 | |||
| 584 | my %testConditions = () ; | ||
| 585 | my %testConditions_2 = () ; | ||
| 586 | my %resources = () ; | ||
| 587 | keys %resources = 8192 ; | ||
| 588 | $resources{CONDITIONS} = {} ; | ||
| 589 | keys %{$resources{CONDITIONS}} = 8192 ; | ||
| 590 | |||
| 591 | my %actions = () ; | ||
| 592 | my %globals = () ; | ||
| 593 | |||
| 594 | keys %testConditions = 8192 ; | ||
| 595 | keys %testConditions_2 = 8192 ; | ||
| 596 | |||
| 597 | |||
| 598 | |||
| 599 | $code =~ s{(?>\A.*? (?=Public \s Class) )}{}sx ; | ||
| 600 | my $class_name; | ||
| 601 | |||
| 602 | ### ClassName | ||
| 603 | $class_name = $1 if $code =~ m{Public \s Class \s+ (\w++)}sx ; | ||
| 604 | { $globals{CLASSNAME} = $class_name; $globals{NAMESPACE} = $globals{CLASSNAME} ; $globals{CLEANUPACTION} = 'testCleanupAction'; $globals{INITIALIZEACTION} = 'testInitializeAction' ; } | ||
| 605 | |||
| 606 | $code =~ s{(:? .*? (?=\<TestMethod \(\) \> \s*_))}{}sx ; | ||
| 607 | |||
| 608 | ### Strip Methods | ||
| 609 | while ( $code =~ m{ \<TestMethod \(\) \> \s* _ \s+ Public \s+ Sub \s+ (?<testmethodname>\w+) \s* \(\) \s* | ||
| 610 | Dim \s testActions \s As \s SqlDatabaseTestActions \s = \s Me \. (?<testdata_name>\w+) | ||
| 611 | |||
| 612 | .*? (?= (?: (?: \<TestMethod \(\) \> \s* _ ) | ||
| 613 | | (?: \#Region \s "Designer \s support \s code" ) | ||
| 614 | ) | ||
| 615 | ) | ||
| 616 | |||
| 617 | }gcsmx | ||
| 618 | ) { | ||
| 619 | $globals{TESTS}{$+{testmethodname}}{NAME} = $+{testmethodname} ; | ||
| 620 | $globals{TESTS}{$+{testmethodname}}{ACTION} = $+{testdata_name} ; | ||
| 621 | } | ||
| 622 | |||
| 623 | ### Builder | ||
| 624 | |||
| 625 | $code =~ s{(?> .*? (?:Private \s+ Sub \s+ InitializeComponent\(\) \s+ ) )}{}sx ; | ||
| 626 | |||
| 627 | my ($part1,$part2) = ( $1,$2 ) if $code =~ m{ ( .*? ) (?= \s* ['']) (.*) }smx ; | ||
| 628 | |||
| 629 | while ( $part1 =~ | ||
| 630 | m{ Dim \s (?<condition_name>\w++) \s As \s Microsoft\.Data\.Schema\.UnitTesting\.Conditions\. (?<condition_type>\w++) \s* | ||
| 631 | }xmsgc | ||
| 632 | ) | ||
| 633 | { $testConditions{$+{condition_name}} = $+{condition_type}; | ||
| 634 | } | ||
| 635 | |||
| 636 | ### Builder 2 | ||
| 637 | |||
| 638 | my $found = 1 ; | ||
| 639 | while ( $found ) | ||
| 640 | { | ||
| 641 | if ( $part2 =~ m{ \G | ||
| 642 | (?: | ||
| 643 | (?<conditionname>\w++) | ||
| 644 | \. (?<conditiontype>\w++) \s = \s | ||
| 645 | (?<conditionvalue> (?: " .*? " ) | ||
| 646 | | (?: System\.TimeSpan\.Parse\( "[\d:]++" \) ) | ||
| 647 | | (?: \w++ ) | ||
| 648 | ) | ||
| 649 | |||
| 650 | ) ## test condition | ||
| 651 | \s*+ | ||
| 652 | }gcmsx ) | ||
| 653 | |||
| 654 | { $testConditions_2{$+{conditionname}}{$+{conditiontype}} = $+{conditionvalue} ; | ||
| 655 | } | ||
| 656 | elsif ( $part2 =~ m{ \G | ||
| 657 | (?<commentblock> \s*+ '[^']*+ \s*+ '[^']*+ \s*+ ['']\s*+ ) | ||
| 658 | \s*+ | ||
| 659 | #warn "@\n"; | ||
| 660 | #warn $part2 ; | ||
| 661 | #die; | ||
| 662 | |||
| 663 | }gcmsx ) {} | ||
| 664 | elsif ( $part2 =~ m{ \G | ||
| 665 | (?: | ||
| 666 | (?<testname2>\w++) | ||
| 667 | \.Conditions\.Add\( (?<conditionname2>\w++) \) | ||
| 668 | ) ## adding test condition to test action | ||
| 669 | \s*+ | ||
| 670 | }gcmsx ) | ||
| 671 | { unshift (@{$resources{CONDITIONS}{$+{testname2}}},$+{conditionname2}) ; | ||
| 672 | } | ||
| 673 | elsif ( $part2 =~ m{ \G | ||
| 674 | Me \. (?<testname>\w++) | ||
| 675 | \. (?<testactiontype>(?:TestAction|PosttestAction|PretestAction)) \s = \s (?<testaction>\w++) | ||
| 676 | \s*+ | ||
| 677 | }gcmsx ) | ||
| 678 | { $actions{$+{testname}}{$+{testactiontype}} = $+{testaction} ; | ||
| 679 | } | ||
| 680 | elsif ( $part2 =~ m{ \G | ||
| 681 | (?: | ||
| 682 | resources\.ApplyResources\( (?<resourcetestaction>\w++) | ||
| 683 | , \s (?<quotedresourcetestaction>"\w++") \) | ||
| 684 | ) ## end of build-up of test action resources | ||
| 685 | \s*+ | ||
| 686 | }gcmsx ) | ||
| 687 | { unshift (@{$resources{$+{resourcetestaction}}},$+{quotedresourcetestaction}) ; | ||
| 688 | } | ||
| 689 | elsif ( $part2 =~ m{ \G | ||
| 690 | (?: | ||
| 691 | (?<endsub> End \s Sub ) | ||
| 692 | ) | ||
| 693 | }gcmsx ) | ||
| 694 | { $found =0 ; last } | ||
| 695 | |||
| 696 | else { | ||
| 697 | warn "UNMATCHED CODE!\n"; | ||
| 698 | my $first = substr($part2,0,100); | ||
| 699 | warn $first ; | ||
| 700 | die; | ||
| 701 | } | ||
| 702 | } | ||
| 703 | return { GLOBALS => \%globals, RESOURCES => \%resources, ACTIONS => \%actions, TESTCONDITIONS => \%testConditions, TESTCONDITIONS_DETAILS => \%testConditions_2 } ; | ||
| 704 | |||
| 705 | |||
| 706 | }; | ||
| 707 | |||
| 708 | |||
| 709 | |||
| 710 | 1; | ||
| 711 | |||
| 712 | __DATA__ |