ParserTest Class Reference
[Maintenance]

Inherited by PTShell.

List of all members.

Public Member Functions

 ParserTest ()
 Sets terminal colorization and diff/quick modes depending on OS and command-line options (--color and --quick).
 chomp ($s)
 Remove last character if it is a newline.
 fuzzTest ($filenames)
 Run a fuzz test series Draw input from a set of test files.
 getFuzzInput ($filenames)
 Get an input dictionary from a set of parser test files.
 getMemoryBreakdown ()
 Get a memory usage breakdown.
 abort ()
 runTestsFromFiles ($filenames)
 Run a series of tests listed in the given text files.
 runTests ($tests)
 getParser ()
 Get a Parser object.
 runTest ($desc, $input, $result, $opts, $config)
 Run a given wikitext input through a freshly-constructed wiki parser, and compare the output against the expected results.
 setupDatabase ()
 Set up a temporary set of wiki tables to work with for the tests.
 changeLBPrefix ($lb, $prefix)
 changeDBPrefix ($db, $prefix)
 showRunFile ($path)
 Show "Reading tests from ...".
 addArticle ($name, $text, $line)
 Insert a temporary test article.
 requireHook ($name)
 Steal a callback function from the primary parser, save it for application to our scary parser.

Protected Member Functions

 changePrefix ($prefix)
 Change the table prefix on all open DB connections/.
 showTesting ($desc)
 "Running test $desc..."
 showSuccess ($desc)
 Print a happy success message.
 showFailure ($desc, $result, $html)
 Print a failure message and provide some explanatory output about what went wrong if so configured.
 quickDiff ($input, $output, $inFileTail='expected', $outFileTail='actual')
 Run given strings through a diff and return the (colorized) output.
 colorDiff ($text)
 Colorize unified diff output if set for ANSI color output.

Private Member Functions

 parseOptions ($instring)
 cleanupOption ($opt)
 setupGlobals ($opts= '', $config= '')
 Set up the global variables for a consistent environment for each test.
 listTables ()
 List of temporary tables to create, without prefix.
 teardownDatabase ()
 setupUploadDir ()
 Create a dummy uploads directory which will contain a couple of files in order to pass existence tests.
 teardownGlobals ()
 Restore default values and perform any necessary clean-up after each test runs.
 teardownUploadDir ($dir)
 Remove the dummy uploads directory.
 dumpToFile ($data, $filename)
 Write the given string to a file, adding a final newline.
 requireFunctionHook ($name)
 Steal a callback function from the primary parser, save it for application to our scary parser.
 tidy ($text)
 wellFormed ($text)
 extractFragment ($text, $position)

Static Private Member Functions

static getOptionValue ($key, $opts, $default)
 Use a regex to find out the value of an option.
static deleteFiles ($files)
 Delete the specified files, if they exist.
static deleteDirs ($dirs)
 Delete the specified directories, if they exist.

Private Attributes

 $color
 boolean $color whereas output should be colorized
 $showOutput
 boolean $showOutput Show test output
 $useTemporaryTables = true
 boolean $useTemporaryTables Use temporary tables for the temporary database
 $databaseSetupDone = false
 boolean $databaseSetupDone True if the database has been set up
 $oldTablePrefix
 string $oldTablePrefix Original table prefix
 $maxFuzzTestLength = 300
 $fuzzSeed = 0
 $memoryLimit = 50


Detailed Description

Definition at line 41 of file parserTests.inc.


Member Function Documentation

ParserTest::abort (  ) 

Definition at line 261 of file parserTests.inc.

Referenced by fuzzTest().

ParserTest::addArticle ( name,
text,
line 
)

Insert a temporary test article.

Parameters:
string $name the title, including any prefix
string $text the article text
int $line the input line number, for reporting errors

Definition at line 1024 of file parserTests.inc.

References $name, $title, Title::newFromText(), setupGlobals(), teardownGlobals(), and wfDie().

ParserTest::changeDBPrefix ( db,
prefix 
)

Definition at line 761 of file parserTests.inc.

ParserTest::changeLBPrefix ( lb,
prefix 
)

Definition at line 757 of file parserTests.inc.

ParserTest::changePrefix ( prefix  )  [protected]

Change the table prefix on all open DB connections/.

Definition at line 751 of file parserTests.inc.

References $wgDBprefix, and wfGetLBFactory().

Referenced by setupDatabase(), and teardownDatabase().

ParserTest::chomp ( s  ) 

Remove last character if it is a newline.

Definition at line 143 of file parserTests.inc.

References $s.

ParserTest::cleanupOption ( opt  )  [private]

Definition at line 475 of file parserTests.inc.

Referenced by parseOptions().

ParserTest::colorDiff ( text  )  [protected]

Colorize unified diff output if set for ANSI color output.

Subtractions are colored blue, additions red.

Parameters:
string $text
Returns:
string

Definition at line 998 of file parserTests.inc.

Referenced by quickDiff().

