[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Autodiscover parser tests for extensions, deprecate $wgParse...
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/363961 ) Change subject: Autodiscover parser tests for extensions, deprecate $wgParserTestFiles .. Autodiscover parser tests for extensions, deprecate $wgParserTestFiles This implements autodiscovery of extension parser tests that are located in the tests/parser/ directory. Any *.txt file in that directory tree will be treated as a parser test. Core parser tests are now defined in ParserTestRunner::$coreTestFiles, and $wgParserTestFiles is marked as deprecated. Bug: T143976 Change-Id: Ia24fd8ef52e6732c698153b17bb679a5f511a2a7 --- M includes/DefaultSettings.php M tests/parser/ParserTestRunner.php M tests/parser/parserTests.php M tests/phpunit/suites/ParserTestTopLevelSuite.php 4 files changed, 61 insertions(+), 10 deletions(-) Approvals: Reedy: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0548d8b..11f08b2 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6333,15 +6333,16 @@ * Parser test suite files to be run by parserTests.php when no specific * filename is passed to it. * - * Extensions may add their own tests to this array, or site-local tests - * may be added via LocalSettings.php + * Extensions using extension.json will have any *.txt file in a + * tests/parser/ directory automatically run. + * + * Core tests can be added to ParserTestRunner::$coreTestFiles. * * Use full paths. + * + * @deprecated since 1.30 */ -$wgParserTestFiles = [ - "$IP/tests/parser/parserTests.txt", - "$IP/tests/parser/extraParserTests.txt" -]; +$wgParserTestFiles = []; /** * Allow running of javascript test suites via [[Special:JavaScriptTest]] (such as QUnit). diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 9dce73f..9255733 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -34,6 +34,18 @@ * @ingroup Testing */ class ParserTestRunner { + + /** +* MediaWiki core parser test files, paths +* will be prefixed with __DIR__ . '/' +* +* @var array +*/ + private static $coreTestFiles = [ + 'parserTests.txt', + 'extraParserTests.txt', + ]; + /** * @var bool $useTemporaryTables Use temporary tables for the temporary database */ @@ -147,6 +159,43 @@ } } + /** +* Get list of filenames to extension and core parser tests +* +* @return array +*/ + public static function getParserTestFiles() { + global $wgParserTestFiles; + + // Add core test files + $files = array_map( function( $item ) { + return __DIR__ . "/$item"; + }, self::$coreTestFiles ); + + // Plus legacy global files + $files = array_merge( $files, $wgParserTestFiles ); + + // Auto-discover extension parser tests + $registry = ExtensionRegistry::getInstance(); + foreach ( $registry->getAllThings() as $info ) { + $dir = dirname( $info['path'] ) . '/tests/parser'; + if ( !file_exists( $dir ) ) { + continue; + } + $dirIterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( $dir ) + ); + foreach ( $dirIterator as $fileInfo ) { + /** @var SplFileInfo $fileInfo */ + if ( substr( $fileInfo->getFilename(), -4 ) === '.txt' ) { + $files[] = $fileInfo->getPathname(); + } + } + } + + return array_unique( $files ); + } + public function getRecorder() { return $this->recorder; } diff --git a/tests/parser/parserTests.php b/tests/parser/parserTests.php index 1d0867a..2735f93 100644 --- a/tests/parser/parserTests.php +++ b/tests/parser/parserTests.php @@ -80,7 +80,7 @@ } public function execute() { - global $wgParserTestFiles, $wgDBtype; + global $wgDBtype; // Cases of weird db corruption were encountered when running tests on earlyish // versions of SQLite @@ -167,7 +167,7 @@ } // Default parser tests and any set from extensions or local config - $files = $this->getOption( 'file', $wgParserTestFiles ); + $files = $this->getOption( 'file', ParserTestRunner::getParserTestFiles() ); $norm =
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Autodiscover parser tests for extensions, deprecate $wgParse...
Legoktm has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/363961 ) Change subject: Autodiscover parser tests for extensions, deprecate $wgParserTestFiles .. Autodiscover parser tests for extensions, deprecate $wgParserTestFiles This implements autodiscovery of extension parser tests that are located in the tests/parser/ directory. Any *.txt file in that directory tree will be treated as a parser test. Core parser tests are now defined in ParserTestRunner::$coreTestFiles, and $wgParserTestFiles is marked as deprecated. Bug: T143976 Change-Id: Ia24fd8ef52e6732c698153b17bb679a5f511a2a7 --- M includes/DefaultSettings.php M tests/parser/ParserTestRunner.php M tests/parser/parserTests.php M tests/phpunit/suites/ParserTestTopLevelSuite.php 4 files changed, 55 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/61/363961/1 diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 1459ab6..aff158d 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6333,15 +6333,16 @@ * Parser test suite files to be run by parserTests.php when no specific * filename is passed to it. * - * Extensions may add their own tests to this array, or site-local tests - * may be added via LocalSettings.php + * Extensions using extension.json will have any *.txt file in a + * tests/parser/ directory automatically run. + * + * Core tests can be added to ParserTestRunner::$coreTestFiles. * * Use full paths. + * + * @deprecated since 1.30 */ -$wgParserTestFiles = [ - "$IP/tests/parser/parserTests.txt", - "$IP/tests/parser/extraParserTests.txt" -]; +$wgParserTestFiles = []; /** * Allow running of javascript test suites via [[Special:JavaScriptTest]] (such as QUnit). diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index a373142..ecaf782 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -34,6 +34,11 @@ * @ingroup Testing */ class ParserTestRunner { + + private static $coreTestFiles = [ + 'parserTests.txt', + 'extraParserTests.txt', + ]; /** * @var bool $useTemporaryTables Use temporary tables for the temporary database */ @@ -147,6 +152,44 @@ } } + /** +* Get list of filenames to extension and core parser tests +* +* @return array +*/ + public static function getParserTestFiles() { + global $wgParserTestFiles; + + // Add core test files + $files = array_map( function( $item ) { + return __DIR__ . "/$item"; + }, self::$coreTestFiles ); + + // Plus legacy global files + $files = array_merge( $files, $wgParserTestFiles ); + + // Auto-discover extension parser tests + $registry = ExtensionRegistry::getInstance(); + foreach ( $registry->getAllThings() as $info ) { + $dir = dirname( $info['path'] ) . '/tests/parser'; + if ( !file_exists( $dir ) ) { + continue; + } + $dirIterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( $dir ) + ); + foreach ( $dirIterator as $fileInfo ) { + /** @var SplFileInfo $fileInfo */ + if ( substr( $fileInfo->getFilename(), -4 ) === '.txt' ) { + $files[] = $fileInfo->getPathname(); + } + } + } + + return array_unique( $files ); + + } + public function getRecorder() { return $this->recorder; } diff --git a/tests/parser/parserTests.php b/tests/parser/parserTests.php index 1d0867a..2735f93 100644 --- a/tests/parser/parserTests.php +++ b/tests/parser/parserTests.php @@ -80,7 +80,7 @@ } public function execute() { - global $wgParserTestFiles, $wgDBtype; + global $wgDBtype; // Cases of weird db corruption were encountered when running tests on earlyish // versions of SQLite @@ -167,7 +167,7 @@ } // Default parser tests and any set from extensions or local config - $files = $this->getOption( 'file', $wgParserTestFiles ); + $files = $this->getOption( 'file', ParserTestRunner::getParserTestFiles() ); $norm = $this->hasOption( 'norm' ) ? explode( ',', $this->getOption( 'norm' ) ) : []; diff --git a/tests/phpunit/suites/ParserTestTopLevelSuite.php