Skip to content
Snippets Groups Projects
Commit f0e660bd authored by Fabian Franz's avatar Fabian Franz
Browse files

Issue #2551981 by jthorson, Mixologic, Fabianx, David_Rothstein: Add...

Issue #2551981 by jthorson, Mixologic, Fabianx, David_Rothstein: Add --directory option to run-tests.sh test discovery
parent 1fea8c83
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,8 @@ Drupal 7.50, xxxx-xx-xx (development version)
- Added a .editorconfig file to auto-configure editors that support it.
- Fixed that cookies from previous tests are still present when a new test
starts in DrupalWebTestCase.
- Added --directory option to run-tests.sh for easier test discovery of all
tests within a project.
Drupal 7.44, 2016-06-15
-----------------------
......
......@@ -142,6 +142,8 @@ function simpletest_script_help() {
--file Run tests identified by specific file names, instead of group names.
Specify the path and the extension (i.e. 'modules/user/user.test').
--directory Run all tests found within the specified file directory.
--xml <path>
If provided, test results will be written as xml files to this path.
......@@ -190,6 +192,7 @@ function simpletest_script_parse_args() {
'all' => FALSE,
'class' => FALSE,
'file' => FALSE,
'directory' => '',
'color' => FALSE,
'verbose' => FALSE,
'test_names' => array(),
......@@ -451,6 +454,51 @@ function simpletest_script_get_test_list() {
}
}
}
elseif ($args['directory']) {
// Extract test case class names from specified directory.
// Find all tests in the PSR-X structure; Drupal\$extension\Tests\*.php
// Since we do not want to hard-code too many structural file/directory
// assumptions about PSR-0/4 files and directories, we check for the
// minimal conditions only; i.e., a '*.php' file that has '/Tests/' in
// its path.
// Ignore anything from third party vendors, and ignore template files used in tests.
// And any api.php files.
$ignore = array('nomask' => '/vendor|\.tpl\.php|\.api\.php/');
$files = array();
if ($args['directory'][0] === '/') {
$directory = $args['directory'];
}
else {
$directory = DRUPAL_ROOT . "/" . $args['directory'];
}
$file_list = file_scan_directory($directory, '/\.php|\.test$/', $ignore);
foreach ($file_list as $file) {
// '/Tests/' can be contained anywhere in the file's path (there can be
// sub-directories below /Tests), but must be contained literally.
// Case-insensitive to match all Simpletest and PHPUnit tests:
// ./lib/Drupal/foo/Tests/Bar/Baz.php
// ./foo/src/Tests/Bar/Baz.php
// ./foo/tests/Drupal/foo/Tests/FooTest.php
// ./foo/tests/src/FooTest.php
// $file->filename doesn't give us a directory, so we use $file->uri
// Strip the drupal root directory and trailing slash off the URI
$filename = substr($file->uri, strlen(DRUPAL_ROOT)+1);
if (stripos($filename, '/Tests/')) {
$files[drupal_realpath($filename)] = 1;
} else if (stripos($filename, '.test')){
$files[drupal_realpath($filename)] = 1;
}
}
// Check for valid class names.
foreach ($all_tests as $class_name) {
$refclass = new ReflectionClass($class_name);
$classfile = $refclass->getFileName();
if (isset($files[$classfile])) {
$test_list[] = $class_name;
}
}
}
else {
// Check for valid group names and get all valid classes in group.
foreach ($args['test_names'] as $group_name) {
......
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