static ParserTest::deleteDirs ( dirs  )  [static, private]

Delete the specified directories, if they exist.

Must be empty.

Parameters:
array $dirs full paths to directories to delete.

Definition at line 895 of file parserTests.inc.

References $dirs.

Referenced by teardownUploadDir().

static ParserTest::deleteFiles ( files  )  [static, private]

Delete the specified files, if they exist.

Parameters:
array $files full paths to files to delete.

Definition at line 883 of file parserTests.inc.

References $files.

Referenced by teardownUploadDir().

ParserTest::dumpToFile ( data,
filename 
) [private]

Write the given string to a file, adding a final newline.

Parameters:
string $data
string $filename

Definition at line 985 of file parserTests.inc.

References $filename.

Referenced by quickDiff().

ParserTest::extractFragment ( text,
position 
) [private]

Definition at line 1114 of file parserTests.inc.

Referenced by wellFormed().

ParserTest::fuzzTest ( filenames  ) 

Run a fuzz test series Draw input from a set of test files.

Definition at line 156 of file parserTests.inc.

References $input, $name, $title, abort(), getFuzzInput(), getMemoryBreakdown(), getParser(), Title::makeTitle(), ParserOptions::newFromUser(), setupDatabase(), setupGlobals(), and teardownGlobals().

ParserTest::getFuzzInput ( filenames  ) 

Get an input dictionary from a set of parser test files.

Definition at line 222 of file parserTests.inc.

References $filename.

Referenced by fuzzTest().

ParserTest::getMemoryBreakdown (  ) 

Get a memory usage breakdown.

Definition at line 237 of file parserTests.inc.

References $classes, and $name.

Referenced by fuzzTest().

static ParserTest::getOptionValue ( key,
opts,
default 
) [static, private]

Use a regex to find out the value of an option.

Parameters:
$key name of option val to retrieve
$opts Options array to look in
$defaults Default value returned if not found

Definition at line 410 of file parserTests.inc.

Referenced by setupGlobals().

ParserTest::getParser (  ) 

Get a Parser object.

Definition at line 306 of file parserTests.inc.

References $wgParserConf, and wfRunHooks().

Referenced by fuzzTest(), and runTest().

ParserTest::listTables (  )  [private]

List of temporary tables to create, without prefix.

Some of these probably aren't necessary.

Definition at line 595 of file parserTests.inc.

References $wgDBtype, and wfRunHooks().

Referenced by setupDatabase().

ParserTest::parseOptions ( instring  )  [private]

Definition at line 419 of file parserTests.inc.

References cleanupOption().

Referenced by runTest().

ParserTest::ParserTest (  ) 

Sets terminal colorization and diff/quick modes depending on OS and command-line options (--color and --quick).

Definition at line 75 of file parserTests.inc.

References $options, showDiffs(), showFailure(), and wfIsWindows().

ParserTest::quickDiff ( input,
output,
inFileTail = 'expected',
outFileTail = 'actual' 
) [protected]

Run given strings through a diff and return the (colorized) output.

Requires writable /tmp directory and a 'diff' command in the PATH.

Parameters:
string $input
string $output
string $inFileTail Tailing for the input file name
string $outFileTail Tailing for the output file name
Returns:
string

Definition at line 963 of file parserTests.inc.

References $input, $output, colorDiff(), dumpToFile(), and wfTempDir().

Referenced by showFailure().

ParserTest::requireFunctionHook ( name  )  [private]

Steal a callback function from the primary parser, save it for application to our scary parser.

If the hook is not installed, die a painful dead to warn the others.

Parameters:
string $name

Definition at line 1064 of file parserTests.inc.

References $name, $wgParser, and wfDie().

ParserTest::requireHook ( name  ) 

Steal a callback function from the primary parser, save it for application to our scary parser.

If the hook is not installed, die a painful dead to warn the others.

Parameters:
string $name

Definition at line 1048 of file parserTests.inc.

References $name, $wgParser, and wfDie().

ParserTest::runTest ( desc,
input,
result,
opts,
config 
)

Run a given wikitext input through a freshly-constructed wiki parser, and compare the output against the expected results.

Prints status and explanatory messages to stdout.

Parameters:
string $input Wikitext to try rendering
string $result Result to output
Returns:
bool

Definition at line 330 of file parserTests.inc.

References $input, $options, $out, $output, $result, $section, $title, $wgOut, getParser(), Title::newFromText(), ParserOptions::newFromUser(), parseOptions(), setupGlobals(), showFailure(), showSuccess(), showTesting(), teardownGlobals(), tidy(), and wellFormed().

Referenced by runTests().

ParserTest::runTests ( tests  ) 

Definition at line 290 of file parserTests.inc.

References $i, $ok, $result, $t, print, and runTest().

Referenced by runTestsFromFiles().

ParserTest::runTestsFromFiles ( filenames  ) 

Run a series of tests listed in the given text files.

