From a1d5f882267f1d37043063365769d9fe7efbaa47 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Wed, 16 Mar 2016 20:11:46 +0900
Subject: [PATCH] Issue #2687837 by alexpott: run-tests.sh --types does not
 work with --directory

---
 core/scripts/run-tests.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index 1b7a45af12b5..df613284be2e 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -14,6 +14,7 @@
 use Drupal\Core\Test\TestRunnerKernel;
 use Drupal\simpletest\Form\SimpletestResultsForm;
 use Drupal\simpletest\TestBase;
+use Drupal\simpletest\TestDiscovery;
 use Symfony\Component\HttpFoundation\Request;
 
 $autoloader = require_once __DIR__ . '/../../autoload.php';
@@ -913,10 +914,12 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) {
 function simpletest_script_get_test_list() {
   global $args;
 
+  $types_processed = empty($args['types']);
   $test_list = array();
   if ($args['all'] || $args['module']) {
     try {
       $groups = simpletest_test_get_all($args['module'], $args['types']);
+      $types_processed = TRUE;
     }
     catch (Exception $e) {
       echo (string) $e;
@@ -1040,6 +1043,7 @@ function simpletest_script_get_test_list() {
     else {
       try {
         $groups = simpletest_test_get_all(NULL, $args['types']);
+        $types_processed = TRUE;
       }
       catch (Exception $e) {
         echo (string) $e;
@@ -1058,6 +1062,15 @@ function simpletest_script_get_test_list() {
     }
   }
 
+  // If the test list creation does not automatically limit by test type then
+  // we need to do so here.
+  if (!$types_processed) {
+    $test_list = array_filter($test_list, function ($test_class) use ($args) {
+      $test_info = TestDiscovery::getTestInfo($test_class);
+      return in_array($test_info['type'], $args['types'], TRUE);
+    });
+  }
+
   if (empty($test_list)) {
     simpletest_script_print_error('No valid tests were specified.');
     exit(SIMPLETEST_SCRIPT_EXIT_FAILURE);
-- 
GitLab