1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-01 19:22:41 +01:00

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
This commit is contained in:
vrana 2012-08-04 19:23:53 -07:00
parent 877e6f743b
commit 5d6e2a4e08
2 changed files with 31 additions and 20 deletions

View file

@ -263,6 +263,8 @@ EOTEXT
$all_autofix = true; $all_autofix = true;
$console = PhutilConsole::getConsole();
foreach ($results as $result) { foreach ($results as $result) {
$result_all_autofix = $result->isAllAutofix(); $result_all_autofix = $result->isAllAutofix();
@ -276,7 +278,7 @@ EOTEXT
$lint_result = $renderer->renderLintResult($result); $lint_result = $renderer->renderLintResult($result);
if ($lint_result) { if ($lint_result) {
echo $lint_result; $console->writeOut('%s', $lint_result);
} }
if ($apply_patches && $result->isPatchable()) { if ($apply_patches && $result->isPatchable()) {
@ -294,12 +296,15 @@ EOTEXT
// TODO: Improve the behavior here, make it more like // TODO: Improve the behavior here, make it more like
// difference_render(). // 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( $prompt = phutil_console_format(
"Apply this patch to __%s__?", "Apply this patch to __%s__?",
$result->getPath()); $result->getPath());
if (!phutil_console_confirm($prompt, $default_no = false)) { if (!$console->confirm($prompt, $default_no = false)) {
continue; continue;
} }
} }
@ -316,12 +321,12 @@ EOTEXT
if ($this->shouldAmendWithoutPrompt || if ($this->shouldAmendWithoutPrompt ||
($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) { ($this->shouldAmendAutofixesWithoutPrompt && $all_autofix)) {
echo phutil_console_format( $console->writeOut(
"<bg:yellow>** LINT NOTICE **</bg> Automatically amending HEAD ". "<bg:yellow>** LINT NOTICE **</bg> Automatically amending HEAD ".
"with lint patches.\n"); "with lint patches.\n");
$amend = true; $amend = true;
} else { } else {
$amend = phutil_console_confirm("Amend HEAD with lint patches?"); $amend = $console->confirm("Amend HEAD with lint patches?");
} }
if ($amend) { if ($amend) {
@ -367,7 +372,7 @@ EOTEXT
if (!$this->getParentWorkflow()) { if (!$this->getParentWorkflow()) {
if ($result_code == self::RESULT_OKAY) { if ($result_code == self::RESULT_OKAY) {
echo $renderer->renderOkayResult(); $console->writeOut('%s', $renderer->renderOkayResult());
} }
} }

View file

@ -163,6 +163,8 @@ EOTEXT
'<bg:yellow>** POSTPONED **</bg>'), '<bg:yellow>** POSTPONED **</bg>'),
); );
$console = PhutilConsole::getConsole();
$unresolved = array(); $unresolved = array();
$coverage = array(); $coverage = array();
$postponed_count = 0; $postponed_count = 0;
@ -173,15 +175,18 @@ EOTEXT
$unresolved[] = $result; $unresolved[] = $result;
} else { } else {
if ($this->engine->shouldEchoTestResults()) { if ($this->engine->shouldEchoTestResults()) {
echo ' '.$status_codes[$result_code]; $duration = '';
if ($result_code == ArcanistUnitTestResult::RESULT_PASS) { 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 ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
if ($this->engine->shouldEchoTestResults()) { if ($this->engine->shouldEchoTestResults()) {
echo $result->getUserData()."\n"; $console->writeOut("%s\n", $result->getUserData());
} }
$unresolved[] = $result; $unresolved[] = $result;
} }
@ -193,7 +198,8 @@ EOTEXT
} }
} }
if ($postponed_count) { if ($postponed_count) {
echo sprintf("%s %s\n", $console->writeOut(
"%s %s\n",
$status_codes[ArcanistUnitTestResult::RESULT_POSTPONED], $status_codes[ArcanistUnitTestResult::RESULT_POSTPONED],
pht('%d test(s)', $postponed_count)); pht('%d test(s)', $postponed_count));
} }
@ -215,13 +221,11 @@ EOTEXT
$file_coverage[$file] = $coverage; $file_coverage[$file] = $coverage;
$file_reports[$file] = $report; $file_reports[$file] = $report;
} }
echo "\n"; $console->writeOut("\n__COVERAGE REPORT__\n");
echo phutil_console_format('__COVERAGE REPORT__');
echo "\n";
asort($file_coverage); asort($file_coverage);
foreach ($file_coverage as $file => $coverage) { foreach ($file_coverage as $file => $coverage) {
echo phutil_console_format( $console->writeOut(
" **%s%%** %s\n", " **%s%%** %s\n",
sprintf('% 3d', (int)(100 * $coverage)), sprintf('% 3d', (int)(100 * $coverage)),
$file); $file);
@ -230,9 +234,11 @@ EOTEXT
if ($this->getArgument('detailed-coverage') && if ($this->getArgument('detailed-coverage') &&
Filesystem::pathExists($full_path) && Filesystem::pathExists($full_path) &&
is_file($full_path)) { is_file($full_path)) {
echo $this->renderDetailedCoverageReport( $console->writeOut(
'%s',
$this->renderDetailedCoverageReport(
Filesystem::readFile($full_path), Filesystem::readFile($full_path),
$file_reports[$file]); $file_reports[$file]));
} }
} }
} }