Skip to content
Snippets Groups Projects
Commit 811885d7 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #1683884 by sun: Update, simplify, and speedup run-tests.sh for PSR-0,...

- Patch #1683884 by sun: Update, simplify, and speedup run-tests.sh for PSR-0, and allow to run all tests of a module.
parent 68859414
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
...@@ -47,18 +47,11 @@ ...@@ -47,18 +47,11 @@
exit; exit;
} }
// Load SimpleTest files.
$groups = simpletest_test_get_all();
$all_tests = array();
foreach ($groups as $group => $tests) {
$all_tests = array_merge($all_tests, array_keys($tests));
}
$test_list = array();
if ($args['list']) { if ($args['list']) {
// Display all available tests. // Display all available tests.
echo "\nAvailable test groups & classes\n"; echo "\nAvailable test groups & classes\n";
echo "-------------------------------\n\n"; echo "-------------------------------\n\n";
$groups = simpletest_test_get_all();
foreach ($groups as $group => $tests) { foreach ($groups as $group => $tests) {
echo $group . "\n"; echo $group . "\n";
foreach ($tests as $class => $info) { foreach ($tests as $class => $info) {
...@@ -129,6 +122,9 @@ function simpletest_script_help() { ...@@ -129,6 +122,9 @@ function simpletest_script_help() {
--all Run all available tests. --all Run all available tests.
--module Run all tests belonging to the specified module name.
(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.
--file Run tests identified by specific file names, instead of group names. --file Run tests identified by specific file names, instead of group names.
...@@ -181,6 +177,7 @@ function simpletest_script_parse_args() { ...@@ -181,6 +177,7 @@ function simpletest_script_parse_args() {
'php' => '', 'php' => '',
'concurrency' => 1, 'concurrency' => 1,
'all' => FALSE, 'all' => FALSE,
'module' => FALSE,
'class' => FALSE, 'class' => FALSE,
'file' => FALSE, 'file' => FALSE,
'color' => FALSE, 'color' => FALSE,
...@@ -489,44 +486,65 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { ...@@ -489,44 +486,65 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
* @return List of tests. * @return List of tests.
*/ */
function simpletest_script_get_test_list() { function simpletest_script_get_test_list() {
global $args, $all_tests, $groups; global $args;
$test_list = array(); $test_list = array();
if ($args['all']) { if ($args['all']) {
$groups = simpletest_test_get_all();
$all_tests = array();
foreach ($groups as $group => $tests) {
$all_tests = array_merge($all_tests, array_keys($tests));
}
$test_list = $all_tests; $test_list = $all_tests;
} }
else { else {
if ($args['class']) { if ($args['class']) {
// Check for valid class names.
foreach ($args['test_names'] as $class_name) { foreach ($args['test_names'] as $class_name) {
if (in_array($class_name, $all_tests)) { $test_list[] = $class_name;
$test_list[] = $class_name; }
} }
elseif ($args['module']) {
$modules = drupal_system_listing('/^' . DRUPAL_PHP_FUNCTION_PATTERN . '\.module$/', 'modules', 'name', 0);
foreach ($args['test_names'] as $module) {
// PSR-0 only.
$dir = dirname($modules[$module]->uri) . "/lib/Drupal/$module/Tests";
$files = file_scan_directory($dir, '@\.php$@', array(
'key' => 'name',
'recurse' => TRUE,
));
$test_list = array_merge($test_list, array_keys($files));
} }
} }
elseif ($args['file']) { elseif ($args['file']) {
$files = array(); // Extract test case class names from specified files.
foreach ($args['test_names'] as $file) { foreach ($args['test_names'] as $file) {
$files[drupal_realpath($file)] = 1; if (!file_exists($file)) {
} simpletest_script_print_error('File not found: ' . $file);
exit;
// Check for valid class names. }
foreach ($all_tests as $class_name) { $content = file_get_contents($file);
$refclass = new ReflectionClass($class_name); // Extract a potential namespace.
$file = $refclass->getFileName(); $namespace = FALSE;
if (isset($files[$file])) { if (preg_match('@^namespace ([^ ;]+)@m', $content, $matches)) {
$test_list[] = $class_name; $namespace = $matches[1];
}
// Extract all class names.
// Abstract classes are excluded on purpose.
preg_match_all('@^class ([^ ]+)@m', $content, $matches);
if (!$namespace) {
$test_list = array_merge($test_list, $matches[1]);
}
else {
foreach ($matches[1] as $class_name) {
$test_list[] = $namespace . '\\' . $class_name;
}
} }
} }
} }
else { else {
// Check for valid group names and get all valid classes in group. $groups = simpletest_test_get_all();
foreach ($args['test_names'] as $group_name) { foreach ($args['test_names'] as $group_name) {
if (isset($groups[$group_name])) { $test_list = array_merge($test_list, array_keys($groups[$group_name]));
foreach ($groups[$group_name] as $class_name => $info) {
$test_list[] = $class_name;
}
}
} }
} }
} }
...@@ -542,7 +560,7 @@ function simpletest_script_get_test_list() { ...@@ -542,7 +560,7 @@ function simpletest_script_get_test_list() {
* Initialize the reporter. * Initialize the reporter.
*/ */
function simpletest_script_reporter_init() { function simpletest_script_reporter_init() {
global $args, $all_tests, $test_list, $results_map; global $args, $test_list, $results_map;
$results_map = array( $results_map = array(
'pass' => 'Pass', 'pass' => 'Pass',
......
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