commit 82b1bdd0392e34de712760d081f2ebced2c7dae7
Author: Antoine Beaupré <anarcat@koumbit.org>
Date:   Wed Apr 20 09:55:34 2011 -0400

    1133284 split up unit from functional tests
    
    this is mostly moving code around and renaming the Drush_TestCase class

diff --git a/tests/backendTest.php b/tests/backendTest.php
index 935c830..f6ccba8 100644
--- a/tests/backendTest.php
+++ b/tests/backendTest.php
@@ -13,7 +13,7 @@
 *    - No network calls and thus faster.
 */
 
-class backendCase extends Drush_TestCase {
+class backendCase extends Drush_CommandTestCase {
   const DRUSH_BACKEND_OUTPUT_DELIMITER = 'DRUSH_BACKEND_OUTPUT_START>>>%s<<<DRUSH_BACKEND_OUTPUT_END';
 
   /*
diff --git a/tests/commandTest.php b/tests/commandTest.php
index 0ee8e57..7cb022a 100644
--- a/tests/commandTest.php
+++ b/tests/commandTest.php
@@ -1,6 +1,6 @@
 <?php
 
-class commandCase extends Drush_TestCase {
+class commandCase extends Drush_CommandTestCase {
   public function testInvoke() {
     $expected = array(
       'unit_drush_init',
diff --git a/tests/contextTest.php b/tests/contextTest.php
index dbbcd96..5d89a4d 100644
--- a/tests/contextTest.php
+++ b/tests/contextTest.php
@@ -8,7 +8,7 @@
 *  @see drush/includes/context.inc.
 */
 
-class contextCase extends Drush_TestCase {
+class contextCase extends Drush_CommandTestCase {
 
   function setUpPaths() {
     $this->root = $this->sites[$this->env]['root'];
diff --git a/tests/coreTest.php b/tests/coreTest.php
index 0d57650..7f75b2b 100644
--- a/tests/coreTest.php
+++ b/tests/coreTest.php
@@ -4,7 +4,7 @@
  * @file
  *   Tests for core commands.
  */
-class coreCase extends Drush_TestCase {
+class coreCase extends Drush_CommandTestCase {
 
   /*
    * Test standalone php-script scripts. Assure that script args and options work.
diff --git a/tests/drush_testcase.inc b/tests/drush_testcase.inc
index 49747fb..05dbbfe 100644
--- a/tests/drush_testcase.inc
+++ b/tests/drush_testcase.inc
@@ -10,112 +10,11 @@ if (!defined('UNISH_DRUSH')) {
 
 abstract class Drush_TestCase extends PHPUnit_Framework_TestCase {
 
-  // Unix exit codes.
-  const EXIT_SUCCESS  = 0;
-  const EXIT_ERROR = 1;
-  /*
-   * An array of Drupal sites that are setup in the drush-sandbox.
-   */
-  var $sites;
-
   function __construct() {
     $this->_output = false;
   }
 
   /**
-   * Assure that each class starts with an empty sandbox directory.
-   */
-  public static function setUpBeforeClass() {
-    $sandbox = $GLOBALS['UNISH_SANDBOX'];
-    if (file_exists($sandbox)) {
-      self::file_delete_recursive($sandbox);
-    }
-    $ret = mkdir($sandbox);
-    // Path must exist before we call realpath().
-    if (!defined('UNISH_SANDBOX')) {
-      define('UNISH_SANDBOX', realpath($sandbox));
-    }
-    chdir(UNISH_SANDBOX);
-
-    // Assure a clean environment - http://drupal.org/node/1103568
-    $home = UNISH_SANDBOX . '/home';
-    mkdir("$home/.drush", 0777, TRUE);
-    putenv("HOME=$home");
-    putenv("HOMEDRIVE=$home");
-    $sandbox = UNISH_SANDBOX;
-    mkdir($sandbox . '/etc/drush', 0777, TRUE);
-    mkdir($sandbox . '/share/drush/commands', 0777, TRUE);
-    putenv("ETC_PREFIX=$sandbox");
-    putenv("SHARE_PREFIX=$sandbox");
-  }
-
-  /**
-   * Runs after each test case. Remove sandbox directory.
-   */
-  public static function tearDownAfterClass() {
-    if (file_exists(UNISH_SANDBOX)) {
-      self::file_delete_recursive(UNISH_SANDBOX);
-    }
-  }
-
-  /**
-   * Actually runs the command. Does not trap the error stream output as this
-   * need PHP 4.3+.
-   *
-   * @param string $command
-   *   The actual command line to run.
-   * @return integer
-   *   Exit code. Usually self::EXIT_ERROR or self::EXIT_SUCCESS.
-   */
-  function execute($command, $expected_return = self::EXIT_SUCCESS) {
-    $this->_output = FALSE;
-    // todo check verbose level from phpunit.
-    if (TRUE) {
-      print "\nExecuting: $command \n";
-    }
-    exec($command, $this->_output, $return);
-    $this->assertEquals($expected_return, $return, 'Unexpected exit code: ' .  $command);
-    return $return;
-  }
-
-  /**
-   * Invoke drush in via execute().
-   *
-   * @param command
-    *   A defined drush command such as 'cron', 'status' or any of the available ones such as 'drush pm'.
-    * @param args
-    *   Command arguments.
-    * @param $options
-    *   An associative array containing options.
-    * @param $site_specification
-    *   A site alias or site specification. Include the '@' at start of a site alias.
-    * @param $cd
-    *   A directory to change into before executing.
-    * @return integer
-    *   An exit code.
-    */
-  function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL) {
-    $cmd[] = $cd ? sprintf('cd %s;', escapeshellarg($cd)) : NULL;
-    $cmd[] = UNISH_DRUSH;
-    $cmd[] = empty($site_specification) ? NULL : escapeshellarg($site_specification);
-    $cmd[] = $command;
-    foreach ($args as $arg) {
-      $cmd[] = escapeshellarg($arg);
-    }
-    $options['nocolor'] = NULL;
-    foreach ($options as $key => $value) {
-      if (is_null($value)) {
-        $cmd[] = "--$key";
-      }
-      else {
-        $cmd[] = "--$key=" . escapeshellarg($value);
-      }
-    }
-    $exec = array_filter($cmd, 'strlen'); // Remove NULLs
-    return $this->execute(implode(' ', $exec));
-  }
-
-  /**
    *    Accessor for the last output.
    *    @return string        Output as text.
    *    @access public
@@ -221,4 +120,154 @@ abstract class Drush_TestCase extends PHPUnit_Framework_TestCase {
   function file_delete_recursive($path) {
     return exec('rm -rf ' . escapeshellarg($path));
   }
-}
\ No newline at end of file
+}
+
+abstract class Drush_CommandTestCase extends Drush_TestCase {
+
+  // Unix exit codes.
+  const EXIT_SUCCESS  = 0;
+  const EXIT_ERROR = 1;
+  /*
+   * An array of Drupal sites that are setup in the drush-sandbox.
+   */
+  var $sites;
+
+  /**
+   * Assure that each class starts with an empty sandbox directory.
+   */
+  public static function setUpBeforeClass() {
+    $sandbox = $GLOBALS['UNISH_SANDBOX'];
+    if (file_exists($sandbox)) {
+      self::file_delete_recursive($sandbox);
+    }
+    $ret = mkdir($sandbox);
+    // Path must exist before we call realpath().
+    if (!defined('UNISH_SANDBOX')) {
+      define('UNISH_SANDBOX', realpath($sandbox));
+    }
+    chdir(UNISH_SANDBOX);
+
+    // Assure a clean environment - http://drupal.org/node/1103568
+    $home = UNISH_SANDBOX . '/home';
+    mkdir("$home/.drush", 0777, TRUE);
+    putenv("HOME=$home");
+    putenv("HOMEDRIVE=$home");
+    $sandbox = UNISH_SANDBOX;
+    mkdir($sandbox . '/etc/drush', 0777, TRUE);
+    mkdir($sandbox . '/share/drush/commands', 0777, TRUE);
+    putenv("ETC_PREFIX=$sandbox");
+    putenv("SHARE_PREFIX=$sandbox");
+  }
+
+  /**
+   * Runs after each test case. Remove sandbox directory.
+   */
+  public static function tearDownAfterClass() {
+    if (file_exists(UNISH_SANDBOX)) {
+      self::file_delete_recursive(UNISH_SANDBOX);
+    }
+  }
+
+  /**
+   * Actually runs the command. Does not trap the error stream output as this
+   * need PHP 4.3+.
+   *
+   * @param string $command
+   *   The actual command line to run.
+   * @return integer
+   *   Exit code. Usually self::EXIT_ERROR or self::EXIT_SUCCESS.
+   */
+  function execute($command, $expected_return = self::EXIT_SUCCESS) {
+    $this->_output = FALSE;
+    // todo check verbose level from phpunit.
+    if (TRUE) {
+      print "\nExecuting: $command \n";
+    }
+    exec($command, $this->_output, $return);
+    $this->assertEquals($expected_return, $return, 'Unexpected exit code: ' .  $command);
+    return $return;
+  }
+
+  /**
+   * Invoke drush in via execute().
+   *
+   * @param command
+    *   A defined drush command such as 'cron', 'status' or any of the available ones such as 'drush pm'.
+    * @param args
+    *   Command arguments.
+    * @param $options
+    *   An associative array containing options.
+    * @param $site_specification
+    *   A site alias or site specification. Include the '@' at start of a site alias.
+    * @param $cd
+    *   A directory to change into before executing.
+    * @return integer
+    *   An exit code.
+    */
+  function drush($command, array $args = array(), array $options = array(), $site_specification = NULL, $cd = NULL) {
+    $cmd[] = $cd ? sprintf('cd %s;', escapeshellarg($cd)) : NULL;
+    $cmd[] = UNISH_DRUSH;
+    $cmd[] = empty($site_specification) ? NULL : escapeshellarg($site_specification);
+    $cmd[] = $command;
+    foreach ($args as $arg) {
+      $cmd[] = escapeshellarg($arg);
+    }
+    $options['nocolor'] = NULL;
+    foreach ($options as $key => $value) {
+      if (is_null($value)) {
+        $cmd[] = "--$key";
+      }
+      else {
+        $cmd[] = "--$key=" . escapeshellarg($value);
+      }
+    }
+    $exec = array_filter($cmd, 'strlen'); // Remove NULLs
+    return $this->execute(implode(' ', $exec));
+  }
+
+}
+
+/**
+ * Base class for Drush unit tests
+ *
+ * Those tests will run in a bootstrapped Drush environment
+ *
+ * This should be ran in separate processes, which the following
+ * annotation should do in 3.6 and above:
+ *
+ * @runTestsInSeparateProcesses
+ */
+abstract class Drush_UnitTestCase extends Drush_TestCase {
+
+  /**
+   * Minimally bootstrap drush
+   *
+   * This is equivalent to the level DRUSH_BOOTSTRAP_NONE, as we
+   * haven't run drush_bootstrap() yet. To do anything, you'll need to
+   * bootstrap to some level using drush_bootstrap().
+   *
+   * @see drush_bootstrap()
+   */
+  public static function setUpBeforeClass() {
+    // mostly taken from drush.php
+    define('DRUSH_BASE_PATH', dirname(__FILE__).'/../');
+    define('DRUSH_REQUEST_TIME', microtime(TRUE));
+
+    require_once DRUSH_BASE_PATH . '/includes/environment.inc';
+    require_once DRUSH_BASE_PATH . '/includes/command.inc';
+    require_once DRUSH_BASE_PATH . '/includes/drush.inc';
+    require_once DRUSH_BASE_PATH . '/includes/backend.inc';
+    require_once DRUSH_BASE_PATH . '/includes/batch.inc';
+    require_once DRUSH_BASE_PATH . '/includes/context.inc';
+    require_once DRUSH_BASE_PATH . '/includes/sitealias.inc';
+    require_once DRUSH_BASE_PATH . '/includes/exec.inc';
+    require_once DRUSH_BASE_PATH . '/includes/drupal.inc';
+    require_once DRUSH_BASE_PATH . '/includes/output.inc';
+    require_once DRUSH_BASE_PATH . '/includes/filesystem.inc';
+    require_once DRUSH_BASE_PATH . '/includes/dbtng.inc';
+    drush_set_context('argc', $GLOBALS['argc']);
+    drush_set_context('argv', $GLOBALS['argv']);
+    drush_set_context('DRUSH_COLUMNS', 80);
+  }
+
+}
diff --git a/tests/fieldTest.php b/tests/fieldTest.php
index b317d72..0632a8a 100644
--- a/tests/fieldTest.php
+++ b/tests/fieldTest.php
@@ -4,7 +4,7 @@
  * @file
  *   Tests for field.drush.inc
  */
-class fieldCase extends Drush_TestCase {
+class fieldCase extends Drush_CommandTestCase {
 
   public function testField() {
     $this->setUpDrupal('dev', TRUE, '7.x', 'standard');
diff --git a/tests/pmDownloadTest.php b/tests/pmDownloadTest.php
index 449a182..86e3a7d 100644
--- a/tests/pmDownloadTest.php
+++ b/tests/pmDownloadTest.php
@@ -3,7 +3,7 @@
 /**
   * pm-download testing
   */  
-class pmDownloadCase extends Drush_TestCase {
+class pmDownloadCase extends Drush_CommandTestCase {
   public function testPmDownload() {
     $this->drush('pm-download', array('devel'));
     $this->assertFileExists(UNISH_SANDBOX . '/devel/README.txt');
diff --git a/tests/pmEnDisUnListVarTest.php b/tests/pmEnDisUnListVarTest.php
index 72222dd..424e963 100644
--- a/tests/pmEnDisUnListVarTest.php
+++ b/tests/pmEnDisUnListVarTest.php
@@ -4,7 +4,7 @@
  * @file
  *   Tests for enable, disable, uninstall, pm-list, and variable-* commands.
  */
-class EnDisUnListVarCase extends Drush_TestCase {
+class EnDisUnListVarCase extends Drush_CommandTestCase {
 
   public function testEnDisUnListVar() {
     $this->setUpDrupal('dev', TRUE);
diff --git a/tests/pmUpdateCodeTest.php b/tests/pmUpdateCodeTest.php
index d90ee6a..5bc538f 100644
--- a/tests/pmUpdateCodeTest.php
+++ b/tests/pmUpdateCodeTest.php
@@ -7,7 +7,7 @@
   *   @todo test security-only once one of these modules or core gets a security release.
   */
 
-class pmUpdateCode extends Drush_TestCase {
+class pmUpdateCode extends Drush_CommandTestCase {
 
   /*
    * Download old core and older contrib releases which will always need updating.
diff --git a/tests/shellAliasTest.php b/tests/shellAliasTest.php
index 5a186f7..ce67ff7 100644
--- a/tests/shellAliasTest.php
+++ b/tests/shellAliasTest.php
@@ -4,7 +4,7 @@
  * @file
  *   Tests for Shell aliases.
  */
-class shellAliasesCase extends Drush_TestCase {
+class shellAliasesCase extends Drush_CommandTestCase {
 
   /*
    * Assure that shell aliases expand as expected.
diff --git a/tests/siteAliasTest.php b/tests/siteAliasTest.php
index 9e0584b..6887aba 100644
--- a/tests/siteAliasTest.php
+++ b/tests/siteAliasTest.php
@@ -4,7 +4,7 @@
  * @file
  *   Tests for sitealias.inc
  */
-class saCase extends Drush_TestCase {
+class saCase extends Drush_CommandTestCase {
 
   /*
    * Assure that site lists work as expected.
diff --git a/tests/siteUpgradeTest.php b/tests/siteUpgradeTest.php
index 55094ec..b481590 100644
--- a/tests/siteUpgradeTest.php
+++ b/tests/siteUpgradeTest.php
@@ -12,7 +12,7 @@
  *     - updatedb and batch.inc
  */
 
-class siteUpgradeCase extends Drush_TestCase {
+class siteUpgradeCase extends Drush_CommandTestCase {
   function testUpgrade() {
     $env = 'testupgrade';
     $this->setUpDrupal($env, TRUE, '6.x');
diff --git a/tests/userTest.php b/tests/userTest.php
index a3defbe..da07d04 100644
--- a/tests/userTest.php
+++ b/tests/userTest.php
@@ -4,7 +4,7 @@
  * @file
  *   Tests for user.drush.inc
  */
-class userCase extends Drush_TestCase {
+class userCase extends Drush_CommandTestCase {
 
   /*
    * Create, edit, block, and cancel users.
