24 require_once __DIR__ .
'/commandLine.inc';
26 $wgHooks[
'BeforeParserFetchTemplateAndtitle'][] =
'PPFuzzTester::templateHook';
30 '[[',
']]',
'{{',
'{{',
'}}',
'}}',
'{{{',
'}}}',
31 '<',
'>',
'<nowiki',
'<gallery',
'</nowiki>',
'</gallery>',
'<nOwIkI>',
'</NoWiKi>',
34 '|',
'=',
"\n",
' ',
"\t",
"\x7f",
35 '~~',
'~~~',
'~~~~',
'subst:',
36 'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
37 'k',
'l',
'm',
'n',
'o',
'p',
'q',
'r',
's',
't',
51 if ( !file_exists(
'results' ) ) {
54 if ( !is_dir(
'results' ) ) {
55 echo
"Unable to create 'results' directory\n";
58 $overallStart = microtime(
true );
59 $reportInterval = 1000;
60 for ( $i = 1;
true; $i++ ) {
61 $t = -microtime(
true );
64 self::$currentTest->execute();
67 $testReport = self::$currentTest->getReport();
68 $exceptionReport =
$e->getText();
69 $hash = md5( $testReport );
70 file_put_contents(
"results/ppft-$hash.in", serialize( self::$currentTest ) );
71 file_put_contents(
"results/ppft-$hash.fail",
72 "Input:\n$testReport\n\nException report:\n$exceptionReport\n" );
73 print
"Test $hash failed\n";
76 $t += microtime(
true );
79 printf(
"Test $passed in %.3f seconds\n",
$t );
80 print self::$currentTest->getReport();
83 $reportMetric = ( microtime(
true ) - $overallStart ) / $i * $reportInterval;
84 if ( $reportMetric > 25 ) {
85 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
90 } elseif ( $reportMetric < 4 ) {
91 if ( substr( $reportInterval, 0, 1 ) ===
'1' ) {
97 if ( $i % $reportInterval == 0 ) {
98 print
"$i tests done\n";
108 if ( $max ===
false ) {
111 $length = mt_rand( $this->minLength, $max );
113 for ( $i = 0; $i < $length; $i++ ) {
114 $hairIndex = mt_rand( 0, count( $this->hairs ) - 1 );
115 $s .= $this->hairs[$hairIndex];
137 $count = count( $this->entryPoints );
138 return $this->entryPoints[ mt_rand( 0,
$count - 1 ) ];
148 $this->mainText =
$tester->makeInputText();
151 $this->entryPoint =
$tester->pickEntryPoint();
152 $this->nickname =
$tester->makeInputText( $wgMaxSigChars + 10 );
153 $this->fancySig = (bool)mt_rand( 0, 1 );
154 $this->templates =
array();
161 $titleText =
$title->getPrefixedDBkey();
163 if ( !isset( $this->templates[$titleText] ) ) {
165 if ( count( $this->templates ) >= $this->parent->maxTemplates ) {
169 if ( !mt_rand( 0, 1 ) ) {
171 $finalTitle = $this->parent->makeTitle();
173 if ( !mt_rand( 0, 5 ) ) {
177 $text = $this->parent->makeInputText();
180 $this->templates[$titleText] =
array(
182 'finalTitle' => $finalTitle );
184 return $this->templates[$titleText];
196 $options->setTemplateCallback(
array( $this,
'templateHook' ) );
203 $s =
"Title: " . $this->
title->getPrefixedDBkey() .
"\n" .
205 "Entry point: {$this->entryPoint}\n" .
206 "User: " . ( $this->fancySig ?
'fancy' :
'no-fancy' ) .
' ' . var_export( $this->nickname,
true ) .
"\n" .
207 "Main text: " . var_export( $this->mainText,
true ) .
"\n";
208 foreach ( $this->templates
as $titleText => $template ) {
209 $finalTitle = $template[
'finalTitle'];
210 if ( $finalTitle != $titleText ) {
211 $s .=
"[[$titleText]] -> [[$finalTitle]]: " . var_export( $template[
'text'],
true ) .
"\n";
213 $s .=
"[[$titleText]]: " . var_export( $template[
'text'],
true ) .
"\n";
216 $s .=
"Output: " . var_export( $this->
output,
true ) .
"\n";
225 if ( $this->mDataLoaded ) {
228 $this->mDataLoaded =
true;
232 function getOption( $oname, $defaultOverride =
null, $ignoreHidden =
false ) {
233 if ( $oname ===
'fancysig' ) {
234 return $this->ppfz_test->fancySig;
235 } elseif ( $oname ===
'nickname' ) {
236 return $this->ppfz_test->nickname;
238 return parent::getOption( $oname, $defaultOverride, $ignoreHidden );
243 ini_set(
'memory_limit',
'50M' );
244 if ( isset(
$args[0] ) ) {
245 $testText = file_get_contents(
$args[0] );
247 print
"File not found\n";
250 $test = unserialize( $testText );
252 print
"Test passed.\n";