Index: modules/simpletest/simpletest.info
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/simpletest.info,v
retrieving revision 1.4
diff -u -r1.4 simpletest.info
--- modules/simpletest/simpletest.info	11 Oct 2008 02:33:01 -0000	1.4
+++ modules/simpletest/simpletest.info	30 Apr 2009 03:44:56 -0000
@@ -6,3 +6,5 @@
 core = 7.x
 files[] = simpletest.module
 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.40
diff -u -r1.40 simpletest.module
--- modules/simpletest/simpletest.module	27 Apr 2009 07:44:09 -0000	1.40
+++ modules/simpletest/simpletest.module	30 Apr 2009 03:44:56 -0000
@@ -71,7 +71,7 @@
   $form = array();
 
   // List out all tests in groups for selection.
-  $uncategorized_tests = simpletest_get_all_tests();
+  $uncategorized_tests = simpletest_test_get_all();
   $tests = simpletest_categorize_tests($uncategorized_tests);
   $selected_tests = array();
 
@@ -328,7 +328,7 @@
  */
 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();
+  simpletest_test_get_all();
 
   // Get list of tests.
   $tests_list = array();
@@ -390,7 +390,7 @@
  */
 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();
+  simpletest_test_get_all();
 
   // Get working values.
   if (!isset($context['sandbox']['max'])) {
@@ -450,56 +450,73 @@
 }
 
 /**
- * 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. The  
  *
  * @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__);
 
-      $tests_directory = $module_path . '/tests';
-      if (is_dir($tests_directory)) {
-        foreach (file_scan_directory($tests_directory, '/\.test$/') as $file) {
-          $files[] = $file->filepath;
-        }
-      }
+  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();
 
-    $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]);
+      $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();
+          }
+
+          $groups[$info['group']][$class] = $info;
+        }
       }
+      
+      // 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;
+  
+  drupal_set_message(print_r($groups, TRUE));
+
+  return $groups;
 }
 
 /**
  * Categorize the tests into groups.
  *
  * @param $tests
- *   A list of tests from simpletest_get_all_tests.
- * @see simpletest_get_all_tests.
+ *   A list of tests from simpletest_test_get_all.
+ * @see simpletest_test_get_all.
  */
 function simpletest_categorize_tests($tests) {
   $groups = 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	30 Apr 2009 03:44:57 -0000
@@ -44,7 +44,7 @@
 }
 
 // Load SimpleTest files.
-$all_tests = simpletest_get_all_tests();
+$all_tests = simpletest_test_get_all();
 $groups = simpletest_categorize_tests($all_tests);
 $test_list = array();
 
@@ -339,7 +339,7 @@
  * Run a single test (assume a Drupal bootstrapped environment).
  */
 function simpletest_script_run_one_test($test_id, $test_class) {
-  simpletest_get_all_tests();
+  simpletest_test_get_all();
   $test = new $test_class($test_id);
   $test->run();
   $info = $test->getInfo();
