? simpletest
Index: run_all_tests.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/run_all_tests.php,v
retrieving revision 1.3
diff -u -p -r1.3 run_all_tests.php
--- run_all_tests.php	5 Apr 2006 00:44:32 -0000	1.3
+++ run_all_tests.php	20 Jan 2008 09:42:46 -0000
@@ -5,29 +5,46 @@
 
 
 /**
-
  * @file
-
- * Run all unit tests for all enabled modules.
-
+ * This script can be run with browser or from command line.
+ * You can provide class names of the tests you wish to run.
+ * For command line: php run_all_tests.php SearchMatchTest,ProfileModuleTestSingle
+ * For browser: http://yoursite.com/sites/all/modules/simpletest/run_all_tests.php?include=SearchMatchTest,ProfileModuleTestSingle
+ * If none of these two options are provided all tests will be run.
  */
 chdir(realpath(dirname(__FILE__) . '/../../'));
-
-require_once './includes/bootstrap.inc';
+if (file_exists('./includes/bootstrap.inc')) {
+  include_once './includes/bootstrap.inc';
+}
+else {
+  chdir(realpath(dirname(__FILE__) . '/../../../../'));
+  if (file_exists('./includes/bootstrap.inc')) {
+    include_once './includes/bootstrap.inc';
+  }
+  else {
+  	exit("bootstrap.inc could not be loaded\n");
+  }
+}
 
 drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
-
-
 // If not in 'safe mode', increase the maximum execution time:
-
 if (!ini_get('safe_mode')) {
-
   set_time_limit(360);
-
 }
 
+$tests = array();
+$html_reporter = FALSE;
+if ($_GET['include']) {
+  $tests = explode(',', $_GET['include']);
+  $html_reporter = TRUE;
+}
+else if ($argc == 2) {
+  $tests = explode(',', $argv[1]);
+}
+$result = simpletest_run_tests($tests, $html_reporter);
 
-
-simpletest_run_tests();
+if (!$html_reporter) {
+  exit($result);
+}
 
Index: simpletest.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/simpletest.module,v
retrieving revision 1.22.2.8
diff -u -p -r1.22.2.8 simpletest.module
--- simpletest.module	11 Jan 2008 16:56:45 -0000	1.22.2.8
+++ simpletest.module	20 Jan 2008 09:42:47 -0000
@@ -14,6 +14,9 @@ function simpletest_help($section) {
     case 'admin/settings/simpletest':
       $output = '';
       break;
+    case 'drush:simpletest':
+      $output = t('Usage: drush [options] simpletest <tests> \n\n<tests> simpletest test classes separated by comma i.e. UploadPictureTests,TaxonomyVocabularyFunctions,TaxonomyTermFunctions,...');
+      break;
   }
 
   return $output;
@@ -99,6 +102,19 @@ function simpletest_load() {
 
 
 /**
+ * Implementation of hook_drush_command().
+ */
+function simpletest_drush_command() {
+  $items['simpletest'] = array(
+    'callback' => 'simpletest_drush_entrypoint',
+    'description' => 'Run simpletest tests'
+  );
+ 
+  return $items;
+}
+
+
+/**
  * Menu callback for both running tests and listing possible tests
  */
 function simpletest_entrypoint() {
@@ -124,6 +140,22 @@ function simpletest_running_output($outp
 }
 
 /**
+ * Drush callback for running tests with drush.
+ */
+function simpletest_drush_entrypoint($tests = NULL) {
+  
+  if (is_null($tests)) {
+    drush_print(t('Running all tests'));
+    $result = simpletest_run_tests();
+  }
+  else {
+    $tests = explode(',', $tests);
+    $result = simpletest_run_tests($tests);
+  }
+  return $result;
+}
+
+/**
  * FAPI form submit for simpletest_overview_form
  *
  * @param $form_id 
@@ -135,8 +167,7 @@ function simpletest_overview_form_submit
     
     case 'all_tests':
       $output  = simpletest_run_tests();
-    break;    
-    
+      break;    
     case 'selected_tests':
       $test_list = array();
       foreach ($form_values as $item => $value){
@@ -145,14 +176,13 @@ function simpletest_overview_form_submit
         }
       }
       if (count($tests_list) > 0 ) {
-				$output = simpletest_run_tests($tests_list);
-			}
-			else { 
-				// no test has been selected
-				drupal_set_message(t('No test has been selected.'), 'error');
-			}
-    break;  
-    
+        $output = simpletest_run_tests($tests_list);
+      }
+      else { 
+        // no test has been selected
+        drupal_set_message(t('No test has been selected.'), 'error');
+      }
+      break;  
     default:
       drupal_set_message(t('No test has been selected.'), 'error');
   }
@@ -207,23 +237,37 @@ function simpletest_overview_form() {
 /**
  * Actually runs tests
  * @param array $testlist list of tests to run or DEFAULT NULL run all tests
+ * @param boolean $html_reporter true if you want results in simple html, FALSE for full drupal page
  */
-function simpletest_run_tests($testlist = NULL) {
+function simpletest_run_tests($testlist = NULL, $html_reporter = FALSE) {
   global $test_running;
   if (!$test_running) {
     $test_running = TRUE;
     $test = simpletest_get_total_test($testlist);
     if (SimpleReporter::inCli()) {
       cache_clear_all();
-      exit ($test->run(new TextReporter()) ? 0 : 1);
+      $reporter = &new TextReporter();
+      $reporter_type = 1;
+    }
+    else if ($html_reporter == TRUE) {
+      $reporter = &new HtmlReporter();
+      $reporter_type = 2;
+    }
+    else {
+      $reporter = &new DrupalReporter();
+      $reporter_type = 3;
     }
-    //$reporter = &new HtmlReporter();
-    $reporter = &new DrupalReporter();
     cache_clear_all();
-    $test->run($reporter);
-//    exit;
+    $results = $test->run($reporter);
     $test_running = FALSE;
-    return $reporter->getOutput();
+    switch ($reporter_type) {
+      case 1:
+        return ($results ? 0 : 1);
+      case 2:
+        break;
+      case 3:
+        return $reporter->getOutput();
+    }
   }
 }
 
