Skip to content
Snippets Groups Projects
Commit 684602ea authored by Alex Pott's avatar Alex Pott
Browse files

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
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -312,7 +312,9 @@ public static function getTestInfo($classname, $doc_comment = NULL) { ...@@ -312,7 +312,9 @@ public static function getTestInfo($classname, $doc_comment = NULL) {
'name' => $classname, 'name' => $classname,
); );
$annotations = array(); $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])) { if (isset($matches[1])) {
foreach ($matches[1] as $key => $annotation) { foreach ($matches[1] as $key => $annotation) {
if (!empty($annotations[$annotation])) { if (!empty($annotations[$annotation])) {
...@@ -369,8 +371,10 @@ public static function parseTestClassSummary($doc_comment) { ...@@ -369,8 +371,10 @@ public static function parseTestClassSummary($doc_comment) {
$lines = explode("\n", $doc_comment); $lines = explode("\n", $doc_comment);
$summary = []; $summary = [];
// Add every line to the summary until the first empty line or annotation
// is found.
foreach ($lines as $line) { foreach ($lines as $line) {
if ($line == ' *' || preg_match('/^ \* \@/', $line)) { if (preg_match('/^[ ]*\*$/', $line) || preg_match('/^[ ]*\* \@/', $line)) {
break; break;
} }
$summary[] = trim($line, ' *'); $summary[] = trim($line, ' *');
......
...@@ -76,6 +76,45 @@ public function infoParserProvider() { ...@@ -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. // Multiple @group annotations.
$tests[] = [ $tests[] = [
// Expected result. // Expected result.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment