26use Wikimedia\TestingAccessWrapper;
29require_once __DIR__ .
'/commandLine.inc';
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' ];
58 if ( !file_exists(
'results' ) ) {
61 if ( !is_dir(
'results' ) ) {
62 echo
"Unable to create 'results' directory\n";
65 $overallStart = microtime(
true );
66 $reportInterval = 1000;
68 for ( $i = 1;
true; $i++ ) {
69 $t = -microtime(
true );
72 self::$currentTest->execute();
74 }
catch ( Exception $e ) {
75 $testReport = self::$currentTest->getReport();
77 $hash = md5( $testReport );
78 file_put_contents(
"results/ppft-$hash.in",
serialize( self::$currentTest ) );
79 file_put_contents(
"results/ppft-$hash.fail",
80 "Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
81 print "Test $hash failed\n";
84 $t += microtime(
true );
87 printf(
"Test $passed in %.3f seconds\n",
$t );
88 print self::$currentTest->getReport();
91 $reportMetric = ( microtime(
true ) - $overallStart ) / $i * $reportInterval;
92 if ( $reportMetric > 25 ) {
93 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
98 } elseif ( $reportMetric < 4 ) {
99 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
100 $reportInterval *= 5;
102 $reportInterval *= 2;
105 if ( $i % $reportInterval == 0 ) {
106 print "$i tests done\n";
116 if ( $max ===
false ) {
119 $length = mt_rand( $this->minLength, $max );
121 for ( $i = 0; $i < $length; $i++ ) {
122 $hairIndex = mt_rand( 0, count( $this->hairs ) - 1 );
123 $s .= $this->hairs[$hairIndex];
129 $s = MediaWikiServices::getInstance()->getContentLanguage()->normalize(
$s );
135 return Title::newFromText( mt_rand( 0, 1000000 ), mt_rand( 0, 10 ) );
145 $count = count( $this->entryPoints );
147 return $this->entryPoints[mt_rand( 0, $count - 1 )];
171 $this->parent = $tester;
172 $this->mainText = $tester->makeInputText();
173 $this->title = $tester->makeTitle();
175 $this->entryPoint = $tester->pickEntryPoint();
177 $this->fancySig = (bool)mt_rand( 0, 1 );
178 $this->templates = [];
186 $titleText =
$title->getPrefixedDBkey();
188 if ( !isset( $this->templates[$titleText] ) ) {
190 if ( count( $this->templates ) >= $this->parent->maxTemplates ) {
194 if ( !mt_rand( 0, 1 ) ) {
196 $finalTitle = $this->parent->makeTitle();
198 if ( !mt_rand( 0, 5 ) ) {
202 $text = $this->parent->makeInputText();
205 $this->templates[$titleText] = [
207 'finalTitle' => $finalTitle ];
210 return $this->templates[$titleText];
217 $user->mName =
'Fuzz';
218 $user->mFrom =
'name';
219 $user->ppfz_test = $this;
223 $options = ParserOptions::newFromUser( $user );
224 $options->setTemplateCallback( [ $this,
'templateHook' ] );
226 $this->output = call_user_func(
227 [ TestingAccessWrapper::newFromObject(
228 MediaWikiServices::getInstance()->getParser()
229 ), $this->entryPoint ],
239 $s =
"Title: " . $this->title->getPrefixedDBkey() .
"\n" .
241 "Entry point: {$this->entryPoint}\n" .
242 "User: " . ( $this->fancySig ?
'fancy' :
'no-fancy' ) .
243 ' ' . var_export( $this->nickname,
true ) .
"\n" .
244 "Main text: " . var_export( $this->mainText,
true ) .
"\n";
245 foreach ( $this->templates as $titleText => $template ) {
246 $finalTitle = $template[
'finalTitle'];
247 if ( $finalTitle != $titleText ) {
248 $s .=
"[[$titleText]] -> [[$finalTitle]]: " . var_export( $template[
'text'],
true ) .
"\n";
250 $s .=
"[[$titleText]]: " . var_export( $template[
'text'],
true ) .
"\n";
253 $s .=
"Output: " . var_export( $this->output,
true ) .
"\n";
262 public function load( $flags =
null ) {
263 if ( $this->mDataLoaded ) {
266 $this->mDataLoaded =
true;
270 public function getOption( $oname, $defaultOverride =
null, $ignoreHidden =
false ) {
271 if ( $oname ===
'fancysig' ) {
272 return $this->ppfz_test->fancySig;
273 } elseif ( $oname ===
'nickname' ) {
274 return $this->ppfz_test->nickname;
276 return parent::getOption( $oname, $defaultOverride, $ignoreHidden );
281ini_set(
'memory_limit',
'50M' );
282if ( isset(
$args[0] ) ) {
283 $testText = file_get_contents(
$args[0] );
285 print "File not found\n";
289 $result = $test->execute();
290 print "Test passed.\n";
293 $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.
array[] $templates
-var array<string,array{text:string|false,finalTitle:Title}>
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.
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