diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 1b8d5b2..2b75d70 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -38,9 +38,15 @@ simpletest_script_init(); -$request = Request::createFromGlobals(); -$kernel = TestRunnerKernel::createFromRequest($request, $autoloader); -$kernel->prepareLegacyRequest($request); +try { + $request = Request::createFromGlobals(); + $kernel = TestRunnerKernel::createFromRequest($request, $autoloader); + $kernel->prepareLegacyRequest($request); +} +catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); +} if ($args['execute-test']) { simpletest_script_setup_database(); @@ -53,7 +59,13 @@ // Display all available tests. echo "\nAvailable test groups & classes\n"; echo "-------------------------------\n\n"; - $groups = simpletest_test_get_all($args['module']); + try { + $groups = simpletest_test_get_all($args['module']); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } foreach ($groups as $group => $tests) { echo $group . "\n"; foreach ($tests as $class => $info) { @@ -67,7 +79,13 @@ if ($args['clean']) { // Clean up left-over tables and directories. - simpletest_clean_environment(); + try { + simpletest_clean_environment(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } echo "\nEnvironment cleaned.\n"; // Get the status messages and print them. @@ -109,7 +127,13 @@ // Clean up all test results. if (!$args['keep-results']) { - simpletest_clean_results_table(); + try { + simpletest_clean_results_table(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } } // Test complete, exit. @@ -499,16 +523,28 @@ function simpletest_script_setup_database($new = FALSE) { if ($new && $sqlite) { require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'simpletest') . '/simpletest.install'; foreach (simpletest_schema() as $name => $table_spec) { - if ($schema->tableExists($name)) { - $schema->dropTable($name); + try { + if ($schema->tableExists($name)) { + $schema->dropTable($name); + } + $schema->createTable($name, $table_spec); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); } - $schema->createTable($name, $table_spec); } } // Verify that the Simpletest database schema exists by checking one table. - if (!$schema->tableExists('simpletest')) { - simpletest_script_print_error('Missing Simpletest database schema. Either install Simpletest module or use the --sqlite parameter.'); - exit(SIMPLETEST_SCRIPT_EXIT_FAILURE); + try { + if (!$schema->tableExists('simpletest')) { + simpletest_script_print_error('Missing Simpletest database schema. Either install Simpletest module or use the --sqlite parameter.'); + exit(SIMPLETEST_SCRIPT_EXIT_FAILURE); + } + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); } } @@ -528,8 +564,16 @@ function simpletest_script_execute_batch($test_classes) { break; } - $test_id = Database::getConnection('default', 'test-runner') - ->insert('simpletest_test_id')->useDefaults(array('test_id'))->execute(); + try { + $test_id = Database::getConnection('default', 'test-runner') + ->insert('simpletest_test_id') + ->useDefaults(array('test_id')) + ->execute(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } $test_ids[] = $test_id; $test_class = array_shift($test_classes); @@ -731,7 +775,13 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { return; } // Retrieve the last database prefix used for testing. - list($db_prefix, ) = simpletest_last_test_get($test_id); + try { + list($db_prefix,) = simpletest_last_test_get($test_id); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } // If no database prefix was found, then the test was not set up correctly. if (empty($db_prefix)) { @@ -746,7 +796,13 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { $messages[] = "- Found database prefix '$db_prefix' for test ID $test_id."; // Read the log file in case any fatal errors caused the test to crash. - simpletest_log_read($test_id, $db_prefix, $test_class); + try { + simpletest_log_read($test_id, $db_prefix, $test_class); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } // Check whether a test site directory was setup already. // @see \Drupal\simpletest\TestBase::prepareEnvironment() @@ -768,12 +824,19 @@ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { } // Clear out all database tables from the test. - $schema = Database::getConnection('default', 'default')->schema(); - $count = 0; - foreach ($schema->findTables($db_prefix . '%') as $table) { - $schema->dropTable($table); - $count++; + try { + $schema = Database::getConnection('default', 'default')->schema(); + $count = 0; + foreach ($schema->findTables($db_prefix . '%') as $table) { + $schema->dropTable($table); + $count++; + } } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } + if ($count) { $messages[] = "- Removed $count leftover tables."; } @@ -797,7 +860,13 @@ function simpletest_script_get_test_list() { $test_list = array(); if ($args['all'] || $args['module']) { - $groups = simpletest_test_get_all($args['module']); + try { + $groups = simpletest_test_get_all($args['module']); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } $all_tests = array(); foreach ($groups as $group => $tests) { $all_tests = array_merge($all_tests, array_keys($tests)); @@ -813,7 +882,13 @@ function simpletest_script_get_test_list() { $test_list[] = $test_class; } else { - $groups = simpletest_test_get_all(); + try { + $groups = simpletest_test_get_all(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } $all_classes = array(); foreach ($groups as $group) { $all_classes = array_merge($all_classes, array_keys($group)); @@ -854,7 +929,13 @@ function simpletest_script_get_test_list() { } } else { - $groups = simpletest_test_get_all(); + try { + $groups = simpletest_test_get_all(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } foreach ($args['test_names'] as $group_name) { if (isset($groups[$group_name])) { $test_list = array_merge($test_list, array_keys($groups[$group_name])); @@ -944,7 +1025,13 @@ function simpletest_script_reporter_display_summary($class, $results) { function simpletest_script_reporter_write_xml_results() { global $args, $test_ids, $results_map; - $results = simpletest_script_load_messages_by_test_id($test_ids); + try { + $results = simpletest_script_load_messages_by_test_id($test_ids); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } $test_class = ''; $xml_files = array(); @@ -1034,7 +1121,13 @@ function simpletest_script_reporter_display_results() { echo "Detailed test results\n"; echo "---------------------\n"; - $results = simpletest_script_load_messages_by_test_id($test_ids); + try { + $results = simpletest_script_load_messages_by_test_id($test_ids); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } $test_class = ''; foreach ($results as $result) { if (isset($results_map[$result->status])) { @@ -1178,10 +1271,16 @@ function simpletest_script_load_messages_by_test_id($test_ids) { } foreach ($test_id_chunks as $test_id_chunk) { - $result_chunk = Database::getConnection('default', 'test-runner') - ->query("SELECT * FROM {simpletest} WHERE test_id IN ( :test_ids[] ) ORDER BY test_class, message_id", array( - ':test_ids[]' => $test_id_chunk, - ))->fetchAll(); + try { + $result_chunk = Database::getConnection('default', 'test-runner') + ->query("SELECT * FROM {simpletest} WHERE test_id IN ( :test_ids[] ) ORDER BY test_class, message_id", array( + ':test_ids[]' => $test_id_chunk, + ))->fetchAll(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } if ($result_chunk) { $results = array_merge($results, $result_chunk); } @@ -1196,14 +1295,20 @@ function simpletest_script_load_messages_by_test_id($test_ids) { function simpletest_script_open_browser() { global $test_ids; - $connection = Database::getConnection('default', 'test-runner'); - $results = $connection->select('simpletest') - ->fields('simpletest') - ->condition('test_id', $test_ids, 'IN') - ->orderBy('test_class') - ->orderBy('message_id') - ->execute() - ->fetchAll(); + try { + $connection = Database::getConnection('default', 'test-runner'); + $results = $connection->select('simpletest') + ->fields('simpletest') + ->condition('test_id', $test_ids, 'IN') + ->orderBy('test_class') + ->orderBy('message_id') + ->execute() + ->fetchAll(); + } + catch (Exception $e) { + echo (string) $e; + exit(SIMPLETEST_SCRIPT_EXIT_EXCEPTION); + } // Get the results form. $form = array();