if ( $this->total > 0 ) {
$this->reportPercentage( $this->success, $this->total );
} else {
- wfDie( "No tests found.\n" );
+ throw new MWException( "No tests found.\n" );
}
}
* and all that fun stuff
*/
function start() {
- global $wgDBtype;
$this->db->begin();
if ( ! $this->db->tableExists( 'testrun' )
'tr_uname' => php_uname()
),
__METHOD__ );
- if ( $wgDBtype === 'postgres' ) {
+ if ( $this->db->getType() === 'postgres' ) {
$this->curRun = $this->db->currentSequenceValue( 'testrun_id_seq' );
} else {
$this->curRun = $this->db->insertId();
}
}
-class RemoteTestRecorder extends TestRecorder {
- function start() {
- parent::start();
-
- $this->results = array();
- $this->ping( 'running' );
- }
-
- function record( $test, $result ) {
- parent::record( $test, $result );
- $this->results[$test] = (bool)$result;
- }
-
- function end() {
- $this->ping( 'complete', $this->results );
- parent::end();
- }
-
- /**
- * Inform a CodeReview instance that we've started or completed a test run...
- *
- * @param $status string: "running" - tell it we've started
- * "complete" - provide test results array
- * "abort" - something went horribly awry
- * @param $results array of test name => true/false
- */
- function ping( $status, $results = false ) {
- global $wgParserTestRemote, $IP;
-
- $remote = $wgParserTestRemote;
- $revId = SpecialVersion::getSvnRevision( $IP );
- $jsonResults = FormatJson::encode( $results );
-
- if ( !$remote ) {
- print "Can't do remote upload without configuring \$wgParserTestRemote!\n";
- exit( 1 );
- }
-
- // Generate a hash MAC to validate our credentials
- $message = array(
- $remote['repo'],
- $remote['suite'],
- $revId,
- $status,
- );
-
- if ( $status == "complete" ) {
- $message[] = $jsonResults;
- }
- $hmac = hash_hmac( "sha1", implode( "|", $message ), $remote['secret'] );
-
- $postData = array(
- 'action' => 'codetestupload',
- 'format' => 'json',
- 'repo' => $remote['repo'],
- 'suite' => $remote['suite'],
- 'rev' => $revId,
- 'status' => $status,
- 'hmac' => $hmac,
- );
-
- if ( $status == "complete" ) {
- $postData['results'] = $jsonResults;
- }
-
- $response = $this->post( $remote['api-url'], $postData );
-
- if ( $response === false ) {
- print "CodeReview info upload failed to reach server.\n";
- exit( 1 );
- }
-
- $responseData = FormatJson::decode( $response, true );
-
- if ( !is_array( $responseData ) ) {
- print "CodeReview API response not recognized...\n";
- wfDebug( "Unrecognized CodeReview API response: $response\n" );
- exit( 1 );
- }
-
- if ( isset( $responseData['error'] ) ) {
- $code = $responseData['error']['code'];
- $info = $responseData['error']['info'];
- print "CodeReview info upload failed: $code $info\n";
- exit( 1 );
- }
- }
-
- function post( $url, $data ) {
- return Http::post( $url, array( 'postData' => $data ) );
- }
-}
-
class TestFileIterator implements Iterator {
private $file;
private $fh;
private $lineNum;
private $eof;
- function __construct( $file, $parserTest = null ) {
+ function __construct( $file, $parserTest ) {
global $IP;
$this->file = $file;
$this->fh = fopen( $this->file, "rt" );
if ( !$this->fh ) {
- wfDie( "Couldn't open file '$file'\n" );
+ throw new MWException( "Couldn't open file '$file'\n" );
}
$this->parserTest = $parserTest;
-
- if ( $this->parserTest ) {
- $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
- }
+ $this->parserTest->showRunFile( wfRelativePath( $this->file, $IP ) );
$this->lineNum = $this->index = 0;
}
function rewind() {
if ( fseek( $this->fh, 0 ) ) {
- wfDie( "Couldn't fseek to the start of '$this->file'\n" );
+ throw new MWException( "Couldn't fseek to the start of '$this->file'\n" );
}
$this->index = -1;
if ( $section == 'endarticle' ) {
if ( !isset( $data['text'] ) ) {
- wfDie( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'endarticle' without 'text' at line {$this->lineNum} of $this->file\n" );
}
if ( !isset( $data['article'] ) ) {
- wfDie( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'endarticle' without 'article' at line {$this->lineNum} of $this->file\n" );
}
- if ( $this->parserTest ) {
- $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
- } else {wfDie("JAJA");
- ParserTest::addArticle( $data['article'], $data['text'], $this->lineNum );
- }
+ $this->parserTest->addArticle( ParserTest::chomp( $data['article'] ), $data['text'], $this->lineNum );
+
$data = array();
$section = null;
if ( $section == 'endhooks' ) {
if ( !isset( $data['hooks'] ) ) {
- wfDie( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'endhooks' without 'hooks' at line {$this->lineNum} of $this->file\n" );
}
foreach ( explode( "\n", $data['hooks'] ) as $line ) {
$line = trim( $line );
if ( $line ) {
- if ( $this->parserTest && !$this->parserTest->requireHook( $line ) ) {
+ if ( !$this->parserTest->requireHook( $line ) ) {
return false;
}
}
if ( $section == 'endfunctionhooks' ) {
if ( !isset( $data['functionhooks'] ) ) {
- wfDie( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'endfunctionhooks' without 'functionhooks' at line {$this->lineNum} of $this->file\n" );
}
foreach ( explode( "\n", $data['functionhooks'] ) as $line ) {
$line = trim( $line );
if ( $line ) {
- if ( $this->parserTest && !$this->parserTest->requireFunctionHook( $line ) ) {
+ if ( !$this->parserTest->requireFunctionHook( $line ) ) {
return false;
}
}
if ( $section == 'end' ) {
if ( !isset( $data['test'] ) ) {
- wfDie( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'end' without 'test' at line {$this->lineNum} of $this->file\n" );
}
if ( !isset( $data['input'] ) ) {
- wfDie( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'end' without 'input' at line {$this->lineNum} of $this->file\n" );
}
if ( !isset( $data['result'] ) ) {
- wfDie( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "'end' without 'result' at line {$this->lineNum} of $this->file\n" );
}
if ( !isset( $data['options'] ) ) {
if ( !isset( $data['config'] ) )
$data['config'] = '';
- if ( $this->parserTest
- && ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
+ if ( ( ( preg_match( '/\\bdisabled\\b/i', $data['options'] ) && !$this->parserTest->runDisabled )
|| !preg_match( "/" . $this->parserTest->regex . "/i", $data['test'] ) ) ) {
# disabled test
$data = array();
continue;
}
- global $wgUseTeX;
-
- if ( $this->parserTest &&
- preg_match( '/\\bmath\\b/i', $data['options'] ) && !$wgUseTeX ) {
- # don't run math tests if $wgUseTeX is set to false in LocalSettings
- $data = array();
- $section = null;
-
- continue;
- }
-
- if ( $this->parserTest ) {
- $this->test = array(
- 'test' => ParserTest::chomp( $data['test'] ),
- 'input' => ParserTest::chomp( $data['input'] ),
- 'result' => ParserTest::chomp( $data['result'] ),
- 'options' => ParserTest::chomp( $data['options'] ),
- 'config' => ParserTest::chomp( $data['config'] ) );
- } else {
- $this->test['test'] = $data['test'];
- }
+ $this->test = array(
+ 'test' => ParserTest::chomp( $data['test'] ),
+ 'input' => ParserTest::chomp( $data['input'] ),
+ 'result' => ParserTest::chomp( $data['result'] ),
+ 'options' => ParserTest::chomp( $data['options'] ),
+ 'config' => ParserTest::chomp( $data['config'] ) );
return true;
}
if ( isset ( $data[$section] ) ) {
- wfDie( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
+ throw new MWException( "duplicate section '$section' at line {$this->lineNum} of $this->file\n" );
}
$data[$section] = '';