Each test consists of a brief description, wikitext input, and the expected HTML output.

Prints status updates on stdout and counts up the total number and percentage of passed tests.

Parameters:
array of strings $filenames
Returns:
bool True if passed all tests, false if any tests failed.

Definition at line 276 of file parserTests.inc.

References $filename, $ok, runTests(), setupDatabase(), and teardownDatabase().

ParserTest::setupDatabase (  ) 

Set up a temporary set of wiki tables to work with for the tests.

Currently this will only be done once per run, and any changes to the db will be visible to later tests in the run.

Definition at line 622 of file parserTests.inc.

References $wgDBprefix, $wgDBtype, $wgMemc, $wgMessageCache, changePrefix(), Language::getLocalisationCache(), listTables(), wfGetDB(), and wfGetLB().

Referenced by fuzzTest(), and runTestsFromFiles().

ParserTest::setupGlobals ( opts = '',
config = '' 
) [private]

Set up the global variables for a consistent environment for each test.

Ideally this should replace the global configuration entirely.

Definition at line 489 of file parserTests.inc.

References $wgDBtype, $wgUser, MagicWord::clearCache(), Language::factory(), getOptionValue(), and setupUploadDir().

Referenced by addArticle(), fuzzTest(), and runTest().

ParserTest::setupUploadDir (  )  [private]

Create a dummy uploads directory which will contain a couple of files in order to pass existence tests.

Returns:
string The directory

Definition at line 794 of file parserTests.inc.

References $IP, wfDebug(), wfMkdirParents(), and wfTempDir().

Referenced by setupGlobals().

ParserTest::showFailure ( desc,
result,
html 
) [protected]

Print a failure message and provide some explanatory output about what went wrong if so configured.

Parameters:
string $desc The test name
string $result Expected HTML output
string $html Actual HTML output
Returns:
bool

Reimplemented in PTShell.

Definition at line 932 of file parserTests.inc.

References $result, print, quickDiff(), showDiffs(), showTesting(), and wellFormed().

Referenced by ParserTest(), and runTest().

ParserTest::showRunFile ( path  ) 

Show "Reading tests from ...".

Parameters:
String $path

Reimplemented in PTShell.

Definition at line 1011 of file parserTests.inc.

References print.

ParserTest::showSuccess ( desc  )  [protected]

Print a happy success message.

Parameters:
string $desc The test name
Returns:
bool

Reimplemented in PTShell.

Definition at line 916 of file parserTests.inc.

References print.

Referenced by runTest().

ParserTest::showTesting ( desc  )  [protected]

"Running test $desc..."

Reimplemented in PTShell.

Definition at line 906 of file parserTests.inc.

References print.

Referenced by runTest(), and showFailure().

ParserTest::teardownDatabase (  )  [private]

Definition at line 765 of file parserTests.inc.

References $wgDBtype, and changePrefix().

Referenced by runTestsFromFiles().

ParserTest::teardownGlobals (  )  [private]

Restore default values and perform any necessary clean-up after each test runs.

Definition at line 822 of file parserTests.inc.

References RepoGroup::destroySingleton(), LinkCache::singleton(), and teardownUploadDir().

Referenced by addArticle(), fuzzTest(), and runTest().

ParserTest::teardownUploadDir ( dir  )  [private]

Remove the dummy uploads directory.

Definition at line 837 of file parserTests.inc.

References deleteDirs(), and deleteFiles().

Referenced by teardownGlobals().

ParserTest::tidy ( text  )  [private]

Definition at line 1082 of file parserTests.inc.

References $wgUseTidy.

Referenced by runTest().

ParserTest::wellFormed ( text  )  [private]

Definition at line 1090 of file parserTests.inc.

References extractFragment(), and Sanitizer::hackDocType().

Referenced by runTest(), and showFailure().


Member Data Documentation

ParserTest::$color [private]

boolean $color whereas output should be colorized

Definition at line 45 of file parserTests.inc.

ParserTest::$databaseSetupDone = false [private]

boolean $databaseSetupDone True if the database has been set up

Definition at line 60 of file parserTests.inc.

ParserTest::$fuzzSeed = 0 [private]

Definition at line 68 of file parserTests.inc.

ParserTest::$maxFuzzTestLength = 300 [private]

Definition at line 67 of file parserTests.inc.

ParserTest::$memoryLimit = 50 [private]

Definition at line 69 of file parserTests.inc.

ParserTest::$oldTablePrefix [private]

string $oldTablePrefix Original table prefix

Definition at line 65 of file parserTests.inc.

ParserTest::$showOutput [private]

boolean $showOutput Show test output

Definition at line 50 of file parserTests.inc.

ParserTest::$useTemporaryTables = true [private]

boolean $useTemporaryTables Use temporary tables for the temporary database

Definition at line 55 of file parserTests.inc.


The documentation for this class was generated from the following file:

Generated on Sat Apr 30 22:57:45 2011 for MediaWiki by  doxygen 1.5.9