diff options
Diffstat (limited to 'includes/parser/Parser_DiffTest.php')
-rw-r--r-- | includes/parser/Parser_DiffTest.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/includes/parser/Parser_DiffTest.php b/includes/parser/Parser_DiffTest.php index be3702cf..608c883a 100644 --- a/includes/parser/Parser_DiffTest.php +++ b/includes/parser/Parser_DiffTest.php @@ -6,6 +6,7 @@ class Parser_DiffTest { var $parsers, $conf; + var $shortOutput = false; var $dfUniqPrefix; @@ -28,6 +29,9 @@ class Parser_DiffTest $doneHook = true; $wgHooks['ParserClearState'][] = array( $this, 'onClearState' ); } + if ( isset( $this->conf['shortOutput'] ) ) { + $this->shortOutput = $this->conf['shortOutput']; + } foreach ( $this->conf['parsers'] as $i => $parserConf ) { if ( !is_array( $parserConf ) ) { @@ -65,13 +69,37 @@ class Parser_DiffTest $lastResult = $currentResult; } if ( $mismatch ) { - throw new MWException( "Parser_DiffTest: results mismatch on call to $name\n" . - 'Arguments: ' . var_export( $args, true ) . "\n" . - 'Results: ' . var_export( $results, true ) . "\n" ); + if ( count( $results ) == 2 ) { + $resultsList = array(); + foreach ( $this->parsers as $i => $parser ) { + $resultsList[] = var_export( $results[$i], true ); + } + $diff = wfDiff( $resultsList[0], $resultsList[1] ); + } else { + $diff = '[too many parsers]'; + } + $msg = "Parser_DiffTest: results mismatch on call to $name\n"; + if ( !$this->shortOutput ) { + $msg .= 'Arguments: ' . $this->formatArray( $args ) . "\n"; + } + $msg .= 'Results: ' . $this->formatArray( $results ) . "\n" . + "Diff: $diff\n"; + throw new MWException( $msg ); } return $lastResult; } + function formatArray( $array ) { + if ( $this->shortOutput ) { + foreach ( $array as $key => $value ) { + if ( $value instanceof ParserOutput ) { + $array[$key] = "ParserOutput: {$value->getText()}"; + } + } + } + return var_export( $array, true ); + } + function setFunctionHook( $id, $callback, $flags = 0 ) { $this->init(); foreach ( $this->parsers as $i => $parser ) { |