ParserTest Class Reference
[Maintenance]

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).
 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.
 getParser ()
 Get a Parser object.
 changeLBPrefix ($lb, $prefix)
 changeDBPrefix ($db, $prefix)

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.
 showRunFile ($path)
 Show "Reading tests from ...".

Private Member Functions

 chomp ($s)
 Remove last character if it is a newline.
 runFile ($filename)
 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.
 setupGlobals ($opts= '', $config= '')
 Set up the global variables for a consistent environment for each test.
 listTables ()
 List of temporary tables to create, without prefix.
 setupDatabase ()
 Set up a temporary set of wiki tables to work with for the tests.
 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.
 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.
 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 ($regex, $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 39 of file parserTests.inc.


Member Function Documentation

ParserTest::abort (  ) 

Definition at line 253 of file parserTests.inc.

Referenced by fuzzTest().

ParserTest::addArticle ( name,
text,
line 
) [private]

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 1009 of file parserTests.inc.

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

Referenced by runFile().

ParserTest::changeDBPrefix ( db,
prefix 
)

Definition at line 763 of file parserTests.inc.

References $db, and $prefix.

ParserTest::changeLBPrefix ( lb,
prefix 
)

Definition at line 759 of file parserTests.inc.

References $lb, and $prefix.

ParserTest::changePrefix ( prefix  )  [protected]

Change the table prefix on all open DB connections/.

Definition at line 753 of file parserTests.inc.

References $prefix, $wgDBprefix, and wfGetLBFactory().

Referenced by setupDatabase(), and teardownDatabase().

ParserTest::chomp ( s  )  [private]

Remove last character if it is a newline.

Definition at line 135 of file parserTests.inc.

References $s.

Referenced by runFile().

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 983 of file parserTests.inc.

References $text.

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 880 of file parserTests.inc.

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 868 of file parserTests.inc.

References $file, and $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 970 of file parserTests.inc.

References $file, and $filename.

Referenced by quickDiff().

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

Definition at line 1096 of file parserTests.inc.

References $start, and $text.

Referenced by wellFormed().

ParserTest::fuzzTest ( filenames  ) 

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

Definition at line 148 of file parserTests.inc.

References $input, $name, $offset, $title, $usage, $user, 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 214 of file parserTests.inc.

References $filename.

Referenced by fuzzTest().

ParserTest::getMemoryBreakdown (  ) 

Get a memory usage breakdown.

Definition at line 229 of file parserTests.inc.

References $classes, $GLOBALS, $method, and $name.

Referenced by fuzzTest().

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

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

Parameters:
$regex A regex, the first group will be the value returned
$opts Options line to look in
$defaults Default value returned if the regex does not match

Definition at line 497 of file parserTests.inc.

Referenced by setupGlobals().

ParserTest::getParser (  ) 

Get a Parser object.

Definition at line 398 of file parserTests.inc.

References $flags, $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 607 of file parserTests.inc.

References $wgDBtype, and wfRunHooks().

Referenced by setupDatabase().

ParserTest::ParserTest (  ) 

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

Definition at line 73 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 948 of file parserTests.inc.

References $input, $output, $prefix, 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 1047 of file parserTests.inc.

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

Referenced by runFile().

ParserTest::requireHook ( 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 1032 of file parserTests.inc.

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

Referenced by runFile().

ParserTest::runFile ( filename  )  [private]

ParserTest::runTest ( desc,
input,
result,
opts,
config 
) [private]

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 422 of file parserTests.inc.

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

Referenced by runFile().

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 268 of file parserTests.inc.

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

ParserTest::setupDatabase (  )  [private]

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 634 of file parserTests.inc.

References $db, $res, $row, $wgDBprefix, $wgDBtype, changePrefix(), listTables(), wfDie(), 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 510 of file parserTests.inc.

References $GLOBALS, $wgUser, 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 792 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

Definition at line 917 of file parserTests.inc.

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

Referenced by ParserTest(), and runTest().

ParserTest::showRunFile ( path  )  [protected]

Show "Reading tests from ...".

Parameters:
String $path

Definition at line 996 of file parserTests.inc.

References print.

Referenced by runFile().

ParserTest::showSuccess ( desc  )  [protected]

Print a happy success message.

Parameters:
string $desc The test name
Returns:
bool

Definition at line 901 of file parserTests.inc.

References print.

Referenced by runTest().

ParserTest::showTesting ( desc  )  [protected]

"Running test $desc..."

Definition at line 891 of file parserTests.inc.

References print.

Referenced by runTest(), and showFailure().

ParserTest::teardownDatabase (  )  [private]

Definition at line 767 of file parserTests.inc.

References $wgDBprefix, and changePrefix().

Referenced by runTestsFromFiles().

ParserTest::teardownGlobals (  )  [private]

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

Definition at line 817 of file parserTests.inc.

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

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

ParserTest::teardownUploadDir ( dir  )  [private]

Remove the dummy uploads directory.

Definition at line 833 of file parserTests.inc.

References deleteDirs(), and deleteFiles().

Referenced by teardownGlobals().

ParserTest::tidy ( text  )  [private]

Definition at line 1064 of file parserTests.inc.

References $text, and $wgUseTidy.

Referenced by runTest().

ParserTest::wellFormed ( text  )  [private]

Definition at line 1072 of file parserTests.inc.

References $text, 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 43 of file parserTests.inc.

ParserTest::$databaseSetupDone = false [private]

boolean $databaseSetupDone True if the database has been set up

Definition at line 58 of file parserTests.inc.

ParserTest::$fuzzSeed = 0 [private]

Definition at line 66 of file parserTests.inc.

ParserTest::$maxFuzzTestLength = 300 [private]

Definition at line 65 of file parserTests.inc.

ParserTest::$memoryLimit = 50 [private]

Definition at line 67 of file parserTests.inc.

ParserTest::$oldTablePrefix [private]

string $oldTablePrefix Original table prefix

Definition at line 63 of file parserTests.inc.

ParserTest::$showOutput [private]

boolean $showOutput Show test output

Definition at line 48 of file parserTests.inc.

ParserTest::$useTemporaryTables = true [private]

boolean $useTemporaryTables Use temporary tables for the temporary database

Definition at line 53 of file parserTests.inc.


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

Generated on Sat Sep 5 02:08:44 2009 for MediaWiki by  doxygen 1.5.9