From: jenkins-bot Date: Sat, 8 Jul 2017 01:01:15 +0000 (+0000) Subject: Merge "Autodiscover parser tests for extensions, deprecate $wgParserTestFiles" X-Git-Tag: 1.31.0-rc.0~2760 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=9aadb1a0df13a78774d5c91f10527cb78924e789;hp=7d623a35bb305b7233a3c2181879fee9ba6c1274 Merge "Autodiscover parser tests for extensions, deprecate $wgParserTestFiles" --- diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 0548d8bacf..11f08b2bb5 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6333,15 +6333,16 @@ $wgSiteStatsAsyncFactor = false; * 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 9dce73f0bb..9255733e74 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -34,6 +34,18 @@ use Wikimedia\TestingAccessWrapper; * @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 @@ class ParserTestRunner { } } + /** + * 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 1d0867abf0..2735f93e0d 100644 --- a/tests/parser/parserTests.php +++ b/tests/parser/parserTests.php @@ -80,7 +80,7 @@ class ParserTestsMaintenance extends Maintenance { } 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 @@ class ParserTestsMaintenance extends Maintenance { } // 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 b/tests/phpunit/suites/ParserTestTopLevelSuite.php index 5d5d693571..09052f3c61 100644 --- a/tests/phpunit/suites/ParserTestTopLevelSuite.php +++ b/tests/phpunit/suites/ParserTestTopLevelSuite.php @@ -69,7 +69,7 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite { if ( is_string( $flags ) ) { $flags = self::CORE_ONLY; } - global $wgParserTestFiles, $IP; + global $IP; $mwTestDir = $IP . '/tests/'; @@ -81,7 +81,8 @@ class ParserTestTopLevelSuite extends PHPUnit_Framework_TestSuite { $filesToTest = []; # Filter out .txt files - foreach ( $wgParserTestFiles as $parserTestFile ) { + $files = ParserTestRunner::getParserTestFiles(); + foreach ( $files as $parserTestFile ) { $isCore = ( 0 === strpos( $parserTestFile, $mwTestDir ) ); if ( $isCore && $wantsCore ) {