Hashar has uploaded a new change for review.
https://gerrit.wikimedia.org/r/54652
Change subject: test: abstract parser test result
......................................................................
test: abstract parser test result
This patch introduce the new ParserTestResult class which is meant to
represent the result of a parser test. I have refactored some methods
to take advantage of this new class.
It just hold the test description and the actual/expected parser output.
A short isSuccess() method is provided for convenience, we can later
improve the class to carry more methods.
Change-Id: Ifb86e09451875dc119633b52d3f7e4f47c67cc60
---
M tests/TestsAutoLoader.php
A tests/parser/ParserTestResult.php
M tests/parser/parserTest.inc
3 files changed, 59 insertions(+), 16 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/52/54652/1
diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php
index 264ba69..363d0a2 100644
--- a/tests/TestsAutoLoader.php
+++ b/tests/TestsAutoLoader.php
@@ -30,6 +30,7 @@
'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",
diff --git a/tests/parser/ParserTestResult.php
b/tests/parser/ParserTestResult.php
new file mode 100644
index 0000000..7d2edfa
--- /dev/null
+++ b/tests/parser/ParserTestResult.php
@@ -0,0 +1,34 @@
+<?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.21
+ */
+class ParserTestResult {
+ /** Name of the parser test */
+ public $description;
+ /** Text that was expected */
+ public $expected;
+ /** Actual text rendered */
+ public $actual;
+
+ /**
+ * @param $description string The test has described in the .txt file
+ */
+ public function __construct( $description ) {
+ $this->description = $description;
+ }
+
+ /** Whether the test passed */
+ public function isSuccess() {
+ return ($this->expected === $this->actual);
+ }
+}
diff --git a/tests/parser/parserTest.inc b/tests/parser/parserTest.inc
index ce621f4..efd2e42 100644
--- a/tests/parser/parserTest.inc
+++ b/tests/parser/parserTest.inc
@@ -518,18 +518,23 @@
}
$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.21 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;
}
}
@@ -1070,10 +1075,12 @@
/**
* Print a happy success message.
*
- * @param $desc String: the test name
+ * Refactored in 1.21 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";
}
@@ -1085,28 +1092,29 @@
* 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.21 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";
}
}
--
To view, visit https://gerrit.wikimedia.org/r/54652
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb86e09451875dc119633b52d3f7e4f47c67cc60
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Hashar <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits