Commit 684602ea authored by alexpott's avatar alexpott

Issue #2491915 by Berdir, miro_dietiker: Test @group detection fails for test...

Issue #2491915 by Berdir, miro_dietiker: Test @group detection fails for test classes with non-standard indendation
parent fe2eecac
......@@ -312,7 +312,9 @@ public static function getTestInfo($classname, $doc_comment = NULL) {
'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 @@ public static function parseTestClassSummary($doc_comment) {
$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, ' *');
......
......@@ -76,6 +76,45 @@ public function infoParserProvider() {
",
];
// 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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment