From 7e01fa5342c5588d7987ee7e065f941ab24bb695 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 11 Mar 2016 21:55:44 +0000
Subject: [PATCH] Issue #2680057 by alexpott, dawehner, isntall: Allow to not
 override the simpletest results on a new test run

---
 core/scripts/run-tests.sh | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh
index eba01b9d1ab2..1b7a45af12b5 100755
--- a/core/scripts/run-tests.sh
+++ b/core/scripts/run-tests.sh
@@ -180,6 +180,12 @@ function simpletest_script_help() {
               Note that ':memory:' cannot be used, because this script spawns
               sub-processes. However, you may use e.g. '/tmpfs/test.sqlite'
 
+  --keep-results-table
+
+              Boolean flag to indicate to not cleanup the simpletest result
+              table. For testbots or repeated execution of a single test it can
+              be helpful to not cleanup the simpletest result table.
+
   --dburl     A URI denoting the database driver, credentials, server hostname,
               and database name to use in tests.
               Required when running tests without a Drupal installation that
@@ -303,6 +309,7 @@ function simpletest_script_parse_args() {
     'color' => FALSE,
     'verbose' => FALSE,
     'keep-results' => FALSE,
+    'keep-results-table' => FALSE,
     'test_names' => array(),
     'repeat' => 1,
     'die-on-fail' => FALSE,
@@ -539,7 +546,8 @@ function simpletest_script_setup_database($new = FALSE) {
 
   // Create the Simpletest schema.
   try {
-    $schema = Database::getConnection('default', 'test-runner')->schema();
+    $connection = Database::getConnection('default', 'test-runner');
+    $schema = $connection->schema();
   }
   catch (\PDOException $e) {
     simpletest_script_print_error($databases['test-runner']['default']['driver'] . ': ' . $e->getMessage());
@@ -549,10 +557,13 @@ function simpletest_script_setup_database($new = FALSE) {
     require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'simpletest') . '/simpletest.install';
     foreach (simpletest_schema() as $name => $table_spec) {
       try {
-        if ($schema->tableExists($name)) {
-          $schema->dropTable($name);
+        $table_exists = $schema->tableExists($name);
+        if (empty($args['keep-results-table']) && $table_exists) {
+          $connection->truncate($name)->execute();
+        }
+        if (!$table_exists) {
+          $schema->createTable($name, $table_spec);
         }
-        $schema->createTable($name, $table_spec);
       }
       catch (Exception $e) {
         echo (string) $e;
-- 
GitLab