/** * Returns a highly visible string used to indicate that an error occurred. * * @param object $test The doctest that is running. * @param object $example The current example in the test. * * @return string */ private function _failureHeader($test, $example) { $out = array($this->_divider); if ($test->filename !== '') { if (!is_null($test->lineno) && !is_null($example->lineno)) { $lineno = $test->lineno + $example->lineno + 1; } else { $lineno = '?'; } $out[] = sprintf('File "%s", line %s, in %s', $test->filename, $lineno, $test->name); } else { $out[] = sprintf('Line %s, in %s', $example->lineno + 1, $test->name); } $out[] = 'Failed example:'; $source = $example->source; $out[] = DocTest::indent($source); return implode("\n", $out); }
/** * Return the differences between expected output and actual output. * * @param object $example The example whose output should be diffed. * @param string $got The actual output for the example. * @param integer $optionflags The options to use when comparing output. * * @return string */ public function outputDifference($example, $got, $optionflags) { $want = $example->want; /** * If <BLANKLINE>s are being used, then replace blank lines * with <BLANKLINE> in the actual output string. */ if (!($optionflags & DOCTEST_DONT_ACCEPT_BLANKLINE)) { $got = preg_replace('/(?m)^[ ]*(?=\\n)/', DOCTEST_BLANKLINE_MARKER, $got); } /** * Check to see if we should put on our fancy pants. */ if ($this->_doAFancyDiff($want, $got, $optionflags)) { throw new Exception('No diff available yet.'); } /** * If we're not using diff, then simply list the expected * output followed by the actual output. */ if ($want !== '' && $got !== '') { return sprintf("Expected:\n%sGot:\n%s", DocTest::indent($want), DocTest::indent($got)); } elseif ($want !== '') { return sprintf("Expected:\n%sGot nothing\n", DocTest::indent($want)); } elseif ($got !== '') { return sprintf("Expected nothing\nGot:\n%s", DocTest::indent($got)); } else { return "Expected nothing\nGot nothing\n"; } }