Skip to content
Snippets Groups Projects
Commit 4378277e authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2390749 by alexpott: run-tests.sh should allow single test methods to be run

parent 9eb4efb9
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
...@@ -159,6 +159,8 @@ function simpletest_script_help() { ...@@ -159,6 +159,8 @@ function simpletest_script_help() {
(e.g., 'node') (e.g., 'node')
--class Run tests identified by specific class names, instead of group names. --class Run tests identified by specific class names, instead of group names.
A specific test method can be added, for example,
'Drupal\book\Tests\BookTest::testBookExport'.
--file Run tests identified by specific file names, instead of group names. --file Run tests identified by specific file names, instead of group names.
Specify the path and the extension Specify the path and the extension
...@@ -625,10 +627,19 @@ function simpletest_script_run_one_test($test_id, $test_class) { ...@@ -625,10 +627,19 @@ function simpletest_script_run_one_test($test_id, $test_class) {
global $args; global $args;
try { try {
$test = new $test_class($test_id); if (strpos($test_class, '::') > 0) {
list($class_name, $method) = explode('::', $test_class, 2);
$methods = [$method];
}
else {
$class_name = $test_class;
// Use empty array to run all the test methods.
$methods = array();
}
$test = new $class_name($test_id);
$test->dieOnFail = (bool) $args['die-on-fail']; $test->dieOnFail = (bool) $args['die-on-fail'];
$test->verbose = (bool) $args['verbose']; $test->verbose = (bool) $args['verbose'];
$test->run(); $test->run($methods);
simpletest_script_reporter_display_summary($test_class, $test->results); simpletest_script_reporter_display_summary($test_class, $test->results);
...@@ -774,7 +785,8 @@ function simpletest_script_get_test_list() { ...@@ -774,7 +785,8 @@ function simpletest_script_get_test_list() {
if ($args['class']) { if ($args['class']) {
$test_list = array(); $test_list = array();
foreach ($args['test_names'] as $test_class) { foreach ($args['test_names'] as $test_class) {
if (class_exists($test_class)) { list($class_name, ) = explode('::', $test_class, 2);
if (class_exists($class_name)) {
$test_list[] = $test_class; $test_list[] = $test_class;
} }
else { else {
...@@ -783,8 +795,8 @@ function simpletest_script_get_test_list() { ...@@ -783,8 +795,8 @@ function simpletest_script_get_test_list() {
foreach ($groups as $group) { foreach ($groups as $group) {
$all_classes = array_merge($all_classes, array_keys($group)); $all_classes = array_merge($all_classes, array_keys($group));
} }
simpletest_script_print_error('Test class not found: ' . $test_class); simpletest_script_print_error('Test class not found: ' . $class_name);
simpletest_script_print_alternatives($test_class, $all_classes, 6); simpletest_script_print_alternatives($class_name, $all_classes, 6);
exit(1); exit(1);
} }
} }
......
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