Index: modules/simpletest/drupal_web_test_case.php
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/drupal_web_test_case.php,v
retrieving revision 1.176
diff -u -p -r1.176 drupal_web_test_case.php
--- modules/simpletest/drupal_web_test_case.php	2 Dec 2009 19:26:22 -0000	1.176
+++ modules/simpletest/drupal_web_test_case.php	6 Dec 2009 05:30:46 -0000
@@ -1166,6 +1166,9 @@ class DrupalWebTestCase extends DrupalTe
   protected function tearDown() {
     global $db_prefix, $user, $language;
 
+    // Capture any (remaining) watchdog messages.
+    $this->assertWatchdogMessages();
+
     // In case a fatal error occured that was not in the test process read the
     // log to pick up any fatal errors.
     $db_prefix_temp = $db_prefix;
@@ -1224,6 +1227,57 @@ class DrupalWebTestCase extends DrupalTe
   }
 
   /**
+   * Assert watchdog messages based on their severity.
+   *
+   * This function can be (repeatedly) invoked to assert new watchdog messages.
+   * All watchdog messages with a higher severity than WATCHDOG_NOTICE are
+   * considered as fails.
+   *
+   * @param $no_fail_expected
+   *   (optional) Boolean whether a failing watchdog message is expected.
+   *   Defaults to TRUE (no fail expected). If FALSE is passed, the logic for
+   *   assertion mesages is flipped.
+   * @param $type
+   *   (optional) A log message type to limit the assertion to, e.g. 'user',
+   *   'page not found', 'access denied', or 'php'.
+   */
+  protected function assertWatchdogMessages($no_fail_expected = TRUE, $type = NULL) {
+    static $seen_ids = array(), $table_exists;
+
+    // @todo Implement simpletest_watchdog() to perform independent logging.
+    if (!isset($table_exists)) {
+      $table_exists = db_table_exists('watchdog');
+    }
+
+    $query = db_select('watchdog', 'w')
+      ->fields('w')
+      ->orderBy('timestamp');
+    if (isset($type)) {
+      $query->condition('w.type', $type);
+    }
+    if (!empty($seen_ids)) {
+      $query->condition('w.wid', $seen_ids, 'NOT IN');
+    }
+    foreach ($query->execute() as $dblog) {
+      // Legacy messages and user specified text.
+      if ($dblog->variables === 'N;') {
+        $message = $dblog->message;
+      }
+      // Message to translate with injected variables.
+      else {
+        $message = t($dblog->message, unserialize($dblog->variables));
+      }
+      if ($no_fail_expected ? $dblog->severity >= WATCHDOG_NOTICE : $dblog->severity < WATCHDOG_NOTICE) {
+        $this->pass($message, t('Watchdog'));
+      }
+      else {
+        $this->fail($message, t('Watchdog'));
+      }
+      $seen_ids[] = $dblog->wid;
+    }
+  }
+
+  /**
    * Initializes the cURL connection.
    *
    * If the simpletest_httpauth_credentials variable is set, this function will
