Index: simpletest.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/simpletest.module,v
retrieving revision 1.41
diff -u -r1.41 simpletest.module
--- simpletest.module	3 Apr 2008 19:57:15 -0000	1.41
+++ simpletest.module	5 Apr 2008 19:32:01 -0000
@@ -217,6 +217,25 @@
 function simpletest_run_tests($testlist = NULL, $reporter = 'drupal') {
   static $test_running;
   if (!$test_running) {
+    $file = drupal_get_path('module', 'simpletest') .'/spikephpcoverage';
+    $coverage = (file_exists($file) && is_dir($file));
+    if ($coverage) {
+      if (!defined('PHPCOVERAGE_HOME')) {
+        define('PHPCOVERAGE_HOME', $file .'/src'); 
+      }
+
+      require_once PHPCOVERAGE_HOME .'/CoverageRecorder.php';
+      require_once PHPCOVERAGE_HOME .'/reporter/HtmlCoverageReporter.php';
+
+      $coverage_reporter = new HtmlCoverageReporter(t('Drupal Code Coverage Report'), '', drupal_get_path('module', 'simpletest') .'/coverage_results/'. date('Y_m_d_H_i_s'));
+
+      $include_paths = array('.');
+      $simpletest_path = drupal_get_path('module', 'simpletest');
+      $exclude_paths = array("$simpletest_path/coverage_results", "$simpletest_path/simpletest", "$simpletest_path/tests", "$simpletest_path/spikephpcoverage");
+      $coverage_recorder = new CoverageRecorder($include_paths, $exclude_paths, $coverage_reporter);
+
+      $coverage_recorder->startInstrumentation();
+    }
     $test_running = TRUE;
     $test = simpletest_get_total_test($testlist);
     switch ($reporter) {
@@ -238,6 +257,12 @@
     $results = $test->run($reporter);
     $test_running = FALSE;
 
+    if ($coverage) {
+      $coverage_recorder->stopInstrumentation();
+      $coverage_recorder->generateReport();
+      $coverage_reporter->printTextSummary();
+    }
+
     switch (get_class($reporter)) {
       case 'TextReporter':
       case 'XMLReporter':
