X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FparserTests.php;h=274356f18e5cdeb94feb4d7b3c79e85084024173;hb=a8f6c1efc39ddcfc8f06dba46993f9a4b2c07eb2;hp=3726d65bb3ee4b8bb57d3a35ab4d8fe246345cf9;hpb=dd92d82b111f388fe16091939c704dfcfa4c561f;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/parserTests.php b/maintenance/parserTests.php index 3726d65bb3..274356f18e 100644 --- a/maintenance/parserTests.php +++ b/maintenance/parserTests.php @@ -1,112 +1,71 @@ +# http://www.mediawiki.org/ +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# http://www.gnu.org/copyleft/gpl.html + /** - * @todo document * @package MediaWiki * @subpackage Maintenance */ /** */ -require_once( 'commandLine.inc' ); -include_once( 'InitialiseMessages.inc' ); +require('parserTests.inc'); -$wgTitle = Title::newFromText( 'Parser test script' ); +if( isset( $options['help'] ) ) { + echo <<] [--file=] + [--record] + [--help] +Options: + --quick Suppress diff output of failed tests + --quiet Suppress notification of passed tests (shows only failed tests) + --show-output Show expected and actual output + --color Override terminal detection and force color output on or off + use wgCommandLineDarkBg = true; if your term is dark + --regex Only run tests whose descriptions which match given regex + --file Run test cases from a custom file instead of parserTests.txt + --record Record tests in database + --help Show this help message -class ParserTest { - function runTestsFromFile( $filename ) { - $infile = fopen( $filename, 'rt' ); - if( !$infile ) { - die( "Couldn't open parserTests.txt\n" ); - } - - $data = array(); - $section = null; - $success = 0; - $total = 0; - $n = 0; - while( false !== ($line = fgets( $infile ) ) ) { - $n++; - if( preg_match( '/^!!\s*(\w+)/', $line, $matches ) ) { - $section = strtolower( $matches[1] ); - if( $section == 'end' ) { - if (isset ($data['disabled'])) { - # disabled test - $data = array(); - $section = null; - continue; - } - if( !isset( $data['test'] ) ) { - die( "'end' without 'test' at line $n\n" ); - } - if( !isset( $data['input'] ) ) { - die( "'end' without 'input' at line $n\n" ); - } - if( !isset( $data['result'] ) ) { - die( "'end' without 'result' at line $n\n" ); - } - if( $this->runTest( - rtrim( $data['test'] ), - rtrim( $data['input'] ), - rtrim( $data['result'] ) ) ) { - $success++; - } - $total++; - $data = array(); - $section = null; - continue; - } - $data[$section] = ''; - continue; - } - if( $section ) { - $data[$section] .= $line; - } - } - if( $total > 0 ) { - $ratio = IntVal( 100.0 * $success / $total ); - print "\nPassed $success of $total tests ($ratio%)\n"; - } - } - /** - * @param string $input Wikitext to try rendering - * @param string $result Result to output - * @return bool - */ - function runTest( $desc, $input, $result ) { - print "Running test $desc..."; +ENDS; + exit( 0 ); +} - $user =& new User(); - $options =& ParserOptions::newFromUser( $user ); - $parser =& new Parser(); - $title =& Title::makeTitle( NS_MAIN, 'Parser_test' ); +# There is a convention that the parser should never +# refer to $wgTitle directly, but instead use the title +# passed to it. +$wgTitle = Title::newFromText( 'Parser test script do not use' ); +$tester = new ParserTest(); - $output =& $parser->parse( $input, $title, $options ); - - $html = $output->getText(); - # $languageLinks = $output->getLanguageLinks(); - # $categoryLinks = $output->getCategoryLinks(); - - if( $result == rtrim( $html ) ) { - return $this->showSuccess( $desc ); - } else { - return $this->showFailure( $desc, $result, $html ); - } - } - - function showSuccess( $desc ) { - print "ok\n"; - return true; - } - - function showFailure( $desc, $result, $html ) { - print "FAILED\n"; - print "!! Expected:\n$result\n"; - print "!! Received:\n$html\n!!\n"; - return false; - } +if( isset( $options['file'] ) ) { + $files = array( $options['file'] ); +} else { + // Default parser tests and any set from extensions or local config + $files = $wgParserTestFiles; } -$tester =& new ParserTest(); -$tester->runTestsFromFile( 'maintenance/parserTests.txt' ); +# Print out software version to assist with locating regressions +$version = SpecialVersion::getVersion(); +echo( "This is MediaWiki version {$version}.\n\n" ); +$ok = $tester->runTestsFromFiles( $files ); +exit ($ok ? 0 : -1); ?>