Fix unit test engine↔parser assignment

In the unit tests, the engine is given a parser, but the parser is not
being associated back with the engine. So in some cases, that could lead
to *another*, default engine being created for certain operations.

Fix that.

Change-Id: I79995c2635d9e470931b84dc1854dae26772bbe3
This commit is contained in:
Brad Jorsch 2013-03-06 18:17:20 -05:00 committed by Gerrit Code Review
parent 201bf237b3
commit 981ea4c39f
2 changed files with 18 additions and 15 deletions

View file

@ -65,8 +65,6 @@ abstract class Scribunto_LuaEngineTestBase extends MediaWikiTestCase {
$suite->setName( $className );
$class = new ReflectionClass( $className );
$parser = new Parser;
$parser->startExternalParse( Title::newMainPage(), new ParserOptions, Parser::OT_HTML, true );
foreach ( self::$engineConfigurations as $engineName => $opts ) {
if ( $group !== null && $group !== $engineName ) {
@ -74,10 +72,13 @@ abstract class Scribunto_LuaEngineTestBase extends MediaWikiTestCase {
}
try {
$parser = new Parser;
$parser->startExternalParse( Title::newMainPage(), new ParserOptions, Parser::OT_HTML, true );
$engineClass = "Scribunto_{$engineName}Engine";
$engine = new $engineClass(
self::$engineConfigurations[$engineName] + array( 'parser' => $parser )
);
$parser->scribunto_engine = $engine;
$engine->setTitle( $parser->getTitle() );
$engine->getInterpreter();
} catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
@ -163,6 +164,7 @@ abstract class Scribunto_LuaEngineTestBase extends MediaWikiTestCase {
$this->engine = new $class(
self::$engineConfigurations[$this->engineName] + array( 'parser' => $parser )
);
$parser->scribunto_engine = $this->engine;
$this->engine->setTitle( $parser->getTitle() );
}
return $this->engine;

View file

@ -16,33 +16,34 @@ class Scribunto_LuaEnvironmentComparisonTest extends MediaWikiTestCase {
protected $engines = array();
function setUp() {
parent::setUp();
function makeEngine( $class, $opts ) {
$parser = new Parser;
$options = new ParserOptions;
$options->setTemplateCallback( array( $this, 'templateCallback' ) );
$parser->startExternalParse( Title::newMainPage(), $options, Parser::OT_HTML, true );
$engine = new $class ( array( 'parser' => $parser ) + $opts );
$parser->scribunto_engine = $engine;
$engine->setTitle( $parser->getTitle() );
$engine->getInterpreter();
return $engine;
}
function setUp() {
parent::setUp();
try {
$engine = new Scribunto_LuaSandboxEngine(
array( 'parser' => $parser ) + $this->sandboxOpts
$this->engines['LuaSandbox'] = $this->makeEngine(
'Scribunto_LuaSandboxEngine', $this->sandboxOpts
);
$engine->setTitle( $parser->getTitle() );
$engine->getInterpreter();
$this->engines['LuaSandbox'] = $engine;
} catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
$this->markTestSkipped( "LuaSandbox interpreter not available" );
return;
}
try {
$engine = new Scribunto_LuaStandaloneEngine(
array( 'parser' => $parser ) + $this->standaloneOpts
$this->engines['LuaStandalone'] = $this->makeEngine(
'Scribunto_LuaStandaloneEngine', $this->standaloneOpts
);
$engine->setTitle( $parser->getTitle() );
$engine->getInterpreter();
$this->engines['LuaStandalone'] = $engine;
} catch ( Scribunto_LuaInterpreterNotFoundError $e ) {
$this->markTestSkipped( "LuaStandalone interpreter not available" );
return;