]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Automatically use the configuration driven unit test engine
authorJoshua Spence <josh@joshuaspence.com>
Mon, 10 Aug 2015 21:55:38 +0000 (07:55 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Mon, 10 Aug 2015 21:55:57 +0000 (07:55 +1000)
Summary: Ref T5568. Use the `ArcanistConfigurationDrivenUnitTestEngine` automatically, if an `.arcunit` file exists. This behavior mimics the auto-detection for the configuration driven lint engine.

Test Plan:
Ran through the following scenarios:

  - Ran `arc unit` and saw unit tests execute.
  - Ran `arc unit --engine PhutilUnitTestEngine`
  - Remove the `.arcunit` file and ran `arc unit`... got an exception.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin

Maniphest Tasks: T5568

Differential Revision: https://secure.phabricator.com/D13855

.arcconfig
src/workflow/ArcanistUnitWorkflow.php
src/workflow/ArcanistWorkflow.php

index 1309022caa685d73801e668c0f4b4c1db7c93997..66841c44ce7676ff79054cc66c7124974e9f5444 100644 (file)
@@ -1,6 +1,5 @@
 {
   "phabricator.uri": "https://secure.phabricator.com/",
-  "unit.engine": "ArcanistConfigurationDrivenUnitTestEngine",
   "load": [
     "src/"
   ]
index 567b772e0da37cc4b6090f84ee0f546043300d73..a97bbdeb8a2e38d49cb03b79944bbbfd80d4afd0 100644 (file)
@@ -113,21 +113,8 @@ EOTEXT
   }
 
   public function run() {
-
     $working_copy = $this->getWorkingCopy();
 
-    $engine_class = $this->getArgument(
-      'engine',
-      $this->getConfigurationManager()->getConfigFromAnySource('unit.engine'));
-
-    if (!$engine_class) {
-      throw new ArcanistNoEngineException(
-        pht(
-          'No unit test engine is configured for this project. Edit %s '.
-          'to specify a unit test engine.',
-          '.arcconfig'));
-    }
-
     $paths = $this->getArgument('paths');
     $rev = $this->getArgument('rev');
     $everything = $this->getArgument('everything');
@@ -145,18 +132,7 @@ EOTEXT
       $paths = $this->selectPathsForWorkflow($paths, $rev);
     }
 
-    if (!class_exists($engine_class) ||
-        !is_subclass_of($engine_class, 'ArcanistUnitTestEngine')) {
-      throw new ArcanistUsageException(
-        pht(
-          "Configured unit test engine '%s' is not a subclass of '%s'.",
-          $engine_class,
-          'ArcanistUnitTestEngine'));
-    }
-
-    $this->engine = newv($engine_class, array());
-    $this->engine->setWorkingCopy($working_copy);
-    $this->engine->setConfigurationManager($this->getConfigurationManager());
+    $this->engine = $this->newUnitTestEngine($this->getArgument('engine'));
     if ($everything) {
       $this->engine->setRunAllTests(true);
     } else {
index dc4913e22148376740fbdcaf1986d1bbb75d6d0f..87b3760553a0b7ea7c6eaa3487537bbaa5145e58 100644 (file)
@@ -1878,6 +1878,59 @@ abstract class ArcanistWorkflow extends Phobject {
     return $engine;
   }
 
+  /**
+   * Build a new unit test engine for the current working copy.
+   *
+   * Optionally, you can pass an explicit engine class name to build an engine
+   * of a particular class. Normally this is used to implement an `--engine`
+   * flag from the CLI.
+   *
+   * @param string Optional explicit engine class name.
+   * @return ArcanistUnitTestEngine Constructed engine.
+   */
+  protected function newUnitTestEngine($engine_class = null) {
+    $working_copy = $this->getWorkingCopy();
+    $config = $this->getConfigurationManager();
+
+    if (!$engine_class) {
+      $engine_class = $config->getConfigFromAnySource('unit.engine');
+    }
+
+    if (!$engine_class) {
+      if (Filesystem::pathExists($working_copy->getProjectPath('.arcunit'))) {
+        $engine_class = 'ArcanistConfigurationDrivenUnitTestEngine';
+      }
+    }
+
+    if (!$engine_class) {
+      throw new ArcanistNoEngineException(
+        pht(
+          "No unit test engine is configured for this project. Create an ".
+          "'%s' file, or configure an advanced engine with '%s' in '%s'.",
+          '.arcunit',
+          'unit.engine',
+          '.arcconfig'));
+    }
+
+    $base_class = 'ArcanistUnitTestEngine';
+    if (!class_exists($engine_class) ||
+        !is_subclass_of($engine_class, $base_class)) {
+      throw new ArcanistUsageException(
+        pht(
+          'Configured unit test engine "%s" is not a subclass of "%s", '.
+          'but must be.',
+          $engine_class,
+          $base_class));
+    }
+
+    $engine = newv($engine_class, array())
+      ->setWorkingCopy($working_copy)
+      ->setConfigurationManager($config);
+
+    return $engine;
+  }
+
+
   protected function openURIsInBrowser(array $uris) {
     $browser = $this->getBrowserCommand();
     foreach ($uris as $uri) {