Index: trunk/phase3/tests/testHelpers.inc |
— | — | @@ -365,6 +365,10 @@ |
366 | 366 | function readNextTest() { |
367 | 367 | $this->clearSection(); |
368 | 368 | |
| 369 | + # Create a fake parser tests which never run anything unless |
| 370 | + # asked to do so. This will avoid running hooks for a disabled test |
| 371 | + $delayedParserTest = new DelayedParserTest(); |
| 372 | + |
369 | 373 | while ( false !== ( $line = fgets( $this->fh ) ) ) { |
370 | 374 | $this->lineNum++; |
371 | 375 | $matches = array(); |
— | — | @@ -390,9 +394,7 @@ |
391 | 395 | $line = trim( $line ); |
392 | 396 | |
393 | 397 | if ( $line ) { |
394 | | - if ( !$this->parserTest->requireHook( $line ) ) { |
395 | | - return false; |
396 | | - } |
| 398 | + $delayedParserTest->requireHook( $line ); |
397 | 399 | } |
398 | 400 | } |
399 | 401 | |
— | — | @@ -408,9 +410,7 @@ |
409 | 411 | $line = trim( $line ); |
410 | 412 | |
411 | 413 | if ( $line ) { |
412 | | - if ( !$this->parserTest->requireFunctionHook( $line ) ) { |
413 | | - return false; |
414 | | - } |
| 414 | + $delayedParserTest->requireFunctionHook( $line ); |
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
— | — | @@ -437,9 +437,20 @@ |
438 | 438 | # disabled test |
439 | 439 | $this->clearSection(); |
440 | 440 | |
| 441 | + # Forget any pending hooks call since test is disabled |
| 442 | + $delayedParserTest->reset(); |
| 443 | + |
441 | 444 | continue; |
442 | 445 | } |
443 | 446 | |
| 447 | + # We are really going to run the test, run pending hooks and hooks function |
| 448 | + wfDebug( __METHOD__ . " unleashing delayed test for: {$this->sectionData['test']}" ); |
| 449 | + $hooksResult = $delayedParserTest->unleash( $this->parserTest ); |
| 450 | + if( !$hooksResult ) { |
| 451 | + # Some hook reported an issue. Abort. |
| 452 | + return false; |
| 453 | + } |
| 454 | + |
444 | 455 | $this->test = array( |
445 | 456 | 'test' => ParserTest::chomp( $this->sectionData['test'] ), |
446 | 457 | 'input' => ParserTest::chomp( $this->sectionData['input'] ), |
— | — | @@ -503,3 +514,69 @@ |
504 | 515 | return true; |
505 | 516 | } |
506 | 517 | } |
| 518 | + |
| 519 | + |
| 520 | +/** |
| 521 | + * A class to delay execution of a parser test hooks. |
| 522 | + * |
| 523 | + */ |
| 524 | +class DelayedParserTest { |
| 525 | + |
| 526 | + /** Initialized on construction */ |
| 527 | + private $hooks; |
| 528 | + private $fnHooks; |
| 529 | + |
| 530 | + public function __construct() { |
| 531 | + $this->reset(); |
| 532 | + } |
| 533 | + |
| 534 | + /** |
| 535 | + * Init/reset or forgot about the current delayed test. |
| 536 | + * Call to this will erase any hooks function that were pending. |
| 537 | + */ |
| 538 | + public function reset() { |
| 539 | + $this->hooks = array(); |
| 540 | + $this->fnHooks = array(); |
| 541 | + } |
| 542 | + |
| 543 | + /** |
| 544 | + * Called whenever we actually want to run the hook. |
| 545 | + * Should be the case if we found the parserTest is not disabled |
| 546 | + */ |
| 547 | + public function unleash( ParserTest &$parserTest ) { |
| 548 | + # Trigger delayed hooks. Any failure will make us abort |
| 549 | + foreach( $this->hooks as $hook ) { |
| 550 | + $ret = $parserTest->requireHook( $hook ); |
| 551 | + if( !$ret ) { |
| 552 | + return false; |
| 553 | + } |
| 554 | + } |
| 555 | + |
| 556 | + # Trigger delayed function hooks. Any failure will make us abort |
| 557 | + foreach( $this->fnHooks as $fnHook ) { |
| 558 | + $ret = $parserTest->requireFunctionHook( $fnHook ); |
| 559 | + if( !$ret ) { |
| 560 | + return false; |
| 561 | + } |
| 562 | + } |
| 563 | + |
| 564 | + # Delayed execution was successful. |
| 565 | + return true; |
| 566 | + } |
| 567 | + |
| 568 | + /** |
| 569 | + * Similar to ParserTest object but does not run anything |
| 570 | + * Use unleash() to really execute the hook |
| 571 | + */ |
| 572 | + public function requireHook( $hook ) { |
| 573 | + $this->hooks[] = $hook; |
| 574 | + } |
| 575 | + /** |
| 576 | + * Similar to ParserTest object but does not run anything |
| 577 | + * Use unleash() to really execute the hook function |
| 578 | + */ |
| 579 | + public function requireFunctionHook( $fnHook ) { |
| 580 | + $this->fnHooks[] = $fnHook; |
| 581 | + } |
| 582 | + |
| 583 | +} |