26use Wikimedia\TestingAccessWrapper;
29require_once __DIR__ .
'/CommandLineInc.php';
33 '[[',
']]',
'{{',
'{{',
'}}',
'}}',
'{{{',
'}}}',
34 '<',
'>',
'<nowiki',
'<gallery',
'</nowiki>',
'</gallery>',
'<nOwIkI>',
'</NoWiKi>',
37 '|',
'=',
"\n",
' ',
"\t",
"\x7f",
38 '~~',
'~~~',
'~~~~',
'subst:',
39 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
40 'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
49 public $entryPoints = [
'fuzzTestSrvus',
'fuzzTestPst',
'fuzzTestPreprocess' ];
61 if ( !file_exists(
'results' ) ) {
64 if ( !is_dir(
'results' ) ) {
65 echo
"Unable to create 'results' directory\n";
68 $overallStart = microtime(
true );
69 $reportInterval = 1000;
71 for ( $i = 1;
true; $i++ ) {
72 $t = -microtime(
true );
75 self::$currentTest->execute();
77 }
catch ( Exception $e ) {
78 $testReport = self::$currentTest->getReport();
80 $hash = md5( $testReport );
81 file_put_contents(
"results/ppft-$hash.in",
serialize( self::$currentTest ) );
82 file_put_contents(
"results/ppft-$hash.fail",
83 "Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
84 print "Test $hash failed\n";
87 $t += microtime(
true );
90 printf(
"Test $passed in %.3f seconds\n",
$t );
91 print self::$currentTest->getReport();
94 $reportMetric = ( microtime(
true ) - $overallStart ) / $i * $reportInterval;
95 if ( $reportMetric > 25 ) {
96 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
101 } elseif ( $reportMetric < 4 ) {
102 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
103 $reportInterval *= 5;
105 $reportInterval *= 2;
108 if ( $i % $reportInterval == 0 ) {
109 print "$i tests done\n";
119 if ( $max ===
false ) {
122 $length = mt_rand( $this->minLength, $max );
124 for ( $i = 0; $i < $length; $i++ ) {
125 $hairIndex = mt_rand( 0, count( $this->hairs ) - 1 );
126 $s .= $this->hairs[$hairIndex];
132 $s = MediaWikiServices::getInstance()->getContentLanguage()->normalize(
$s );
138 return Title::newFromText( mt_rand( 0, 1000000 ), mt_rand( 0, 10 ) );
148 $count = count( $this->entryPoints );
150 return $this->entryPoints[mt_rand( 0, $count - 1 )];
174 $this->parent = $tester;
175 $this->mainText = $tester->makeInputText();
176 $this->title = $tester->makeTitle();
178 $this->entryPoint = $tester->pickEntryPoint();
180 $this->fancySig = (bool)mt_rand( 0, 1 );
181 $this->templates = [];
189 $titleText =
$title->getPrefixedDBkey();
191 if ( !isset( $this->templates[$titleText] ) ) {
193 if ( count( $this->templates ) >= $this->parent->maxTemplates ) {
197 if ( !mt_rand( 0, 1 ) ) {
199 $finalTitle = $this->parent->makeTitle();
201 if ( !mt_rand( 0, 5 ) ) {
205 $text = $this->parent->makeInputText();
208 $this->templates[$titleText] = [
210 'finalTitle' => $finalTitle ];
213 return $this->templates[$titleText];
218 $user->mName =
'Fuzz';
219 $user->mFrom =
'name';
220 $user->ppfz_test = $this;
224 $options = ParserOptions::newFromUser( $user );
225 $options->setTemplateCallback( [ $this,
'templateHook' ] );
227 $this->output = call_user_func(
228 [ TestingAccessWrapper::newFromObject(
229 MediaWikiServices::getInstance()->getParser()
230 ), $this->entryPoint ],
240 $s =
"Title: " . $this->title->getPrefixedDBkey() .
"\n" .
242 "Entry point: {$this->entryPoint}\n" .
243 "User: " . ( $this->fancySig ?
'fancy' :
'no-fancy' ) .
244 ' ' . var_export( $this->nickname,
true ) .
"\n" .
245 "Main text: " . var_export( $this->mainText,
true ) .
"\n";
246 foreach ( $this->templates as $titleText => $template ) {
247 $finalTitle = $template[
'finalTitle'];
248 if ( $finalTitle != $titleText ) {
249 $s .=
"[[$titleText]] -> [[$finalTitle]]: " . var_export( $template[
'text'],
true ) .
"\n";
251 $s .=
"[[$titleText]]: " . var_export( $template[
'text'],
true ) .
"\n";
254 $s .=
"Output: " . var_export( $this->output,
true ) .
"\n";
263 public function load( $flags =
null ) {
264 if ( $this->mDataLoaded ) {
267 $this->mDataLoaded =
true;
271 public function getOption( $oname, $defaultOverride =
null, $ignoreHidden =
false ) {
272 if ( $oname ===
'fancysig' ) {
273 return $this->ppfz_test->fancySig;
274 } elseif ( $oname ===
'nickname' ) {
275 return $this->ppfz_test->nickname;
277 return parent::getOption( $oname, $defaultOverride, $ignoreHidden );
282ini_set(
'memory_limit',
'50M' );
283if ( isset(
$args[0] ) ) {
284 $testText = file_get_contents(
$args[0] );
286 print "File not found\n";
290 $result = $test->execute();
291 print "Test passed.\n";
294 $tester->verbose = isset( $options[
'verbose'] );
unserialize( $serialized)
$wgMaxSigChars
Maximum number of Unicode characters in signature.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
getText()
Get the text to display when reporting the error on the command line.
static bool PPFuzzTest $currentTest
makeInputText( $max=false)
load( $flags=null)
Load the user table data for this object from the source given by mFrom.
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
static setUser( $user)
Reset the stub global user to a different "real" user object, while ensuring that any method calls on...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
loadDefaults( $name=false, $actorId=null)
Set cached properties to default.
while(( $__line=Maintenance::readconsole()) !==false) print
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s