diff options
author | Subramanya Sastry <ssastry@wikimedia.org> | 2022-05-14 00:06:03 -0500 |
---|---|---|
committer | C. Scott Ananian <cananian@wikimedia.org> | 2022-05-20 20:37:50 +0000 |
commit | 9e6b7156bc12b276214731e665379c90a71af175 (patch) | |
tree | 97e8ae797cdcf96cca9086f8e1bfa86dbe4e2326 /tests/phpunit/suites | |
parent | b5bcc0dec3b98f907007cdccddc15bc689b3134d (diff) | |
download | mediawikicore-9e6b7156bc12b276214731e665379c90a71af175.tar.gz mediawikicore-9e6b7156bc12b276214731e665379c90a71af175.zip |
Add Parsoid capabilities to parserTests.php script
* This adds all of Parsoid's abilities to the parserTests.php script
* Parsoid testing mode requires a "--parsoid" CLI option.
* This supports "--wt2html" and the other testing modes,
"--updateKnownFailures", "--knownFailures", and "--changetree"
options that are part of the Parsoid's parserTests.php script.
* Verified that the output of parserTests.php test run matches
the output of the PHPUnit test run on the Cite extensions'
citeParserTests.txt file.
Change-Id: I87a1f621d0a2579ac47fa80d34cf74d4456bcf62
Diffstat (limited to 'tests/phpunit/suites')
-rw-r--r-- | tests/phpunit/suites/ParserTestTopLevelSuite.php | 12 | ||||
-rw-r--r-- | tests/phpunit/suites/ParsoidTestFileSuite.php | 52 |
2 files changed, 13 insertions, 51 deletions
diff --git a/tests/phpunit/suites/ParserTestTopLevelSuite.php b/tests/phpunit/suites/ParserTestTopLevelSuite.php index cbcd5e79b080..3a43d27eaa2b 100644 --- a/tests/phpunit/suites/ParserTestTopLevelSuite.php +++ b/tests/phpunit/suites/ParserTestTopLevelSuite.php @@ -64,13 +64,19 @@ class ParserTestTopLevelSuite extends TestSuite { return new self( $flags ); } - public function __construct( $flags ) { + public function __construct( $flags, array $parserTestFlags = null ) { parent::__construct(); $this->ptRecorder = new PhpunitTestRecorder; + $runnerOpts = $parserTestFlags ?? json_decode( getenv( "PARSERTEST_FLAGS" ) ?: "[]", true ); + // PHPUnit test runners requires all tests to be pregenerated. + // But, generating Parsoid selser edit trees requires the DOM. + // So, we cannot pregenerate Parsoid selser auto-edit tests. + // They have to be generated dynamically. So, set this to 0. + // We will handle auto-edit selser tests as a composite test. + $runnerOpts['numchanges'] = 0; $this->ptRunner = new ParserTestRunner( - $this->ptRecorder, - json_decode( getenv( "PARSERTEST_FLAGS" ) ?: "[]", true ) + $this->ptRecorder, $runnerOpts ); if ( is_string( $flags ) ) { diff --git a/tests/phpunit/suites/ParsoidTestFileSuite.php b/tests/phpunit/suites/ParsoidTestFileSuite.php index 6aee3208d11b..75a863727d44 100644 --- a/tests/phpunit/suites/ParsoidTestFileSuite.php +++ b/tests/phpunit/suites/ParsoidTestFileSuite.php @@ -1,6 +1,5 @@ <?php -use MediaWiki\MediaWikiServices; use PHPUnit\Framework\TestSuite; use Wikimedia\Parsoid\ParserTests\Test as ParsoidTest; use Wikimedia\ScopedCallback; @@ -30,22 +29,8 @@ class ParsoidTestFileSuite extends TestSuite { $this->ptFileInfo = Wikimedia\Parsoid\ParserTests\TestFileReader::read( $fileName, static function ( $msg ) { wfDeprecatedMsg( $msg, '1.35', false, false ); } ); - $fileOptions = $this->ptFileInfo->fileOptions; - if ( !isset( $fileOptions['parsoid-compatible'] ) ) { - // Running files in Parsoid integrated mode is opt-in for now. - $skipMessage = 'not compatible with Parsoid integrated mode'; - } elseif ( !MediaWikiServices::getInstance()->hasService( 'ParsoidPageConfigFactory' ) ) { - // Disable integrated mode if Parsoid's services aren't available - // (Temporary measure until Parsoid is fully integrated in core.) - $skipMessage = 'Parsoid not available'; - } elseif ( !$this->ptRunner->meetsRequirements( $fileOptions['requirements'] ?? [] ) ) { - $skipMessage = 'required extension not enabled'; - } elseif ( ( $runnerOpts['testFile'] ?? $fileName ) !== $fileName ) { - $skipMessage = 'Not the requested test file'; - } else { - $skipMessage = null; - } + $skipMessage = $this->ptRunner->getSkipMessage( $this->ptFileInfo->fileOptions, $runnerOpts, $fileName ); // Don't bother doing anything else if a skip message is set. if ( $skipMessage !== null ) { return; @@ -76,14 +61,14 @@ class ParsoidTestFileSuite extends TestSuite { } ); - // Add a "selser-auto" composite test + // Add a "selser-auto-composite" composite test if ( in_array( 'selser', $testModes ) && $runnerOpts['selser'] !== 'noauto' && ( $t->options['parsoid']['selser'] ?? null ) !== 'noauto' ) { $newTest = $test; $newTest['parsoid'] = $t; - $newTest['parsoidMode'] = "selser-auto"; + $newTest['parsoidMode'] = "selser-auto-composite"; $newTest['parsoid-changetree'] = $runnerOpts['changetree']; $pit = new ParserIntegrationTest( $runner, $fileName, $newTest, $skipMessage ); $suite->addTest( $pit, [ 'Database', 'Parser', 'ParserTests' ] ); @@ -106,36 +91,7 @@ class ParsoidTestFileSuite extends TestSuite { protected function tearDown(): void { if ( $this->ptRunner->getOptions()['updateKnownFailures'] ) { - $testKnownFailures = []; - foreach ( $this->ptFileInfo->testCases as $t ) { - if ( $t->knownFailures ) { - $testKnownFailures[$t->testName] = $t->knownFailures; - // FIXME: This reduces noise when updateKnownFailures is used - // with a subset of test modes. But, this also mixes up the selser - // test results with non-selser ones. - // ksort( $testKnownFailures[$t->testName] ); - } - } - // Sort, otherwise, titles get added above based on the first - // failing mode, which can make diffs harder to verify when - // failing modes change. - ksort( $testKnownFailures ); - $contents = json_encode( - $testKnownFailures, - JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | - JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE - ) . "\n"; - - if ( file_exists( $this->ptFileInfo->knownFailuresPath ) ) { - $old = file_get_contents( $this->ptFileInfo->knownFailuresPath ); - } else { - $old = ""; - } - - if ( $this->ptFileInfo->knownFailuresPath && $old !== $contents ) { - error_log( "Updating known failures file: {$this->ptFileInfo->knownFailuresPath}" ); - file_put_contents( $this->ptFileInfo->knownFailuresPath, $contents ); - } + $this->ptRunner->updateKnownFailures( $this->ptFileInfo ); } if ( $this->ptTeardownScope ) { |