From 9a90062eca15355d96eec8a3cd1e3bbfb4fa2174 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 19 Mar 2013 15:00:44 +0100 Subject: [PATCH] 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 --- tests/TestsAutoLoader.php | 1 + tests/parser/ParserTestResult.php | 42 +++++++++++++++++++++++++++++++ tests/parser/parserTest.inc | 40 +++++++++++++++++------------ 3 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 tests/parser/ParserTestResult.php diff --git a/tests/TestsAutoLoader.php b/tests/TestsAutoLoader.php index 264ba695c6..363d0a2eaa 100644 --- a/tests/TestsAutoLoader.php +++ b/tests/TestsAutoLoader.php @@ -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", diff --git a/tests/parser/ParserTestResult.php b/tests/parser/ParserTestResult.php new file mode 100644 index 0000000000..e846da5431 --- /dev/null +++ b/tests/parser/ParserTestResult.php @@ -0,0 +1,42 @@ +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 ce621f4e37..526a6d6da6 100644 --- a/tests/parser/parserTest.inc +++ b/tests/parser/parserTest.inc @@ -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; } } @@ -1070,10 +1075,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"; } @@ -1085,28 +1092,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"; } } -- 2.20.1