Merge "test: abstract parser test result"

This commit is contained in:
jenkins-bot 2013-04-22 19:09:20 +00:00 committed by Gerrit Code Review
commit 4fe59cd7c2
3 changed files with 67 additions and 16 deletions

View file

@ -30,6 +30,7 @@ $wgAutoloadClasses += array(
'DbTestPreviewer' => "$testDir/testHelpers.inc",
'DbTestRecorder' => "$testDir/testHelpers.inc",
'DelayedParserTest' => "$testDir/testHelpers.inc",
'ParserTestResult' => "$testDir/parser/ParserTestResult.php",
'TestFileIterator' => "$testDir/testHelpers.inc",
'TestRecorder' => "$testDir/testHelpers.inc",

View file

@ -0,0 +1,42 @@
<?php
/**
* @copyright Copyright © 2013, Antoine Musso
* @copyright Copyright © 2013, Wikimedia Foundation Inc.
* @license GNU GPL v2
*
* @file
*/
/**
* Represent the result of a parser test.
*
* @since 1.22
*/
class ParserTestResult {
/**
* Description of the parser test.
*
* This is usually the text used to describe a parser test in the .txt
* files. It is initialized on a construction and you most probably
* never want to change it.
*/
public $description;
/** Text that was expected */
public $expected;
/** Actual text rendered */
public $actual;
/**
* @param $description string A short text describing the parser test
* usually the text in the parser test .txt file. The description
* is later available using the property $description.
*/
public function __construct( $description ) {
$this->description = $description;
}
/** Whether the test passed */
public function isSuccess() {
return ($this->expected === $this->actual);
}
}

View file

@ -518,18 +518,23 @@ class ParserTest {
}
$this->teardownGlobals();
return $this->showTestResult( $desc, $result, $out );
$testResult = new ParserTestResult( $desc );
$testResult->expected = $result;
$testResult->actual = $out;
return $this->showTestResult( $testResult );
}
/**
*
* Refactored in 1.22 to use ParserTestResult
*/
function showTestResult( $desc, $result, $out ) {
if ( $result === $out ) {
$this->showSuccess( $desc );
function showTestResult( ParserTestResult $testResult ) {
if ( $testResult->isSuccess() ) {
$this->showSuccess( $testResult );
return true;
} else {
$this->showFailure( $desc, $result, $out );
$this->showFailure( $testResult );
return false;
}
}
@ -1095,10 +1100,12 @@ class ParserTest {
/**
* Print a happy success message.
*
* @param $desc String: the test name
* Refactored in 1.22 to use ParserTestResult
*
* @param $testResult ParserTestResult
* @return Boolean
*/
protected function showSuccess( $desc ) {
protected function showSuccess( ParserTestResult $testResult ) {
if ( $this->showProgress ) {
print $this->term->color( '1;32' ) . 'PASSED' . $this->term->reset() . "\n";
}
@ -1110,28 +1117,29 @@ class ParserTest {
* Print a failure message and provide some explanatory output
* about what went wrong if so configured.
*
* @param $desc String: the test name
* @param $result String: expected HTML output
* @param $html String: actual HTML output
* Refactored in 1.22 to use ParserTestResult
*
* @param $testResult ParserTestResult
* @return Boolean
*/
protected function showFailure( $desc, $result, $html ) {
protected function showFailure( ParserTestResult $testResult ) {
if ( $this->showFailure ) {
if ( !$this->showProgress ) {
# In quiet mode we didn't show the 'Testing' message before the
# test, in case it succeeded. Show it now:
$this->showTesting( $desc );
$this->showTesting( $testResult->description );
}
print $this->term->color( '31' ) . 'FAILED!' . $this->term->reset() . "\n";
if ( $this->showOutput ) {
print "--- Expected ---\n$result\n--- Actual ---\n$html\n";
print "--- Expected ---\n{$testResult->expected}\n";
print "--- Actual ---\n{$testResult->actual}\n";
}
if ( $this->showDiffs ) {
print $this->quickDiff( $result, $html );
if ( !$this->wellFormed( $html ) ) {
print $this->quickDiff( $testResult->expected, $testResult->actual );
if ( !$this->wellFormed( $testResult->actual ) ) {
print "XML error: $this->mXmlError\n";
}
}