<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet href="/assets/rss.xsl" type="text/xsl"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"

>
<channel>
	<title>Sacha Chua - tag - patch</title>
	<atom:link href="https://sachachua.com/blog/tag/patch/feed/index.xml" rel="self" type="application/rss+xml" />
	<atom:link href="https://sachachua.com/blog/tag/patch" rel="alternate" type="text/html" />
	<link>https://sachachua.com/blog/tag/patch/feed/index.xml</link>
	<description>Emacs, sketches, and life</description>
  
	<lastBuildDate>Tue, 09 Jun 2026 02:51:39 GMT</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>daily</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>11ty</generator>
  <item>
		<title>Running groups of Drupal tests from the command line</title>
		<link>https://sachachua.com/blog/2008/08/running-groups-of-drupal-tests-from-the-command-line/</link>
		<dc:creator><![CDATA[Sacha Chua]]></dc:creator>
		<pubDate>Tue, 19 Aug 2008 07:26:20 GMT</pubDate>
    <category>drupal</category>
		<guid isPermaLink="false">https://sachachua.com/blog/?p=5074</guid>
		<description><![CDATA[<p>I&#8217;ve written about using <a href="http://www.drupal.org/projects/drush">drush</a> to <a href="https://sachachua.com/blog/2008/08/05/drupal-shell-quickly-evaluating-php-statements-in-a-drupal-context/">evaluate PHP statements in the Drupal context using the command line</a> before, and it turns out that Drush is also quite useful for running Simpletest scripts. Drush comes with a module that allows you to display all the available tests with &#8220;drush test list&#8221;, run all the tests with &#8220;drush test run&#8221;, or run specified tests with &#8220;drush test run test1,test2&#8221;.</p>
<p>&#8216;Course, I wanted to run groups of tests and tests matching regular expressions, so I defined two new commands:</p>
<dl>
<dt>drush test run re <em>regular-expression</em></dt>
<dd>Run all tests matching a regular expression that uses ereg(..) to match.</dd>
<dd>Ex: drush test run re Example.*</dd>
<dt>drush test run group <em>group1,group2&#8230;</em></dt>
<dd>Run all tests matching the given groups</dd>
<dd>Ex: drush test run group Example</dd>
</dl>
<p>Here&#8217;s the patch to make it happen:</p>
<pre>
Index: drush_simpletest.module
===================================================================
&#45;&#45;- drush_simpletest.module	(revision 884)
+++ drush_simpletest.module	(working copy)
@@ -12,9 +12,13 @@
 function drush_simpletest_help($section) {
   switch ($section) {
       case 'drush:test run':
-        return t("Usage drush [options] test run<classes>.\n\nRun the specified specified unit tests. If </classes><classes> is omitted, all tests are run. </classes><classes> should be a list of classes separated by a comma. For example: PageCreationTest,PageViewTest.");
+        return t("Usage drush [options] test run </classes><classes>.\n\nRun the specified unit tests. If </classes><classes> is omitted, all tests are run. </classes><classes> should be a list of classes separated by a comma. For example: PageCreationTest,PageViewTest.");
       case 'drush:test list':
         return t("Usage drush [options] test list.\n\nList the available tests. Use drush test run command to run them. ");
+      case 'drush:test group':
+        return t("Usage drush [options] test group <groups>.\n\nRun all unit tests in the specified groups. For example: drush test group Group1,Group2");
+      case 'drush:test re':
+        return t("Usage drush [options] test re <regular expression="">.\n\nRun all unit tests matching this regular expression. For example: drush test re Page.*");
   }
 }
 
@@ -30,10 +34,18 @@
     'callback' => 'drush_test_list',
     'description' => 'List the available Simpletest test classes.',
   );
+  $items['test re'] = array(
+    'callback' => 'drush_test_re',
+    'description' => 'Run one or more Simpletest tests based on regular expressions.',
+  );
+  $items['test group'] = array(
+    'callback' => 'drush_test_group',
+    'description' => 'Run one or more Simpletest test groups.',
+  );
   return $items;
 }
 
-function drush_test_list() {
+function drush_test_get_list() {
   simpletest_load();
   // TODO: Refactor simpletest.module so we don't copy code from DrupalUnitTests
   $files = array();
@@ -60,6 +72,11 @@
       $rows[] = array($class, $info['name'], truncate_utf8($info['desc'], 30, TRUE, TRUE));
     }
   }
+  return $rows;
+}
+
+function drush_test_list() {
+  $rows = drush_test_get_list();
   return drush_print_table($rows, 0, TRUE);
 }
 
@@ -75,3 +92,31 @@
   }
   return $result;
 }
+
+function drush_test_re($expression) {
+  if (!$expression) {
+    die('You must specify a regular expression.');
+  }
+  $rows = drush_test_get_list();
+  $tests = array();
+  foreach ($rows as $row) {
+    if (ereg($expression, $row[0])) {
+      $tests[] = $row[0];
+    }
+  }
+  simpletest_run_tests($tests, 'text');
+  return $result;
+}
+
+function drush_test_group($groups) {
+  $rows = drush_test_get_list();
+  $tests = array();
+  $groups = explode(',', $groups);
+  foreach ($rows as $row) {
+    if (in_array($row[1], $groups)) {
+      $tests[] = $row[0];
+    }
+  }
+  simpletest_run_tests($tests, 'text');
+  return $result;
+}
</regular></groups></classes></pre>
<p>That makes running tests so much easier and more fun!</p>

<p>You can <a href="https://sachachua.com/blog/2008/08/running-groups-of-drupal-tests-from-the-command-line/#comment">view 1 comment</a> or <a href="mailto:sacha@sachachua.com?subject=Comment%20on%20https%3A%2F%2Fsachachua.com%2Fblog%2F2008%2F08%2Frunning-groups-of-drupal-tests-from-the-command-line%2F&body=Name%20you%20want%20to%20be%20credited%20by%20(if%20any)%3A%20%0AMessage%3A%20%0ACan%20I%20share%20your%20comment%20so%20other%20people%20can%20learn%20from%20it%3F%20Yes%2FNo%0A">e-mail me at sacha@sachachua.com</a>.</p>]]></description>
		</item>
	</channel>
</rss>