r62006 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62005‎ | r62006 | r62007 >
Date:04:01, 5 February 2010
Author:mah
Status:resolved (Comments)
Tags:
Comment:
PHPUnit now sees individual parser tests as separate tests. This
involved changing parserTests.inc slightly to create an iterator that
reads parserTests.txt — separating the reading of the file from the
execution of the tests.

PHPUnit still doesn't see individual assertions, but that is less
important right now.

Tested maintenance/parserTests.php against maintenance/parserTests.txt
and extensions/Cite/citeParserTests.txt to verify that the parser tests
still worked as expected.
Modified paths:
  • /trunk/phase3/maintenance/parserTests.inc (modified) (history)
  • /trunk/phase3/maintenance/tests/MediaWikiParserTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/parserTests.inc
@@ -1,5 +1,5 @@
22 <?php
3 -# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
 3+# Copyright (C) 2004, 2010 Brion Vibber <brion@pobox.com>
44 # http://www.mediawiki.org/
55 #
66 # This program is free software; you can redistribute it and/or modify
@@ -120,6 +120,8 @@
121121 $this->recorder = new DbTestPreviewer( $this );
122122 } elseif( isset( $options['upload'] ) ) {
123123 $this->recorder = new RemoteTestRecorder( $this );
 124+ } elseif( class_exists( 'PHPUnitTestRecorder' ) ) {
 125+ $this->recorder = new PHPUnitTestRecorder( $this );
124126 } else {
125127 $this->recorder = new TestRecorder( $this );
126128 }
@@ -138,7 +140,7 @@
139141 /**
140142 * Remove last character if it is a newline
141143 */
142 - private function chomp($s) {
 144+ public function chomp($s) {
143145 if (substr($s, -1) === "\n") {
144146 return substr($s, 0, -1);
145147 }
@@ -276,7 +278,8 @@
277279 $this->setupDatabase();
278280 $ok = true;
279281 foreach( $filenames as $filename ) {
280 - $ok = $this->runFile( $filename ) && $ok;
 282+ $tests = new TestFileIterator( $filename, $this );
 283+ $ok = $this->runTests( $tests ) && $ok;
281284 }
282285 $this->teardownDatabase();
283286 $this->recorder->report();
@@ -284,124 +287,17 @@
285288 return $ok;
286289 }
287290
288 - private function runFile( $filename ) {
289 - $infile = fopen( $filename, 'rt' );
290 - if( !$infile ) {
291 - wfDie( "Couldn't open file '$filename'\n" );
292 - } else {
293 - global $IP;
294 - $relative = wfRelativePath( $filename, $IP );
295 - $this->showRunFile( $relative );
296 - }
297 -
298 - $data = array();
299 - $section = null;
300 - $n = 0;
 291+ function runTests($tests) {
301292 $ok = true;
302 - while( false !== ($line = fgets( $infile ) ) ) {
303 - $n++;
304 - $matches = array();
305 - if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
306 - $section = strtolower( $matches[1] );
307 - if( $section == 'endarticle') {
308 - if( !isset( $data['text'] ) ) {
309 - wfDie( "'endarticle' without 'text' at line $n of $filename\n" );
310 - }
311 - if( !isset( $data['article'] ) ) {
312 - wfDie( "'endarticle' without 'article' at line $n of $filename\n" );
313 - }
314 - $this->addArticle($this->chomp($data['article']), $this->chomp($data['text']), $n);
315 - $data = array();
316 - $section = null;
317 - continue;
318 - }
319 - if( $section == 'endhooks' ) {
320 - if( !isset( $data['hooks'] ) ) {
321 - wfDie( "'endhooks' without 'hooks' at line $n of $filename\n" );
322 - }
323 - foreach( explode( "\n", $data['hooks'] ) as $line ) {
324 - $line = trim( $line );
325 - if( $line ) {
326 - $this->requireHook( $line );
327 - }
328 - }
329 - $data = array();
330 - $section = null;
331 - continue;
332 - }
333 - if( $section == 'endfunctionhooks' ) {
334 - if( !isset( $data['functionhooks'] ) ) {
335 - wfDie( "'endfunctionhooks' without 'functionhooks' at line $n of $filename\n" );
336 - }
337 - foreach( explode( "\n", $data['functionhooks'] ) as $line ) {
338 - $line = trim( $line );
339 - if( $line ) {
340 - $this->requireFunctionHook( $line );
341 - }
342 - }
343 - $data = array();
344 - $section = null;
345 - continue;
346 - }
347 - if( $section == 'end' ) {
348 - if( !isset( $data['test'] ) ) {
349 - wfDie( "'end' without 'test' at line $n of $filename\n" );
350 - }
351 - if( !isset( $data['input'] ) ) {
352 - wfDie( "'end' without 'input' at line $n of $filename\n" );
353 - }
354 - if( !isset( $data['result'] ) ) {
355 - wfDie( "'end' without 'result' at line $n of $filename\n" );
356 - }
357 - if( !isset( $data['options'] ) ) {
358 - $data['options'] = '';
359 - }
360 - else {
361 - $data['options'] = $this->chomp( $data['options'] );
362 - }
363 - if (!isset( $data['config'] ) )
364 - $data['config'] = '';
365 -
366 - if ( (preg_match('/\\bdisabled\\b/i', $data['options'])
367 - || !preg_match("/{$this->regex}/i", $data['test'])) && !$this->runDisabled ) {
368 - # disabled test
369 - $data = array();
370 - $section = null;
371 - continue;
372 - }
373 - if ( preg_match('/\\bmath\\b/i', $data['options']) && !$this->savedGlobals['wgUseTeX'] ) {
374 - # don't run math tests if $wgUseTeX is set to false in LocalSettings
375 - $data = array();
376 - $section = null;
377 - continue;
378 - }
379 - $result = $this->runTest(
380 - $this->chomp( $data['test'] ),
381 - $this->chomp( $data['input'] ),
382 - $this->chomp( $data['result'] ),
383 - $this->chomp( $data['options'] ),
384 - $this->chomp( $data['config'] )
385 - );
386 - $ok = $ok && $result;
387 - $this->recorder->record( $this->chomp( $data['test'] ), $result );
388 - $data = array();
389 - $section = null;
390 - continue;
391 - }
392 - if ( isset ($data[$section] ) ) {
393 - wfDie( "duplicate section '$section' at line $n of $filename\n" );
394 - }
395 - $data[$section] = '';
396 - continue;
397 - }
398 - if( $section ) {
399 - $data[$section] .= $line;
400 - }
 293+ foreach($tests as $i => $t) {
 294+ $result =
 295+ $this->runTest($t['test'], $t['input'], $t['result'], $t['options'], $t['config']);
 296+ $ok = $ok && $result;
 297+ $this->recorder->record( $t['test'], $result );
401298 }
402299 if ( $this->showProgress ) {
403300 print "\n";
404301 }
405 - return $ok;
406302 }
407303
408304 /**
@@ -431,7 +327,7 @@
432328 * @param string $result Result to output
433329 * @return bool
434330 */
435 - private function runTest( $desc, $input, $result, $opts, $config ) {
 331+ public function runTest( $desc, $input, $result, $opts, $config ) {
436332 if( $this->showProgress ) {
437333 $this->showTesting( $desc );
438334 }
@@ -722,7 +618,7 @@
723619 * Currently this will only be done once per run, and any changes to
724620 * the db will be visible to later tests in the run.
725621 */
726 - private function setupDatabase() {
 622+ function setupDatabase() {
727623 global $wgDBprefix, $wgDBtype;
728624 if ( $this->databaseSetupDone ) {
729625 return;
@@ -1111,7 +1007,7 @@
11121008 *
11131009 * @param String $path
11141010 */
1115 - protected function showRunFile( $path ){
 1011+ public function showRunFile( $path ){
11161012 print $this->term->color( 1 ) .
11171013 "Reading tests from \"$path\"..." .
11181014 $this->term->reset() .
@@ -1124,7 +1020,7 @@
11251021 * @param string $text the article text
11261022 * @param int $line the input line number, for reporting errors
11271023 */
1128 - private function addArticle($name, $text, $line) {
 1024+ public function addArticle($name, $text, $line) {
11291025 $this->setupGlobals();
11301026 $title = Title::newFromText( $name );
11311027 if ( is_null($title) ) {
@@ -1148,7 +1044,7 @@
11491045 * die a painful dead to warn the others.
11501046 * @param string $name
11511047 */
1152 - private function requireHook( $name ) {
 1048+ public function requireHook( $name ) {
11531049 global $wgParser;
11541050 $wgParser->firstCallInit( ); //make sure hooks are loaded.
11551051 if( isset( $wgParser->mTagHooks[$name] ) ) {
@@ -1652,3 +1548,171 @@
16531549 return Http::post( $url, array( 'postData' => $data) );
16541550 }
16551551 }
 1552+
 1553+class TestFileIterator implements Iterator {
 1554+ private $file;
 1555+ private $fh;
 1556+ private $parser;
 1557+ private $index = 0;
 1558+ private $test;
 1559+ private $lineNum;
 1560+ private $eof;
 1561+
 1562+ function __construct( $file, $parser = null ) {
 1563+ global $IP;
 1564+
 1565+ $this->file = $file;
 1566+ $this->fh = fopen($this->file, "r");
 1567+ if( !$this->fh ) {
 1568+ wfDie( "Couldn't open file '$file'\n" );
 1569+ }
 1570+
 1571+ $this->parser = $parser;
 1572+
 1573+ if( $this->parser ) $this->parser->showRunFile( wfRelativePath( $this->file, $IP ) );
 1574+ $this->lineNum = $this->index = 0;
 1575+ }
 1576+
 1577+ function setParser( ParserTest $parser ) {
 1578+ $this->parser = $parser;
 1579+ }
 1580+
 1581+ function rewind() {
 1582+ if(fseek($this->fh, 0)) {
 1583+ wfDie( "Couldn't fseek to the start of '$filename'\n" );
 1584+ }
 1585+ $this->index = 0;
 1586+ $this->lineNum = 0;
 1587+ $this->eof = false;
 1588+ $this->readNextTest();
 1589+
 1590+ return true;
 1591+ }
 1592+
 1593+ function current() {
 1594+ return $this->test;
 1595+ }
 1596+
 1597+ function key() {
 1598+ return $this->index;
 1599+ }
 1600+
 1601+ function next() {
 1602+ if($this->readNextTest()) {
 1603+ $this->index++;
 1604+ return true;
 1605+ } else {
 1606+ $this->eof = true;
 1607+ }
 1608+ }
 1609+
 1610+ function valid() {
 1611+ return $this->eof != true;
 1612+ }
 1613+
 1614+ function readNextTest() {
 1615+ $data = array();
 1616+ $section = null;
 1617+
 1618+ while( false !== ($line = fgets( $this->fh ) ) ) {
 1619+ $this->lineNum++;
 1620+ $matches = array();
 1621+ if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) {
 1622+ $section = strtolower( $matches[1] );
 1623+ if( $section == 'endarticle') {
 1624+ if( !isset( $data['text'] ) ) {
 1625+ wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $filename\n" );
 1626+ }
 1627+ if( !isset( $data['article'] ) ) {
 1628+ wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $filename\n" );
 1629+ }
 1630+ if( $this->parser ) $this->parser->addArticle($this->parser->chomp($data['article']), $this->parser->chomp($data['text']),
 1631+ $this->lineNum);
 1632+ $data = array();
 1633+ $section = null;
 1634+ continue;
 1635+ }
 1636+ if( $section == 'endhooks' ) {
 1637+ if( !isset( $data['hooks'] ) ) {
 1638+ wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $filename\n" );
 1639+ }
 1640+ foreach( explode( "\n", $data['hooks'] ) as $line ) {
 1641+ $line = trim( $line );
 1642+ if( $line ) {
 1643+ if( $this->parser ) $this->parser->requireHook( $line );
 1644+ }
 1645+ }
 1646+ $data = array();
 1647+ $section = null;
 1648+ continue;
 1649+ }
 1650+ if( $section == 'endfunctionhooks' ) {
 1651+ if( !isset( $data['functionhooks'] ) ) {
 1652+ wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $filename\n" );
 1653+ }
 1654+ foreach( explode( "\n", $data['functionhooks'] ) as $line ) {
 1655+ $line = trim( $line );
 1656+ if( $line ) {
 1657+ if( $this->parser ) $this->parser->requireFunctionHook( $line );
 1658+ }
 1659+ }
 1660+ $data = array();
 1661+ $section = null;
 1662+ continue;
 1663+ }
 1664+ if( $section == 'end' ) {
 1665+ if( !isset( $data['test'] ) ) {
 1666+ wfDie( "'end' without 'test' at line {$this->lineNum} of $filename\n" );
 1667+ }
 1668+ if( !isset( $data['input'] ) ) {
 1669+ wfDie( "'end' without 'input' at line {$this->lineNum} of $filename\n" );
 1670+ }
 1671+ if( !isset( $data['result'] ) ) {
 1672+ wfDie( "'end' without 'result' at line {$this->lineNum} of $filename\n" );
 1673+ }
 1674+ if( !isset( $data['options'] ) ) {
 1675+ $data['options'] = '';
 1676+ }
 1677+ if (!isset( $data['config'] ) )
 1678+ $data['config'] = '';
 1679+
 1680+ if ( $this->parser && (preg_match('/\\bdisabled\\b/i', $data['options'])
 1681+ || !preg_match("/{$this->parser->regex}/i", $data['test'])) && !$this->parser->runDisabled ) {
 1682+ # disabled test
 1683+ $data = array();
 1684+ $section = null;
 1685+ continue;
 1686+ }
 1687+ if ( $this->parser &&
 1688+ preg_match('/\\bmath\\b/i', $data['options']) && !$this->parser->savedGlobals['wgUseTeX'] ) {
 1689+ # don't run math tests if $wgUseTeX is set to false in LocalSettings
 1690+ $data = array();
 1691+ $section = null;
 1692+ continue;
 1693+ }
 1694+
 1695+ if( $this->parser ) {
 1696+ $this->test = array(
 1697+ 'test' => $this->parser->chomp( $data['test'] ),
 1698+ 'input' => $this->parser->chomp( $data['input'] ),
 1699+ 'result' => $this->parser->chomp( $data['result'] ),
 1700+ 'options' => $this->parser->chomp( $data['options'] ),
 1701+ 'config' => $this->parser->chomp( $data['config'] ) );
 1702+ } else {
 1703+ $this->test['test'] = $data['test'];
 1704+ }
 1705+ return true;
 1706+ }
 1707+ if ( isset ($data[$section] ) ) {
 1708+ wfDie( "duplicate section '$section' at line {$this->lineNum} of $filename\n" );
 1709+ }
 1710+ $data[$section] = '';
 1711+ continue;
 1712+ }
 1713+ if( $section ) {
 1714+ $data[$section] .= $line;
 1715+ }
 1716+ }
 1717+ return false;
 1718+ }
 1719+}
\ No newline at end of file
Index: trunk/phase3/maintenance/tests/MediaWikiParserTest.php
@@ -2,45 +2,109 @@
33
44 global $IP;
55 define( "NO_COMMAND_LINE", 1 );
 6+define( "PARSER_TESTS", "$IP/maintenance/parserTests.txt" );
 7+
68 require_once( "$IP/maintenance/parserTests.inc" );
7 -require_once( "ImageFunctions.php" );
8 -require_once( "ProxyTools.php" );
9 -require_once( "ObjectCache.php" );
109
11 -class PTShell extends ParserTest {
 10+class PHPUnitTestRecorder extends TestRecorder {
1211
13 - private $cb;
 12+ function record( $test, $result ) {
 13+ $this->total++;
 14+ $this->success += $result;
1415
15 - function setCallback( $cb ) {
16 - $this->cb = $cb;
1716 }
1817
19 - function showTesting( $desc ) {
20 - }
 18+ function reportPercentage( $success, $total ) {}
 19+}
2120
22 - function showRunFile( $path ) {
 21+class MediaWikiParserTestSuite extends PHPUnit_Framework_TestSuite {
 22+#implements PHPUnit_Framework_SelfDescribing {
 23+ static private $count;
 24+ static public $parser;
 25+ static public $iter;
 26+
 27+ public static function suite() {
 28+ $suite = new PHPUnit_Framework_TestSuite();
 29+
 30+ self::$iter = new TestFileIterator( PARSER_TESTS );
 31+
 32+ foreach(self::$iter as $i => $test) {
 33+ $suite->addTest(new ParserUnitTest($i, $test['test']));
 34+ self::$count++;
 35+ }
 36+ unset($tests);
 37+
 38+ self::$parser = new PTShell;
 39+ self::$iter->setParser(self::$parser);
 40+ self::$parser->recorder->start();
 41+ self::$parser->setupDatabase();
 42+ self::$iter->rewind();
 43+ /* } */
 44+ /* function setUp() { */
 45+ global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
 46+ $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache,
 47+ $wgMessageCache, $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc,
 48+ $wgNamespaceAliases, $wgNamespaceProtection, $wgLocalFileRepo,
 49+ $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
 50+ $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
 51+
 52+ $wgScript = '/index.php';
 53+ $wgScriptPath = '/';
 54+ $wgArticlePath = '/wiki/$1';
 55+ $wgStyleSheetPath = '/skins';
 56+ $wgStylePath = '/skins';
 57+ $wgThumbnailScriptPath = false;
 58+ $wgLocalFileRepo = array(
 59+ 'class' => 'LocalRepo',
 60+ 'name' => 'local',
 61+ 'directory' => '',
 62+ 'url' => 'http://example.com/images',
 63+ 'hashLevels' => 2,
 64+ 'transformVia404' => false,
 65+ );
 66+ $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
 67+ $wgNamespaceAliases['Image'] = NS_FILE;
 68+ $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 69+
 70+
 71+ $wgEnableParserCache = false;
 72+ $wgDeferredUpdateList = array();
 73+ $wgMemc =& wfGetMainCache();
 74+ $messageMemc =& wfGetMessageCacheStorage();
 75+ $parserMemc =& wfGetParserCacheStorage();
 76+
 77+ $wgContLang = new StubContLang;
 78+ $wgUser = new StubUser;
 79+ $wgLang = new StubUserLang;
 80+ $wgOut = new StubObject( 'wgOut', 'OutputPage' );
 81+ $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
 82+ $wgRequest = new WebRequest;
 83+
 84+ $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
 85+ array( $messageMemc, $wgUseDatabaseMessages,
 86+ $wgMsgCacheExpiry, wfWikiID() ) );
 87+ if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
 88+
 89+ return $suite;
2390 }
2491
25 - function showSuccess( $desc ) {
26 - $this->cb->assertTrue( true, $desc );
27 - echo "PASSED: $desc\n";
28 - return true;
 92+ public function tearDown() {
 93+ $this->teardownDatabase();
 94+ $this->recorder->report();
 95+ $this->recorder->end();
 96+ $this->teardownUploadDir($this->uploadDir);
2997 }
3098
31 - function showFailure( $desc, $expected, $got ) {
32 - /* $this->cb->assertEquals( $expected, $got, $desc ); */
33 - echo "FAILED: $desc\n";
34 - echo "got: $got\n";
35 - echo "expected: $expected\n";
 99+ public function count() {return self::$count;}
 100+
 101+ public function toString() {
 102+ return "MediaWiki Parser Tests";
36103 }
37 -}
38104
39 -class MediaWikiParserTest extends PHPUnit_Framework_TestCase {
40 - private $parserTester;
 105+
41106 private $db;
42107 private $uploadDir;
43108 private $keepUploads;
44 -
45109 /**
46110 * Remove the dummy uploads directory
47111 */
@@ -132,88 +196,84 @@
133197 copy( "$IP/skins/monobook/headbg.jpg", "$dir/0/09/Bad.jpg" );
134198 return $dir;
135199 }
 200+}
136201
137 - function setUp() {
138 - global $wgParser, $wgParserConf, $IP, $messageMemc, $wgMemc, $wgDeferredUpdateList,
139 - $wgUser, $wgLang, $wgOut, $wgRequest, $wgStyleDirectory, $wgEnableParserCache, $wgMessageCache,
140 - $wgUseDatabaseMessages, $wgMsgCacheExpiry, $parserMemc, $wgNamespaceAliases, $wgNamespaceProtection,
141 - $wgLocalFileRepo, $wgNamespacesWithSubpages, $wgThumbnailScriptPath, $wgScriptPath,
142 - $wgArticlePath, $wgStyleSheetPath, $wgScript, $wgStylePath;
 202+class ParserUnitTest extends PHPUnit_Framework_TestCase {
 203+ private $number = 0;
 204+ private $test = "";
143205
144 - $wgScript = '/index.php';
145 - $wgScriptPath = '/';
146 - $wgArticlePath = '/wiki/$1';
147 - $wgStyleSheetPath = '/skins';
148 - $wgStylePath = '/skins';
149 - $wgThumbnailScriptPath = false;
150 - $this->uploadDir = $this->setupUploadDir();
151 - $wgLocalFileRepo = array(
152 - 'class' => 'LocalRepo',
153 - 'name' => 'local',
154 - 'directory' => $this->uploadDir,
155 - 'url' => 'http://example.com/images',
156 - 'hashLevels' => 2,
157 - 'transformVia404' => false,
158 - );
159 - //$wgNamespacesWithSubpages = array( 0 => isset( $opts['subpage'] ) );
160 - $wgNamespaceProtection[NS_MEDIAWIKI] = 'editinterface';
161 - $wgNamespaceAliases['Image'] = NS_FILE;
162 - $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK;
 206+ public function __construct($number, $test) {
 207+ $this->number = $number;
 208+ $this->test = $test;
 209+ }
163210
 211+ function count() {return 1;}
164212
165 - $wgEnableParserCache = false;
166 - $wgDeferredUpdateList = array();
167 - $wgMemc =& wfGetMainCache();
168 - $messageMemc =& wfGetMessageCacheStorage();
169 - $parserMemc =& wfGetParserCacheStorage();
 213+ public function run(PHPUnit_Framework_TestResult $result = NULL) {
 214+ PHPUnit_Framework_Assert::resetCount();
 215+ if ($result === NULL) {
 216+ $result = new PHPUnit_Framework_TestResult;
 217+ }
170218
171 - $wgContLang = new StubContLang;
172 - $wgUser = new StubUser;
173 - $wgLang = new StubUserLang;
174 - $wgOut = new StubObject( 'wgOut', 'OutputPage' );
175 - $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], array( $wgParserConf ) );
176 - $wgRequest = new WebRequest;
 219+ $t = MediaWikiParserTestSuite::$iter->current();
 220+ $k = MediaWikiParserTestSuite::$iter->key();
177221
178 - $wgMessageCache = new StubObject( 'wgMessageCache', 'MessageCache',
179 - array( $messageMemc, $wgUseDatabaseMessages, $wgMsgCacheExpiry, wfWikiID() ) );
180 - if( $wgStyleDirectory === false) $wgStyleDirectory = "$IP/skins";
 222+ if(!MediaWikiParserTestSuite::$iter->valid()) {
 223+ return;
 224+ }
181225
182 - $this->parserTester = new PTShell();
183 - $this->parserTester->setCallback( $this );
 226+ // The only way this should happen is if the parserTest.txt
 227+ // file were modified while the script is running.
 228+ if($k != $this->number) {
 229+ $i = $this->number;
 230+ wfDie("I got confused!\n");
 231+ }
184232
185 - /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
186 - /* $this->db['type'] = $wgDBtype; */
187 - /* $this->db['server'] = $wgDBserver; */
188 - /* $this->db['name'] = $wgDBname; */
189 - /* $this->db['user'] = $wgDBuser; */
190 - /* $this->db['password'] = $wgDBpassword; */
191 - /* $this->db['port'] = $wgDBport; */
192 - /* $this->db['mwschema'] = $wgDBmwschema; */
193 - /* $this->db['ts2schema'] = $wgDBts2chema; */
 233+ $result->startTest($this);
 234+ PHPUnit_Util_Timer::start();
 235+
 236+ $r = false;
 237+ try {
 238+ $r = MediaWikiParserTestSuite::$parser->runTest(
 239+ $t['test'], $t['input'], $t['result'], $t['options'], $t['config']
 240+ );
 241+ PHPUnit_Framework_Assert::assertTrue(true, $t['test']);
 242+ }
 243+ catch (PHPUnit_Framework_AssertionFailedError $e) {
 244+ $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
 245+ }
 246+ catch (Exception $e) {
 247+ $result->addError($this, $e, PHPUnit_Util_Timer::stop());
 248+ }
 249+ PHPUnit_Framework_Assert::assertTrue(true, $t['test']);
 250+
 251+ $result->endTest($this, PHPUnit_Util_Timer::stop());
 252+
 253+ MediaWikiParserTestSuite::$parser->recorder->record($t['test'], $r);
 254+ MediaWikiParserTestSuite::$iter->next();
 255+ $this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
 256+
 257+ return $result;
194258 }
195259
196 - function tearDown() {
197 - $this->teardownUploadDir($this->uploadDir);
198 - /* $db = wfGetDB( DB_MASTER ); */
199 - /* $db->close(); */
200 - /* global $wgDBtype, $wgDBserver, $wgDBname, $wgDBuser, $wgDBpassword, $wgDBport, $wgDBmwschema, $wgDBts2chema; */
 260+}
201261
202 - /* $wgDBtype = $this->db['type']; */
203 - /* $wgDBserver = $this->db['server']; */
204 - /* $wgDBname = $this->db['name']; */
205 - /* $wgDBuser = $this->db['user']; */
206 - /* $wgDBpassword = $this->db['password']; */
207 - /* $wgDBport = $this->db['port']; */
208 - /* $wgDBmwschema = $this->db['mwschema']; */
209 - /* $wgDBts2chema = $this->db['ts2schema']; */
 262+class PTShell extends ParserTest {
 263+ function showTesting( $desc ) {
 264+ }
210265
 266+ function showRunFile( $path ) {
211267 }
212268
 269+ function showSuccess( $desc ) {
 270+ PHPUnit_Framework_Assert::assertTrue(true, $desc);
 271+ return true;
 272+ }
213273
214 - function testParser() {
215 - global $IP;
 274+ function showFailure( $desc, $expected, $got ) {
 275+ PHPUnit_Framework_Assert::assertEquals($expected, $got, $desc);
 276+ }
216277
217 - $this->parserTester->runTestsFromFiles( array( "$IP/maintenance/parserTests.txt" ) );
218 - }
219278 }
220279
 280+

Follow-up revisions

RevisionCommit summaryAuthorDate
r62424parserTests.txt shall be opened in text mode....platonides13:46, 13 February 2010
r64750re r62006 change private function to publicmah13:48, 8 April 2010
r64880Follow up r62006 readding return $ok; to what is now runTests()...platonides14:06, 10 April 2010
r82877Remove NewParserHelpers.php and use instead the original TestFileIterator fro...platonides23:45, 26 February 2011

Comments

#Comment by IAlex (talk | contribs)   16:49, 6 February 2010

This seems to have some side effects (reported by avar):

  • Tests use too much memory (> 1 GB)
  • A test in language converter fails
  • ...

See mailarchive:wikitech-l/2010-February/046657.html for more details, reverse merging of this revision resolves the problems.

#Comment by 😂 (talk | contribs)   12:12, 30 March 2010

As of r64379, all non-skipped tests are passing for me with both 'make phpunit' and 'make tap' (one ApiTest in make tap is failing, but that's unrelated to this). Memory usage seems to be better as well. I'm only getting ~120MB used with phpunit, which isn't bad at all.

Going to mark this resolved.

#Comment by Tim Starling (talk | contribs)   07:49, 8 April 2010

This refactor introduces an invalid call to a private function:

Reading tests from "extensions/LabeledSectionTransclusion/lstParserTests.txt"...
Fatal error: Call to private method ParserTest::requireFunctionHook() from context 'TestFileIterator' in .../maintenance/parserTests.inc on line 1657
#Comment by MarkAHershberger (talk | contribs)   13:49, 8 April 2010

see r64750

Status & tagging log