} elseif( wfIsWindows() ) {
$this->color = false;
} else {
- $this->color = true;
+ # Only colorize output if stdout is a terminal.
+ $this->color = posix_isatty(1);
}
if( isset( $_SERVER['argv'] ) && in_array( '--quick', $_SERVER['argv'] ) ) {
$this->showDiffs = true;
}
}
-
+
+ /**
+ * Remove last character if it is a newline
+ * @access private
+ */
+ function chomp($s) {
+ if (substr($s, -1) === "\n") {
+ return substr($s, 0, -1);
+ }
+ else {
+ return $s;
+ }
+ }
/**
* Run a series of tests listed in the given text file.
if( !isset( $data['article'] ) ) {
die( "'endarticle' without 'article' at line $n\n" );
}
- $this->addArticle(rtrim($data['article']), rtrim($data['text']));
+ $this->addArticle($this->chomp($data['article']), $this->chomp($data['text']));
$data = array();
$section = null;
continue;
if( !isset( $data['options'] ) ) {
$data['options'] = '';
}
+ else {
+ $data['options'] = $this->chomp( $data['options'] );
+ }
if( $this->runTest(
- rtrim( $data['test'] ),
- rtrim( $data['input'] ),
- rtrim( $data['result'] ),
- rtrim( $data['options'] ) ) ) {
+ $this->chomp( $data['test'] ),
+ $this->chomp( $data['input'] ),
+ $this->chomp( $data['result'] ),
+ $this->chomp( $data['options'] ) ) ) {
$success++;
}
$total++;
#if (preg_match('/cat/i', $opts)) {
# $out .= $output->getCategoryLinks();
#}
- }
- global $wgUseTidy;
- if ($wgUseTidy) {
- # Using Parser here is probably theoretically
- # wrong, because we shouldn't use Parser to
- # validate itself, but this should be safe
- # in practice.
- $result = Parser::tidy($result);
+ if ($GLOBALS['wgUseTidy']) {
+ $result = Parser::tidy($result);
+ }
}
$this->teardownGlobals();
- if( rtrim($result) === rtrim($out) ) {
+ if( $result === $out ) {
return $this->showSuccess( $desc );
} else {
return $this->showFailure( $desc, $result, $out );
*/
function dumpToFile( $data, $filename ) {
$file = fopen( $filename, "wt" );
- fwrite( $file, rtrim( $data ) . "\n" );
+ fwrite( $file, $data . "\n" );
fclose( $file );
}
* @access private
*/
function addArticle($name, $text) {
+ # TODO: check if article exists and die gracefully
+ # if we are trying to insert a duplicate
$this->setupGlobals();
$title = Title::newFromText( $name );
$art = new Article($title);
-- HACK: this should go away when there is a better way
-CREATE TEMPORARY TEMPORARY TABLE parsertestuser (
+CREATE TEMPORARY TABLE parsertestuser (
user_id int(5) unsigned NOT NULL auto_increment,
user_name varchar(255) binary NOT NULL default '',
user_real_name varchar(255) binary NOT NULL default '',
INDEX user_name (user_name(10))
);
-CREATE TEMPORARY TEMPORARY TABLE parsertestcur (
+CREATE TEMPORARY TABLE parsertestcur (
cur_id int(8) unsigned NOT NULL auto_increment,
cur_namespace tinyint(2) unsigned NOT NULL default '0',
cur_title varchar(255) binary NOT NULL default '',
KEY (l_to)
);
-CREATE TEMPORARY TEMPORARY TABLE parsertestbrokenlinks (
+CREATE TEMPORARY TABLE parsertestbrokenlinks (
bl_from int(8) unsigned NOT NULL default '0',
bl_to varchar(255) binary NOT NULL default '',
UNIQUE KEY bl_from(bl_from,bl_to),
KEY (bl_to)
);
-CREATE TEMPORARY TEMPORARY TABLE parsertestimagelinks (
+CREATE TEMPORARY TABLE parsertestimagelinks (
il_from int(8) unsigned NOT NULL default '0',
il_to varchar(255) binary NOT NULL default '',
UNIQUE KEY il_from(il_from,il_to),