Some tweaks to the test tree:

* Moved Test.php to t/Test.php
* Updated t/inc/Languages.t so that it doesn't throw a fatal error because $wgMemc isn't set when creating the Laguage object
* Added  t/inc/Parser.t, a version of the parser tests with TAP output. I modified some methods of the ParserTests class so that i can extend it in t/inc/Parser.t to modify the format of the output.
* Killed ending ?> tags in PHP tests
This commit is contained in:
Alexandre Emsenhuber 2008-03-28 16:11:36 +00:00
parent e932be4752
commit a41b7035dc
11 changed files with 82 additions and 47 deletions

View file

@ -15,11 +15,11 @@ MAINTENANCE_TESTS=$(wildcard t/maint/*t)
FAST_TESTS=$(BASE_TEST) $(INCLUDES_TESTS)
ALL_TESTS=$(BASE_TEST) $(INCLUDES_TESTS) $(MAINTENANCE_TESTS)
test: Test.php
test: t/Test.php
$(PROVE_BIN) $(ALL_TESTS)
fast: Test.php
fast: t/Test.php
$(PROVE_BIN) $(FAST_TESTS)
verbose: Test.php
verbose: t/Test.php
$(PROVE_BIN) -v $(ALL_TESTS) | egrep -v '^ok'

View file

@ -142,10 +142,7 @@ class ParserTest {
} else {
global $IP;
$relative = wfRelativePath( $filename, $IP );
print $this->term->color( 1 ) .
"Reading tests from \"$relative\"..." .
$this->term->reset() .
"\n";
$this->showRunFile( $relative );
}
$data = array();
@ -646,7 +643,7 @@ class ParserTest {
/**
* "Running test $desc..."
*/
private function showTesting( $desc ) {
protected function showTesting( $desc ) {
print "Running test $desc... ";
}
@ -656,7 +653,7 @@ class ParserTest {
* @param string $desc The test name
* @return bool
*/
private function showSuccess( $desc ) {
protected function showSuccess( $desc ) {
if( $this->showProgress ) {
print $this->term->color( '1;32' ) . 'PASSED' . $this->term->reset() . "\n";
}
@ -672,7 +669,7 @@ class ParserTest {
* @param string $html Actual HTML output
* @return bool
*/
private function showFailure( $desc, $result, $html ) {
protected function showFailure( $desc, $result, $html ) {
if( $this->showFailure ) {
if( !$this->showProgress ) {
# In quiet mode we didn't show the 'Testing' message before the
@ -703,7 +700,7 @@ class ParserTest {
* @param string $outFileTail Tailing for the output file name
* @return string
*/
private function quickDiff( $input, $output, $inFileTail='expected', $outFileTail='actual' ) {
protected function quickDiff( $input, $output, $inFileTail='expected', $outFileTail='actual' ) {
$prefix = wfTempDir() . "/mwParser-" . mt_rand();
$infile = "$prefix-$inFileTail";
@ -738,7 +735,7 @@ class ParserTest {
* @param string $text
* @return string
*/
private function colorDiff( $text ) {
protected function colorDiff( $text ) {
return preg_replace(
array( '/^(-.*)$/m', '/^(\+.*)$/m' ),
array( $this->term->color( 34 ) . '$1' . $this->term->reset(),
@ -746,6 +743,18 @@ class ParserTest {
$text );
}
/**
* Show "Reading tests from ..."
*
* @param String $path
*/
protected function showRunFile( $path ){
print $this->term->color( 1 ) .
"Reading tests from \"$path\"..." .
$this->term->reset() .
"\n";
}
/**
* Insert a temporary test article
* @param string $name the title, including any prefix

View file

@ -6,17 +6,15 @@ F<t> - MediaWiki test tree
This is the MediaWiki test tree (well, one of them), tests in this
directory are self-contained programs that produce TAP output via the
F<Test.php> module (/trunk/Test/Test.php) (see
F<Test.php> module (/trunk/phase3/t/Test.php) (see
http://search.cpan.org/~petdance/TAP-1.00/TAP.pm#THE_TAP_FORMAT for
information on the TAP format).
=head1 Running the tests
You'll need F<Test.php> to run the tests, it lives in the
F<trunk/Test> directory and can be copied or linked to the F<phase3>
directory.
To run all tests, you can run
ln -s ../Test/Test.php .
make test
Since the tests are self-contained PHP programs you can run them
(Xml.t here) as:

View file

@ -494,5 +494,3 @@ code under copyright law.
=cut
*/
?>

View file

@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
require 'Test.php';
require 't/Test.php';
plan( 1120 );
@ -58,4 +58,3 @@ foreach ( $private as $p ) {
}
/* vim: set filetype=php: */
?>

View file

@ -1,18 +1,18 @@
#!/usr/bin/env php
<?php
require 'Test.php';
require 't/Test.php';
# Test offset usage for a given language::userAdjust
function test_userAdjust( $langObj, $date, $offset, $expected ) {
function test_userAdjust( &$langObj, $date, $offset, $expected ) {
global $wgLocalTZoffset;
$wgLocalTZoffset = $offset;
cmp_ok(
$langObj->userAdjust( $date, '' ),
strval( $langObj->userAdjust( $date, '' ) ),
'==',
$expected,
"User adjust $date by $offset minutes should give $expected"
strval( $expected ),
"User adjust {$date} by {$offset} minutes should give {$expected}"
);
}
@ -31,25 +31,22 @@ $userAdjust_tests = array(
array( 20061231235959, -60, 20061231225959 ),
);
plan( 7 + count($userAdjust_tests) );
require_ok( 'includes/Defines.php' );
# require_ok() doesn't work for these, find out why
plan( count($userAdjust_tests) );
define( 'MEDIAWIKI', 1 );
# Don't use require_ok as these files need global variables
require 'includes/Defines.php';
require 'includes/ProfilerStub.php';
require 'LocalSettings.php';
require 'includes/DefaultSettings.php';
require 'includes/Setup.php';
# Create a language object
require_ok( 'languages/Language.php' );
require_ok( 'includes/Title.php' );
$wgContLang = $en = Language::factory( 'en' );
# We need an user to test the lang
require_ok( 'includes/GlobalFunctions.php' );
require_ok( 'includes/ProfilerStub.php' );
require_ok( 'includes/Exception.php' );
require_ok( 'includes/User.php' );
global $wgUser;
$wgUser = new User();
@ -59,4 +56,3 @@ foreach( $userAdjust_tests as $data ) {
}
/* vim: set filetype=php: */
?>

View file

@ -1,6 +1,6 @@
#!/usr/bin/env php
<?php
require 'Test.php';
require 't/Test.php';
plan(3);
@ -24,4 +24,3 @@ $str = "
#echo $lc->html;
/* vim: set filetype=php: */
?>

39
t/inc/Parser.t Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env php
<?php
require 't/Test.php';
require 'maintenance/parserTests.inc';
error_reporting( E_ALL ^ E_NOTICE );
class ProveTestRecorder extends TestRecorder {
function record( $name, $res ){}
function report(){}
function reportPercentage( $success, $total ){}
}
class ProveParserTest extends ParserTest {
function showSuccess( $desc ){
pass( $desc );
}
function showFailure( $desc, $exp, $got ){
_proclaim( false, $desc, false, $got, $exp );
}
function showRunFile( $path ){}
}
$options = array( 'quick', 'quiet', 'compare' );
$tester = new ProveParserTest();
$tester->showProgress = false;
$tester->showFailure = false;
$tester->recorder = new ProveTestRecorder( $tester->term );
// Do not output the number of tests, if will be done automatically at the end
$tester->runTestsFromFiles( $wgParserTestFiles );
/* vim: set filetype=php: */

View file

@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
require 'Test.php';
require 't/Test.php';
plan( 13 );
@ -62,4 +62,3 @@ cmp_ok(
);
/* vim: set filetype=php: */
?>

View file

@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
require 'Test.php';
require 't/Test.php';
plan( 2 + 255 );
@ -30,4 +30,3 @@ foreach ( range( 1, 255 ) as $num ) {
}
/* vim: set filetype=php: */
?>

View file

@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php
require 'Test.php';
require 't/Test.php';
plan( 8 );
@ -54,4 +54,3 @@ cmp_ok(
cmp_ok( Xml::closeElement( 'element' ), '==', '</element>', 'closeElement() shortcut' );
/* vim: set filetype=php: */
?>