Index: modules/simpletest/simpletest.info
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.info,v
retrieving revision 1.5
diff -u -r1.5 simpletest.info
--- modules/simpletest/simpletest.info	1 May 2009 11:01:53 -0000	1.5
+++ modules/simpletest/simpletest.info	1 May 2009 19:45:38 -0000
@@ -7,3 +7,5 @@
 files[] = simpletest.module
 files[] = simpletest.pages.inc
 files[] = simpletest.install
+files[] = simpletest.test
+files[] = drupal_web_test_case.php
Index: modules/simpletest/simpletest.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.module,v
retrieving revision 1.41
diff -u -r1.41 simpletest.module
--- modules/simpletest/simpletest.module	1 May 2009 11:01:53 -0000	1.41
+++ modules/simpletest/simpletest.module	1 May 2009 19:45:39 -0000
@@ -142,9 +142,6 @@
  * Batch operation callback.
  */
 function _simpletest_batch_operation($test_list_init, $test_id, &$context) {
-  // Ensure that all classes are loaded before we unserialize some instances.
-  simpletest_get_all_tests();
-
   // Get working values.
   if (!isset($context['sandbox']['max'])) {
     // First iteration: initialize working values.
@@ -200,64 +197,62 @@
 }
 
 /**
- * Get a list of all of the tests.
+ * Get a list of all of the registered tests.
+ *
+ * The list of test classes is loaded from the registry where is looks for
+ * files ending in ".test". Once loaded the test list is cached and stored in
+ * a static variable.
  *
  * @return
- *   An array of tests, with the class name as the keys and the instantiated
- *   versions of the classes as the values.
+ *   An array of tests keyed with the groups specified in each of the tests
+ *   getInfo() array and then by the test class.
  */
-function simpletest_get_all_tests() {
-  static $formatted_classes;
-  if (!isset($formatted_classes)) {
-    require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'simpletest') . '/drupal_web_test_case.php';
-    $files = array();
-    foreach (array_keys(module_rebuild_cache()) as $module) {
-      $module_path = drupal_get_path('module', $module);
-      $test = $module_path . "/$module.test";
-      if (file_exists($test)) {
-        $files[] = $test;
-      }
+function simpletest_test_get_all() {
+  $groups = &drupal_static(__FUNCTION__);
+
+  if (!$groups) {
+    // Load test information from cache if available, otherwise retrieve the
+    // information from each tests getInfo() method.
+    if ($cache = cache_get('simpletest', 'cache')) {
+      $groups = $cache->data;
+    }
+    else {
+      // Select all clases in files ending with .test.
+      $classes = db_select('registry')
+        ->fields('registry', array('name'))
+        ->condition('type', 'class')
+        ->condition('filename', '%.test', 'LIKE')
+        ->execute();
+
+      $groups = array();
+
+      // Check that each class has a getInfo() method and store the information
+      // in an array keyed with the group specified in the test information.
+      foreach ($classes as $class) {
+        $class = $class->name;
+        if (class_exists($class) && method_exists($class, 'getInfo')) {
+          // Valid test class, retrieve test information.
+          $info = call_user_func(array($class, 'getInfo'));
+
+          // Initialize test groups.
+          if (!isset($groups[$info['group']])) {
+            $groups[$info['group']] = array();
+          }
 
-      $tests_directory = $module_path . '/tests';
-      if (is_dir($tests_directory)) {
-        foreach (file_scan_directory($tests_directory, '/\.test$/') as $file) {
-          $files[] = $file->filepath;
+          $groups[$info['group']][$class] = $info;
         }
       }
-    }
 
-    $existing_classes = get_declared_classes();
-    foreach ($files as $file) {
-      include_once DRUPAL_ROOT . '/' . $file;
-    }
-    $classes = array_values(array_diff(get_declared_classes(), $existing_classes));
-    foreach ($classes as $key => $class) {
-      if (!method_exists($class, 'getInfo')) {
-        unset($classes[$key]);
+      // Sort the groups and tests within the groups by name.
+      uksort($groups, 'strnatcasecmp');
+      foreach ($groups as $group => &$tests) {
+        uksort($tests, 'strnatcasecmp');
       }
+
+      cache_set('simpletest', $groups);
     }
   }
-  if (count($classes) == 0) {
-    drupal_set_message('No test cases found.', 'error');
-    return FALSE;
-  }
-  return $classes;
-}
 
-/**
- * Categorize the tests into groups.
- *
- * @param $tests
- *   A list of tests from simpletest_get_all_tests.
- * @see simpletest_get_all_tests.
- */
-function simpletest_categorize_tests($tests) {
-  $groups = array();
-  foreach ($tests as $test) {
-    $info = call_user_func(array($test, 'getInfo'));
-    $groups[$info['group']][$test] = $info;
-  }
-  uksort($groups, 'strnatcasecmp');
   return $groups;
 }
 
Index: modules/simpletest/simpletest.pages.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.pages.inc,v
retrieving revision 1.1
diff -u -r1.1 simpletest.pages.inc
--- modules/simpletest/simpletest.pages.inc	1 May 2009 13:40:56 -0000	1.1
+++ modules/simpletest/simpletest.pages.inc	1 May 2009 19:45:39 -0000
@@ -12,10 +12,6 @@
 function simpletest_test_form() {
   $form = array();
 
-  // Categorize the tests for display.
-  $uncategorized_tests = simpletest_get_all_tests();
-  $tests = simpletest_categorize_tests($uncategorized_tests);
-
   $form['tests'] = array(
     '#type' => 'fieldset',
     '#title' => t('Tests'),
@@ -27,13 +23,14 @@
   );
 
   // Generate the list of tests arranged by group.
-  foreach ($tests as $group_name => $test_group) {
-    $form['tests']['table'][$group_name] = array(
+  $groups = simpletest_test_get_all();
+  foreach ($groups as $group => $tests) {
+    $form['tests']['table'][$group] = array(
       '#collapsed' => TRUE,
     );
 
-    foreach ($test_group as $class => $info) {
-      $form['tests']['table'][$group_name][$class] = array(
+    foreach ($tests as $class => $info) {
+      $form['tests']['table'][$group][$class] = array(
         '#type' => 'checkbox',
         '#title' => $info['name'],
         '#description' => $info['description'],
@@ -166,9 +163,6 @@
  * Run selected tests.
  */
 function simpletest_test_form_submit($form, &$form_state) {
-  // Ensure that all classes are loaded before we create instances to get test information and run.
-  simpletest_get_all_tests();
-
   // Get list of tests.
   $tests_list = array();
   foreach ($form_state['values'] as $class_name => $value) {
@@ -200,7 +194,6 @@
 
   // Load all classes and include CSS.
   drupal_add_css(drupal_get_path('module', 'simpletest') . '/simpletest.css');
-  simpletest_get_all_tests();
 
   // Keep track of which test cases passed or failed.
   $filter = array(
Index: scripts/run-tests.sh
===================================================================
RCS file: /cvs/drupal/drupal/scripts/run-tests.sh,v
retrieving revision 1.26
diff -u -r1.26 run-tests.sh
--- scripts/run-tests.sh	13 Apr 2009 12:23:26 -0000	1.26
+++ scripts/run-tests.sh	1 May 2009 19:45:39 -0000
@@ -44,8 +44,11 @@
 }
 
 // Load SimpleTest files.
-$all_tests = simpletest_get_all_tests();
-$groups = simpletest_categorize_tests($all_tests);
+$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']) {
@@ -54,8 +57,8 @@
   echo   "-------------------------------\n\n";
   foreach ($groups as $group => $tests) {
     echo $group . "\n";
-    foreach ($tests as $class_name => $info) {
-      echo " - " . $info['name'] . ' (' . $class_name . ')' . "\n";
+    foreach ($tests as $class => $info) {
+      echo " - " . $info['name'] . ' (' . $class . ')' . "\n";
     }
   }
   exit;
@@ -339,7 +342,6 @@
  * Run a single test (assume a Drupal bootstrapped environment).
  */
 function simpletest_script_run_one_test($test_id, $test_class) {
-  simpletest_get_all_tests();
   $test = new $test_class($test_id);
   $test->run();
   $info = $test->getInfo();
