]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use PhutilConsole in lint and unit
authorvrana <jakubv@fb.com>
Sun, 5 Aug 2012 02:23:53 +0000 (19:23 -0700)
committervrana <jakubv@fb.com>
Mon, 6 Aug 2012 01:39:32 +0000 (18:39 -0700)
Test Plan:
`arc lint` with OK result and with patchable error.
`arc unit` with passes and errors.
`arc diff` with patchable lint error.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D3151

src/workflow/ArcanistLintWorkflow.php
src/workflow/ArcanistUnitWorkflow.php

index cd8cb8fc2a63c0260f779668e8904830f979473e..89fd54bd88274c49bbdf328e5700e8df40b61282 100644 (file)
@@ -263,6 +263,8 @@ EOTEXT
 
     $all_autofix = true;
 
+    $console = PhutilConsole::getConsole();
+
     foreach ($results as $result) {
       $result_all_autofix = $result->isAllAutofix();
 
@@ -276,7 +278,7 @@ EOTEXT
 
       $lint_result = $renderer->renderLintResult($result);
       if ($lint_result) {
-        echo $lint_result;
+        $console->writeOut('%s', $lint_result);
       }
 
       if ($apply_patches && $result->isPatchable()) {
@@ -294,12 +296,15 @@ EOTEXT
 
           // TODO: Improve the behavior here, make it more like
           // difference_render().
-          passthru(csprintf("diff -u %s %s", $old_file, $new_file));
+          list(, $stdout, $stderr) =
+            exec_manual("diff -u %s %s", $old_file, $new_file);
+          $console->writeOut('%s', $stdout);
+          $console->writeErr('%s', $stderr);
 
           $prompt = phutil_console_format(
             "Apply this patch to __%s__?",
             $result->getPath());
-          if (!phutil_console_confirm($prompt, $default_no = false)) {
+          if (!$console->confirm($prompt, $default_no = false)) {
             continue;
           }
         }
@@ -316,12 +321,12 @@ EOTEXT
 
       if ($this->shouldAmendWithoutPrompt ||
           ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {
-        echo phutil_console_format(
+        $console->writeOut(
           "<bg:yellow>** LINT NOTICE **</bg> Automatically amending HEAD ".
           "with lint patches.\n");
         $amend = true;
       } else {
-        $amend = phutil_console_confirm("Amend HEAD with lint patches?");
+        $amend = $console->confirm("Amend HEAD with lint patches?");
       }
 
       if ($amend) {
@@ -367,7 +372,7 @@ EOTEXT
 
     if (!$this->getParentWorkflow()) {
       if ($result_code == self::RESULT_OKAY) {
-        echo $renderer->renderOkayResult();
+        $console->writeOut('%s', $renderer->renderOkayResult());
       }
     }
 
index 8666e63fdfb042d6cabe2f49694a1689688758d2..fe28b75448853ca749e67b54797ea5244068da0e 100644 (file)
@@ -163,6 +163,8 @@ EOTEXT
         '<bg:yellow>** POSTPONED **</bg>'),
       );
 
+    $console = PhutilConsole::getConsole();
+
     $unresolved = array();
     $coverage = array();
     $postponed_count = 0;
@@ -173,15 +175,18 @@ EOTEXT
         $unresolved[] = $result;
       } else {
         if ($this->engine->shouldEchoTestResults()) {
-          echo '  '.$status_codes[$result_code];
+          $duration = '';
           if ($result_code == ArcanistUnitTestResult::RESULT_PASS) {
-            echo ' '.self::formatTestDuration($result->getDuration());
+            $duration = ' '.self::formatTestDuration($result->getDuration());
           }
-          echo ' '.$result->getName()."\n";
+          $console->writeOut(
+            "  %s %s\n",
+            $status_codes[$result_code].$duration,
+            $result->getName());
         }
         if ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
           if ($this->engine->shouldEchoTestResults()) {
-            echo $result->getUserData()."\n";
+            $console->writeOut("%s\n", $result->getUserData());
           }
           $unresolved[] = $result;
         }
@@ -193,9 +198,10 @@ EOTEXT
       }
     }
     if ($postponed_count) {
-      echo sprintf("%s %s\n",
-         $status_codes[ArcanistUnitTestResult::RESULT_POSTPONED],
-         pht('%d test(s)', $postponed_count));
+      $console->writeOut(
+        "%s %s\n",
+        $status_codes[ArcanistUnitTestResult::RESULT_POSTPONED],
+        pht('%d test(s)', $postponed_count));
     }
 
     if ($coverage) {
@@ -215,13 +221,11 @@ EOTEXT
         $file_coverage[$file] = $coverage;
         $file_reports[$file] = $report;
       }
-      echo "\n";
-      echo phutil_console_format('__COVERAGE REPORT__');
-      echo "\n";
+      $console->writeOut("\n__COVERAGE REPORT__\n");
 
       asort($file_coverage);
       foreach ($file_coverage as $file => $coverage) {
-        echo phutil_console_format(
+        $console->writeOut(
           "    **%s%%**     %s\n",
           sprintf('% 3d', (int)(100 * $coverage)),
           $file);
@@ -230,9 +234,11 @@ EOTEXT
         if ($this->getArgument('detailed-coverage') &&
             Filesystem::pathExists($full_path) &&
             is_file($full_path)) {
-          echo $this->renderDetailedCoverageReport(
-            Filesystem::readFile($full_path),
-            $file_reports[$file]);
+          $console->writeOut(
+            '%s',
+            $this->renderDetailedCoverageReport(
+              Filesystem::readFile($full_path),
+              $file_reports[$file]));
         }
       }
     }