40 public function start();
49 public function end();
59 $this->
term = $parent->term;
69 $this->success += (
$result ? 1 : 0 );
77 if ( $this->total > 0 ) {
86 print $this->
term->color( 1 ) .
"Passed $success of $total tests ($ratio)... ";
89 print $this->
term->color( 32 ) .
"ALL TESTS PASSED!";
92 print $this->
term->color( 31 ) .
"$failed tests failed!";
95 print $this->
term->reset() .
"\n";
112 parent::__construct(
$parent );
116 $this->db = $this->lb->getConnection(
DB_MASTER );
126 if ( !$this->db->tableExists(
'testrun', __METHOD__ )
127 || !$this->db->tableExists(
'testitem', __METHOD__ )
129 print
"WARNING> `testrun` table not found in database.\n";
130 $this->prevRun =
false;
133 $this->prevRun = $this->db->selectField(
'testrun',
'MAX(tr_id)' );
136 $this->results =
array();
145 if ( $this->prevRun ) {
149 'fp' =>
'previously failing test(s) now PASSING! :)',
150 'pn' =>
'previously PASSING test(s) removed o_O',
151 'np' =>
'new PASSING test(s) :)',
153 'pf' =>
'previously passing test(s) now FAILING! :(',
154 'fn' =>
'previously FAILING test(s) removed O_o',
155 'nf' =>
'new FAILING test(s) :(',
156 'ff' =>
'still FAILING test(s) :(',
159 $prevResults =
array();
161 $res = $this->db->select(
'testitem',
array(
'ti_name',
'ti_success' ),
162 array(
'ti_run' => $this->prevRun ), __METHOD__ );
164 foreach (
$res as $row ) {
165 if ( !$this->parent->regex
166 || preg_match(
"/{$this->parent->regex}/i", $row->ti_name )
168 $prevResults[$row->ti_name] = $row->ti_success;
172 $combined = array_keys( $this->results + $prevResults );
174 # Determine breakdown by change type
175 $breakdown =
array();
176 foreach ( $combined
as $test ) {
177 if ( !isset( $prevResults[
$test] ) ) {
179 } elseif ( $prevResults[
$test] == 1 ) {
185 if ( !isset( $this->results[
$test] ) ) {
187 } elseif ( $this->results[
$test] == 1 ) {
193 $code = $before . $after;
195 if ( isset( $table[$code] ) ) {
201 foreach ( $table
as $code => $label ) {
202 if ( !empty( $breakdown[$code] ) ) {
203 $count = count( $breakdown[$code] );
204 printf(
"\n%4d %s\n",
$count, $label );
206 foreach ( $breakdown[$code]
as $differing_test_name => $statusInfo ) {
207 print
" * $differing_test_name [$statusInfo]\n";
212 print
"No previous test runs to compare against.\n";
226 if ( $after ==
'n' ) {
227 $changedRun = $this->db->selectField(
'testitem',
229 array(
'ti_name' => $testname ),
231 $appear = $this->db->selectRow(
'testrun',
232 array(
'tr_date',
'tr_mw_version' ),
233 array(
'tr_id' => $changedRun ),
236 return "First recorded appearance: "
237 . date(
"d-M-Y H:i:s", strtotime( $appear->tr_date ) )
238 .
", " . $appear->tr_mw_version;
244 'ti_name' => $testname,
245 'ti_success' => ( $after ==
'f' ?
"1" :
"0" ) );
247 if ( $this->curRun ) {
248 $conds[] =
"ti_run != " . $this->db->addQuotes( $this->curRun );
251 $changedRun = $this->db->selectField(
'testitem',
'MAX(ti_run)', $conds, __METHOD__ );
254 if ( is_null( $changedRun ) ) {
255 if ( $after ==
"f" ) {
256 return "Has never passed";
258 return "Has never failed";
265 $pre = $this->db->selectRow(
'testrun',
266 array(
'tr_date',
'tr_mw_version' ),
267 array(
'tr_id' => $changedRun ),
269 $post = $this->db->selectRow(
'testrun',
270 array(
'tr_date',
'tr_mw_version' ),
271 array(
"tr_id > " . $this->db->addQuotes( $changedRun ) ),
273 array(
"LIMIT" => 1,
"ORDER BY" =>
'tr_id' )
277 $postDate = date(
"d-M-Y H:i:s", strtotime( $post->tr_date ) ) .
", {$post->tr_mw_version}";
282 return ( $after ==
"f" ?
"Introduced" :
"Fixed" ) .
" between "
283 . date(
"d-M-Y H:i:s", strtotime(
$pre->tr_date ) ) .
", " .
$pre->tr_mw_version
291 $this->lb->commitMasterChanges();
292 $this->lb->closeAll();
305 $this->db->begin( __METHOD__ );
307 if ( !$this->db->tableExists(
'testrun' )
308 || !$this->db->tableExists(
'testitem' )
310 print
"WARNING> `testrun` table not found in database. Trying to create table.\n";
311 $this->db->sourceFile( $this->db->patchPath(
'patch-testrun.sql' ) );
312 echo
"OK, resuming.\n";
317 $this->db->insert(
'testrun',
319 'tr_date' => $this->db->timestamp(),
321 'tr_php_version' => phpversion(),
322 'tr_db_version' => $this->db->getServerVersion(),
323 'tr_uname' => php_uname()
326 if ( $this->db->getType() ===
'postgres' ) {
327 $this->curRun = $this->db->currentSequenceValue(
'testrun_id_seq' );
329 $this->curRun = $this->db->insertId();
342 $this->db->insert(
'testitem',
344 'ti_run' => $this->curRun,
346 'ti_success' =>
$result ? 1 : 0,
366 $this->fh = fopen( $this->
file,
"rt" );
369 throw new MWException(
"Couldn't open file '$file'\n" );
374 $this->lineNum = $this->index = 0;
378 if ( fseek( $this->fh, 0 ) ) {
379 throw new MWException(
"Couldn't fseek to the start of '$this->file'\n" );
408 return $this->eof !=
true;
414 # Create a fake parser tests which never run anything unless
415 # asked to do so. This will avoid running hooks for a disabled test
418 while (
false !== (
$line = fgets( $this->fh ) ) ) {
425 if ( $this->
section ==
'endarticle' ) {
429 $this->parserTest->addArticle( ParserTest::chomp( $this->sectionData[
'article'] ), $this->sectionData[
'text'], $this->lineNum );
436 if ( $this->
section ==
'endhooks' ) {
439 foreach ( explode(
"\n", $this->sectionData[
'hooks'] )
as $line ) {
443 $delayedParserTest->requireHook(
$line );
452 if ( $this->
section ==
'endfunctionhooks' ) {
455 foreach ( explode(
"\n", $this->sectionData[
'functionhooks'] )
as $line ) {
459 $delayedParserTest->requireFunctionHook(
$line );
468 if ( $this->
section ==
'end' ) {
475 if ( !isset( $this->sectionData[
'options'] ) ) {
476 $this->sectionData[
'options'] =
'';
479 if ( !isset( $this->sectionData[
'config'] ) ) {
480 $this->sectionData[
'config'] =
'';
483 if ( $input ==
false ||
$result ==
false ||
484 ( ( preg_match(
'/\\bdisabled\\b/i', $this->sectionData[
'options'] ) && !$this->parserTest->runDisabled )
485 || ( preg_match(
'/\\bparsoid\\b/i', $this->sectionData[
'options'] ) &&
$result !=
'html/php' && !$this->parserTest->runParsoid )
486 || !preg_match(
"/" . $this->parserTest->regex .
"/i", $this->sectionData[
'test'] ) )
491 # Forget any pending hooks call since test is disabled
492 $delayedParserTest->reset();
497 # We are really going to run the test, run pending hooks and hooks function
498 wfDebug( __METHOD__ .
" unleashing delayed test for: {$this->sectionData['test']}" );
499 $hooksResult = $delayedParserTest->unleash( $this->parserTest );
500 if ( !$hooksResult ) {
501 # Some hook reported an issue. Abort.
506 'test' => ParserTest::chomp( $this->sectionData[
'test'] ),
507 'input' => ParserTest::chomp( $this->sectionData[ $input ] ),
508 'result' => ParserTest::chomp( $this->sectionData[
$result ] ),
509 'options' => ParserTest::chomp( $this->sectionData[
'options'] ),
510 'config' => ParserTest::chomp( $this->sectionData[
'config'] ),
516 if ( isset( $this->sectionData[$this->
section] ) ) {
517 throw new MWException(
"duplicate section '$this->section' at line {$this->lineNum} of $this->file\n" );
537 $this->sectionData =
array();
554 if ( is_null( $this->
section ) ) {
555 throw new MWException( __METHOD__ .
" can not verify a null section!\n" );
557 if ( !is_array( $tokens ) ) {
558 $tokens =
array( $tokens );
560 if ( count( $tokens ) == 0 ) {
561 throw new MWException( __METHOD__ .
" can not verify zero sections!\n" );
565 $tokens = array_filter( $tokens,
function ( $token ) use ( $data ) {
566 return isset( $data[ $token ] );
569 if ( count( $tokens ) == 0 ) {
574 "'%s' without '%s' at line %s of %s\n",
576 implode(
',', $tokens ),
581 if ( count( $tokens ) > 1 ) {
583 "'%s' with unexpected tokens '%s' at line %s of %s\n",
585 implode(
',', $tokens ),
591 $tokens = array_values( $tokens );
615 $this->fnHooks =
array();
623 if ( !( $parserTest instanceof ParserTest || $parserTest instanceof NewParserTest ) ) {
624 throw new MWException( __METHOD__ .
" must be passed an instance of ParserTest or NewParserTest classes\n" );
627 # Trigger delayed hooks. Any failure will make us abort
628 foreach ( $this->
hooks as $hook ) {
629 $ret = $parserTest->requireHook( $hook );
635 # Trigger delayed function hooks. Any failure will make us abort
636 foreach ( $this->fnHooks
as $fnHook ) {
637 $ret = $parserTest->requireFunctionHook( $fnHook );
643 # Delayed execution was successful.
652 $this->
hooks[] = $hook;
660 $this->fnHooks[] = $fnHook;