public function setUp() { wfDebug(__METHOD__); $db = wfGetDB(DB_MASTER); $type = $db->getType(); $prefix = $type === 'oracle' ? MediaWikiTestCase::ORA_DB_PREFIX : MediaWikiTestCase::DB_PREFIX; MediaWikiTestCase::setupTestDB($db, $prefix); $teardown = $this->ptRunner->setDatabase($db); $teardown = $this->ptRunner->setupUploads($teardown); $this->ptTeardownScope = $teardown; }
public function setUp() { $this->ptTeardownScope = $this->ptRunner->staticSetup(); }
public function execute() { global $wgParserTestFiles, $wgDBtype; // Cases of weird db corruption were encountered when running tests on earlyish // versions of SQLite if ($wgDBtype == 'sqlite') { $db = wfGetDB(DB_MASTER); $version = $db->getServerVersion(); if (version_compare($version, '3.6') < 0) { die("Parser tests require SQLite version 3.6 or later, you have {$version}\n"); } } // Print out software version to assist with locating regressions $version = SpecialVersion::getVersion('nodb'); echo "This is MediaWiki version {$version}.\n\n"; // Only colorize output if stdout is a terminal. $color = !wfIsWindows() && Maintenance::posix_isatty(1); if ($this->hasOption('color')) { switch ($this->getOption('color')) { case 'no': $color = false; break; case 'yes': default: $color = true; break; } } $record = $this->hasOption('record'); $compare = $this->hasOption('compare'); $regex = $this->getOption('filter', $this->getOption('regex', false)); if ($regex !== false) { $regex = "/{$regex}/i"; if ($record) { echo "Warning: --record cannot be used with --regex, disabling --record\n"; $record = false; } } $term = $color ? new AnsiTermColorer() : new DummyTermColorer(); $recorder = new MultiTestRecorder(); $recorder->addRecorder(new ParserTestPrinter($term, ['showDiffs' => !$this->hasOption('quick'), 'showProgress' => !$this->hasOption('quiet'), 'showFailure' => !$this->hasOption('quiet') || !$record && !$compare, 'showOutput' => $this->hasOption('show-output'), 'useDwdiff' => $this->hasOption('dwdiff'), 'markWhitespace' => $this->hasOption('mark-ws')])); $recorderLB = false; if ($record || $compare) { $recorderLB = wfGetLBFactory()->newMainLB(); // This connection will have the wiki's table prefix, not parsertest_ $recorderDB = $recorderLB->getConnection(DB_MASTER); // Add recorder before previewer because recorder will create the // DB table if it doesn't exist if ($record) { $recorder->addRecorder(new DbTestRecorder($recorderDB)); } $recorder->addRecorder(new DbTestPreviewer($recorderDB, function ($name) use($regex) { // Filter reports of old tests by the filter regex if ($regex === false) { return true; } else { return (bool) preg_match($regex, $name); } })); } // Default parser tests and any set from extensions or local config $files = $this->getOption('file', $wgParserTestFiles); $norm = $this->hasOption('norm') ? explode(',', $this->getOption('norm')) : []; $tester = new ParserTestRunner($recorder, ['norm' => $norm, 'regex' => $regex, 'keep-uploads' => $this->hasOption('keep-uploads'), 'run-disabled' => $this->hasOption('run-disabled'), 'run-parsoid' => $this->hasOption('run-parsoid'), 'use-tidy-config' => $this->hasOption('use-tidy-config'), 'file-backend' => $this->getOption('file-backend'), 'upload-dir' => $this->getOption('upload-dir')]); $ok = $tester->runTestsFromFiles($files); if ($recorderLB) { $recorderLB->closeAll(); } if (!$ok) { exit(1); } }
private function execute() { while (false !== ($line = fgets($this->fh))) { $this->lineNum++; $matches = []; if (preg_match('/^!!\\s*(\\S+)/', $line, $matches)) { $this->section = strtolower($matches[1]); if ($this->section == 'endarticle') { $this->checkSection('text'); $this->checkSection('article'); $this->addArticle(ParserTestRunner::chomp($this->sectionData['article']), $this->sectionData['text'], $this->lineNum); $this->clearSection(); continue; } if ($this->section == 'endhooks') { $this->checkSection('hooks'); foreach (explode("\n", $this->sectionData['hooks']) as $line) { $line = trim($line); if ($line) { $this->addRequirement('hook', $line); } } $this->clearSection(); continue; } if ($this->section == 'endfunctionhooks') { $this->checkSection('functionhooks'); foreach (explode("\n", $this->sectionData['functionhooks']) as $line) { $line = trim($line); if ($line) { $this->addRequirement('functionHook', $line); } } $this->clearSection(); continue; } if ($this->section == 'endtransparenthooks') { $this->checkSection('transparenthooks'); foreach (explode("\n", $this->sectionData['transparenthooks']) as $line) { $line = trim($line); if ($line) { $this->addRequirement('transparentHook', $line); } } $this->clearSection(); continue; } if ($this->section == 'end') { $this->checkSection('test'); $this->addCurrentTest(); $this->clearSection(); continue; } if (isset($this->sectionData[$this->section])) { throw new MWException("duplicate section '{$this->section}' " . "at line {$this->lineNum} of {$this->file}\n"); } $this->sectionLineNum[$this->section] = $this->lineNum; $this->sectionData[$this->section] = ''; continue; } if ($this->section) { $this->sectionData[$this->section] .= $line; } } }