]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Improve argument passthru behavior to make added args available to test engines.
authorepriestley <epriestley@javelinjs.com>
Wed, 2 Feb 2011 04:32:10 +0000 (20:32 -0800)
committerepriestley <epriestley@javelinjs.com>
Wed, 2 Feb 2011 04:45:32 +0000 (20:45 -0800)
Summary:
When you add new arguments to the unit command, they need to be
threaded through to the unit engine. This enables you to specify passthru
command which will be shipped through the callstack.

Test Plan:
Ran 'arc diff --maxtests 8 --apply-patches --trace' and verified
resulting behavior was correct.

Differential Revision: 207877
Reviewed By: dschleimer
Reviewers: dschleimer
CC: dschleimer
Revert Plan:
OK

src/unit/engine/base/ArcanistBaseUnitTestEngine.php
src/unit/engine/base/__init__.php
src/workflow/base/ArcanistBaseWorkflow.php
src/workflow/diff/ArcanistDiffWorkflow.php
src/workflow/unit/ArcanistUnitWorkflow.php

index 7ec25c5eb83d15dfa4751e96b8ebdfa4c26b2505..cfc1b6f7865784be859e50d54a97e0b99ec08644 100644 (file)
@@ -20,6 +20,7 @@ abstract class ArcanistBaseUnitTestEngine {
 
   private $workingCopy;
   private $paths;
+  private $arguments = array();
 
   final public function __construct() {
 
@@ -45,6 +46,15 @@ abstract class ArcanistBaseUnitTestEngine {
     return $this->paths;
   }
 
+  final public function setArguments(array $arguments) {
+    $this->arguments = $arguments;
+    return $this;
+  }
+
+  final public function getArgument($key, $default = null) {
+    return idx($this->arguments, $key, $default);
+  }
+
   abstract public function run();
 
 }
index 69d1e77a3b92b8613c84002a2f8f6c91428d25b8..3f0e488f6ac54f86ab13b0ca1d665d10220866c9 100644 (file)
@@ -6,5 +6,7 @@
 
 
 
+phutil_require_module('phutil', 'utils');
+
 
 phutil_require_source('ArcanistBaseUnitTestEngine.php');
index a95447663eedc1420819b9ebca741b93f4830817..410040ffeb26e45da77ff6a58384da119ede7fc1 100644 (file)
@@ -555,4 +555,29 @@ class ArcanistBaseWorkflow {
     return array('any');
   }
 
+  protected function getPassthruArgumentsAsMap($command) {
+    $map = array();
+    foreach ($this->getCompleteArgumentSpecification() as $key => $spec) {
+      if (!empty($spec['passthru'][$command])) {
+        if (isset($this->arguments[$key])) {
+          $map[$key] = $this->arguments[$key];
+        }
+      }
+    }
+    return $map;
+  }
+
+  protected function getPassthruArgumentsAsArgv($command) {
+    $spec = $this->getCompleteArgumentSpecification();
+    $map = $this->getPassthruArgumentsAsMap($command);
+    $argv = array();
+    foreach ($map as $key => $value) {
+      $argv[] = '--'.$key;
+      if (!empty($spec[$key]['param'])) {
+        $argv[] = $value;
+      }
+    }
+    return $argv;
+  }
+
 }
index fa0fe94ef095a8617a8bfe12f75127a7e191942e..974253a7f2253c3974df2eb8769966fec858a4cc 100644 (file)
@@ -149,10 +149,16 @@ EOTEXT
       'lintall' => array(
         'help' =>
           "Raise all lint warnings, not just those on lines you changed.",
+        'passthru' => array(
+          'lint' => true,
+        ),
       ),
       'advice' => array(
         'help' =>
           "Raise lint advice in addition to lint warnings and errors.",
+        'passthru' => array(
+          'lint' => true,
+        ),
       ),
       'apply-patches' => array(
         'help' =>
@@ -161,12 +167,18 @@ EOTEXT
         'conflicts' => array(
           'never-apply-patches' => true,
         ),
+        'passthru' => array(
+          'lint' => true,
+        ),
       ),
       'never-apply-patches' => array(
         'help' => 'Never apply patches suggested by lint.',
         'conflicts' => array(
           'apply-patches' => true,
         ),
+        'passthru' => array(
+          'lint' => true,
+        ),
       ),
       '*' => 'paths',
     );
@@ -836,19 +848,7 @@ EOTEXT
 
     echo "Linting...\n";
     try {
-      $argv = array();
-      if ($this->getArgument('lintall')) {
-        $argv[] = '--lintall';
-      }
-      if ($this->getArgument('advice')) {
-        $argv[] = '--advice';
-      }
-      if ($this->getArgument('apply-patches')) {
-        $argv[] = '--apply-patches';
-      }
-      if ($this->getArgument('never-apply-patches')) {
-        $argv[] = '--never-apply-patches';
-      }
+      $argv = $this->getPassthruArgumentsAsArgv('lint');
       if ($repository_api instanceof ArcanistSubversionAPI) {
         $argv = array_merge($argv, array_keys($paths));
       } else {
@@ -905,7 +905,7 @@ EOTEXT
 
     echo "Running unit tests...\n";
     try {
-      $argv = array();
+      $argv = $this->getPassthruArgumentsAsArgv('unit');
       if ($repository_api instanceof ArcanistSubversionAPI) {
         $argv = array_merge($argv, array_keys($paths));
       }
index 800d4d0bce2422375eda4b0133ad85e8c65d0e37..e4d517e898ae6bf2142ebfdf77543fd2f18b7934 100644 (file)
@@ -77,6 +77,7 @@ EOTEXT
     $engine = newv($engine_class, array());
     $engine->setWorkingCopy($working_copy);
     $engine->setPaths($paths);
+    $engine->setArguments($this->getPassthruArgumentsAsMap('unit'));
 
     $results = $engine->run();