From 5d6e2a4e08163420cbe13dbed2b8032c31aa1b74 Mon Sep 17 00:00:00 2001 From: vrana Date: Sat, 4 Aug 2012 19:23:53 -0700 Subject: [PATCH] Use PhutilConsole in lint and unit 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 | 17 +++++++++----- src/workflow/ArcanistUnitWorkflow.php | 34 ++++++++++++++++----------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/workflow/ArcanistLintWorkflow.php b/src/workflow/ArcanistLintWorkflow.php index cd8cb8fc..89fd54bd 100644 --- a/src/workflow/ArcanistLintWorkflow.php +++ b/src/workflow/ArcanistLintWorkflow.php @@ -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( "** LINT NOTICE ** 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()); } } diff --git a/src/workflow/ArcanistUnitWorkflow.php b/src/workflow/ArcanistUnitWorkflow.php index 8666e63f..fe28b754 100644 --- a/src/workflow/ArcanistUnitWorkflow.php +++ b/src/workflow/ArcanistUnitWorkflow.php @@ -163,6 +163,8 @@ EOTEXT '** POSTPONED **'), ); + $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])); } } }