ParserTests: Add --dir option as a complement to the --file option

This lets us run parser tests on specific directories. This is
particularly useful when syncing tests between Parsoid and core
since it lets us rerun tests for all synced files as well as
update known failures if requires for Parsoid integrated mode
test runs.

Change-Id: I9030ddd63997b0b197991860aeb850ebf54d4dd7
This commit is contained in:
Subramanya Sastry 2022-10-24 13:05:51 -05:00
parent 18091ab582
commit 6591c2e74d
2 changed files with 28 additions and 13 deletions

View file

@ -260,21 +260,34 @@ class ParserTestRunner {
/**
* Get list of filenames to extension and core parser tests
*
* @param array $dirs
* @return array
*/
public static function getParserTestFiles() {
// Auto-discover core test files
$ptDirs = [ 'core' => __DIR__ ];
// Auto-discover extension parser tests
$registry = ExtensionRegistry::getInstance();
foreach ( $registry->getAllThings() as $info ) {
$dir = dirname( $info['path'] ) . '/tests/parser';
if ( !is_dir( $dir ) ) {
continue;
public static function getParserTestFiles( array $dirs = [] ): array {
if ( $dirs ) {
$ptDirs = [];
foreach ( $dirs as $i => $dir ) {
if ( !is_dir( $dir ) ) {
echo "$dir is not a directory. Skipping it.\n";
continue;
}
$ptDirs["_CLI{$i}_"] = $dir;
}
} else {
// Auto-discover core test files
$ptDirs = [ 'core' => __DIR__ ];
// Auto-discover extension parser tests
$registry = ExtensionRegistry::getInstance();
foreach ( $registry->getAllThings() as $info ) {
$dir = dirname( $info['path'] ) . '/tests/parser';
if ( !is_dir( $dir ) ) {
continue;
}
$ptDirs[ $info['name'] ] = $dir;
}
$ptDirs[ $info['name'] ] = $dir;
}
$files = [];
foreach ( $ptDirs as $extName => $dir ) {
$counter = 1;

View file

@ -69,6 +69,8 @@ class ParserTestsMaintenance extends Maintenance {
$this->addOption( 'filter', 'Alias for --regex', false, true );
$this->addOption( 'file', 'Run test cases from a custom file instead of parserTests.txt',
false, true, false, true );
$this->addOption( 'dir', 'Run test cases for all *.txt files in a directory',
false, true, false, true );
$this->addOption( 'record', 'Record tests in database' );
$this->addOption( 'compare', 'Compare with recorded results, without updating the database.' );
$this->addOption( 'setversion', 'When using --record, set the version string to use (useful' .
@ -208,8 +210,8 @@ class ParserTestsMaintenance extends Maintenance {
}
// Default parser tests and any set from extensions or local config
$files = $this->getOption( 'file', ParserTestRunner::getParserTestFiles() );
$dirs = $this->getOption( 'dir', [] );
$files = $this->getOption( 'file', ParserTestRunner::getParserTestFiles( $dirs ) );
$norm = $this->hasOption( 'norm' ) ? explode( ',', $this->getOption( 'norm' ) ) : [];
$selserOpt = $this->getOption( 'selser', false ); /* can also be 'noauto' */