Fixed TapParser parse fail with valid data + added tests
This commit is contained in:
parent
0887bd4bc4
commit
1c864cebed
|
@ -13,9 +13,10 @@ use Symfony\Component\Yaml\Yaml;
|
||||||
class TapParser
|
class TapParser
|
||||||
{
|
{
|
||||||
const TEST_COUNTS_PATTERN = '/^\d+\.\.(\d+)/';
|
const TEST_COUNTS_PATTERN = '/^\d+\.\.(\d+)/';
|
||||||
const TEST_LINE_PATTERN = '/^(ok|not ok)(?:\s+\d+)?(?:\s+\-)?\s*(.*?)(?:\s*#\s*(skip|todo)\s*(.*))?\s*$/i';
|
const TEST_LINE_PATTERN = '/^(ok|not ok)(?:\s+\d+)?(?:\s+\-)?\s*(.*?)(?:\s*#\s*(skip|todo)\s*(.*))?\s*$/i';
|
||||||
const TEST_YAML_START = '/^(\s*)---/';
|
const TEST_YAML_START = '/^(\s*)---/';
|
||||||
const TEST_DIAGNOSTIC = '/^#/';
|
const TEST_DIAGNOSTIC = '/^#/';
|
||||||
|
const TEST_COVERAGE = '/^Generating/';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
|
@ -81,7 +82,7 @@ class TapParser
|
||||||
$line = $this->nextLine();
|
$line = $this->nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($this->results) !== $this->testCount) {
|
if (false !== $this->testCount && count($this->results) !== $this->testCount) {
|
||||||
throw new Exception(Lang::get('tap_error'));
|
throw new Exception(Lang::get('tap_error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,13 +127,15 @@ class TapParser
|
||||||
/** Parse a single line.
|
/** Parse a single line.
|
||||||
*
|
*
|
||||||
* @param string $line
|
* @param string $line
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function parseLine($line)
|
protected function parseLine($line)
|
||||||
{
|
{
|
||||||
if (preg_match(self::TEST_COUNTS_PATTERN, $line, $matches)) {
|
if (preg_match(self::TEST_COUNTS_PATTERN, $line, $matches)) {
|
||||||
$this->testCount = intval($matches[1]);
|
$this->testCount = intval($matches[1]);
|
||||||
|
|
||||||
} elseif (preg_match(self::TEST_DIAGNOSTIC, $line)) {
|
} elseif (preg_match(self::TEST_DIAGNOSTIC, $line) || preg_match(self::TEST_COVERAGE, $line) || !$line) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} elseif (preg_match(self::TEST_LINE_PATTERN, $line, $matches)) {
|
} elseif (preg_match(self::TEST_LINE_PATTERN, $line, $matches)) {
|
||||||
|
|
|
@ -23,6 +23,28 @@ ok 1 - SomeTest::testAnother
|
||||||
not ok
|
not ok
|
||||||
1..2
|
1..2
|
||||||
Trailing garbage !
|
Trailing garbage !
|
||||||
|
TAP;
|
||||||
|
$parser = new TapParser($content);
|
||||||
|
$result = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertEquals(array(
|
||||||
|
array('pass' => true, 'severity' => 'success', 'message' => 'SomeTest::testAnother'),
|
||||||
|
array('pass' => false, 'severity' => 'fail', 'message' => ''),
|
||||||
|
), $result);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $parser->getTotalFailures());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSimple2()
|
||||||
|
{
|
||||||
|
$content = <<<TAP
|
||||||
|
Leading garbage !
|
||||||
|
TAP version 13
|
||||||
|
|
||||||
|
ok 1 - SomeTest::testAnother
|
||||||
|
not ok
|
||||||
|
1..2
|
||||||
|
|
||||||
TAP;
|
TAP;
|
||||||
$parser = new TapParser($content);
|
$parser = new TapParser($content);
|
||||||
$result = $parser->parse();
|
$result = $parser->parse();
|
||||||
|
@ -48,6 +70,20 @@ TAP;
|
||||||
$parser->parse();
|
$parser->parse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTapCoverage()
|
||||||
|
{
|
||||||
|
$content = <<<TAP
|
||||||
|
TAP version 13
|
||||||
|
|
||||||
|
Generating code coverage report in HTML format ... done
|
||||||
|
|
||||||
|
TAP;
|
||||||
|
$parser = new TapParser($content);
|
||||||
|
$result = $parser->parse();
|
||||||
|
|
||||||
|
$this->assertEquals(array(), $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Exception
|
* @expectedException \Exception
|
||||||
* @expectedExceptionMessageRegExp /Duplicated TAP/
|
* @expectedExceptionMessageRegExp /Duplicated TAP/
|
||||||
|
|
Loading…
Reference in a new issue