Issue #2491915 by Berdir, miro_dietiker: Test @group detection fails for test classes with non-standard indendation

8.0.x
Alex Pott 2015-05-21 14:19:05 +01:00
parent fe2eecace0
commit 684602eacc
2 changed files with 45 additions and 2 deletions

View File

@ -312,7 +312,9 @@ class TestDiscovery {
'name' => $classname,
);
$annotations = array();
preg_match_all('/^ \* \@([^\s]*) (.*$)/m', $doc_comment, $matches);
// Look for annotations, allow an arbitrary amount of spaces before the
// * but nothing else.
preg_match_all('/^[ ]*\* \@([^\s]*) (.*$)/m', $doc_comment, $matches);
if (isset($matches[1])) {
foreach ($matches[1] as $key => $annotation) {
if (!empty($annotations[$annotation])) {
@ -369,8 +371,10 @@ class TestDiscovery {
$lines = explode("\n", $doc_comment);
$summary = [];
// Add every line to the summary until the first empty line or annotation
// is found.
foreach ($lines as $line) {
if ($line == ' *' || preg_match('/^ \* \@/', $line)) {
if (preg_match('/^[ ]*\*$/', $line) || preg_match('/^[ ]*\* \@/', $line)) {
break;
}
$summary[] = trim($line, ' *');

View File

@ -76,6 +76,45 @@ class TestInfoParsingTest extends UnitTestCase {
",
];
// Test with a different amount of leading spaces.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\field\Tests\BulkDeleteTest',
'group' => 'field',
'description' => 'Bulk delete storages and fields, and clean up afterwards.',
],
// Classname.
'Drupal\field\Tests\BulkDeleteTest',
// Doc block.
"/**
* Bulk delete storages and fields, and clean up afterwards.
*
* @group field
*/
",
];
// Make sure that a "* @" inside a string does not get parsed as an
// annotation.
$tests[] = [
// Expected result.
[
'name' => 'Drupal\field\Tests\BulkDeleteTest',
'group' => 'field',
'description' => 'Bulk delete storages and fields, and clean up afterwards. * @',
],
// Classname.
'Drupal\field\Tests\BulkDeleteTest',
// Doc block.
"/**
* Bulk delete storages and fields, and clean up afterwards. * @
*
* @group field
*/
",
];
// Multiple @group annotations.
$tests[] = [
// Expected result.