2011-01-09 15:22:25 -08:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 11:36:08 -08:00
|
|
|
/**
|
|
|
|
* Runs unit tests which cover your changes.
|
|
|
|
*/
|
2014-07-22 07:49:15 +10:00
|
|
|
final class ArcanistUnitWorkflow extends ArcanistWorkflow {
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2011-06-08 16:36:17 -07:00
|
|
|
const RESULT_OKAY = 0;
|
|
|
|
const RESULT_UNSOUND = 1;
|
|
|
|
const RESULT_FAIL = 2;
|
|
|
|
const RESULT_SKIP = 3;
|
|
|
|
const RESULT_POSTPONED = 4;
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2011-01-11 22:13:31 -08:00
|
|
|
private $unresolvedTests;
|
2012-01-31 12:07:19 -08:00
|
|
|
private $testResults;
|
2011-05-27 16:15:43 -07:00
|
|
|
private $engine;
|
2011-01-11 22:13:31 -08:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 08:35:03 -07:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'unit';
|
|
|
|
}
|
|
|
|
|
2012-03-05 10:02:37 -08:00
|
|
|
public function getCommandSynopses() {
|
2011-01-09 15:22:25 -08:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 12:40:50 -08:00
|
|
|
**unit** [__options__] [__paths__]
|
|
|
|
**unit** [__options__] --rev [__rev__]
|
2012-03-05 10:02:37 -08:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 12:40:50 -08:00
|
|
|
Supports: git, svn, hg
|
2011-11-30 12:56:18 -08:00
|
|
|
Run unit tests that cover specified paths. If no paths are specified,
|
|
|
|
unit tests covering all modified files will be run.
|
2011-01-09 15:22:25 -08:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 12:40:50 -08:00
|
|
|
'rev' => array(
|
|
|
|
'param' => 'revision',
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht(
|
|
|
|
'Run unit tests covering changes since a specific revision.'),
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 12:40:50 -08:00
|
|
|
'supports' => array(
|
|
|
|
'git',
|
|
|
|
'hg',
|
|
|
|
),
|
|
|
|
'nosupport' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'svn' => pht(
|
|
|
|
'Arc unit does not currently support %s in SVN.',
|
|
|
|
'--rev'),
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 12:40:50 -08:00
|
|
|
),
|
|
|
|
),
|
2011-02-16 11:53:13 -08:00
|
|
|
'engine' => array(
|
|
|
|
'param' => 'classname',
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht('Override configured unit engine for this project.'),
|
2011-02-16 11:53:13 -08:00
|
|
|
),
|
2012-01-31 12:07:19 -08:00
|
|
|
'coverage' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht('Always enable coverage information.'),
|
2012-01-31 12:07:19 -08:00
|
|
|
'conflicts' => array(
|
|
|
|
'no-coverage' => null,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'no-coverage' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht('Always disable coverage information.'),
|
2012-01-31 12:07:19 -08:00
|
|
|
),
|
|
|
|
'detailed-coverage' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht(
|
|
|
|
'Show a detailed coverage report on the CLI. Implies %s.',
|
|
|
|
'--coverage'),
|
2012-01-31 12:07:19 -08:00
|
|
|
),
|
2012-12-17 12:56:41 -08:00
|
|
|
'json' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht('Report results in JSON format.'),
|
2012-12-17 12:56:41 -08:00
|
|
|
),
|
2013-08-01 12:07:11 -07:00
|
|
|
'output' => array(
|
|
|
|
'param' => 'format',
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht(
|
2013-08-01 12:07:11 -07:00
|
|
|
"With 'full', show full pretty report (Default). ".
|
|
|
|
"With 'json', report results in JSON format. ".
|
|
|
|
"With 'ugly', use uglier (but more efficient) JSON formatting. ".
|
2015-05-13 18:05:15 +10:00
|
|
|
"With 'none', don't print results."),
|
2013-08-01 12:07:11 -07:00
|
|
|
'conflicts' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'json' => pht('Only one output format allowed'),
|
|
|
|
'ugly' => pht('Only one output format allowed'),
|
2014-09-27 10:21:23 +10:00
|
|
|
),
|
2013-08-01 12:07:11 -07:00
|
|
|
),
|
2012-12-17 12:56:41 -08:00
|
|
|
'everything' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht('Run every test.'),
|
2012-12-17 12:56:41 -08:00
|
|
|
'conflicts' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'rev' => pht('%s runs all tests.', '--everything'),
|
2012-12-17 12:56:41 -08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
'ugly' => array(
|
2015-05-13 18:05:15 +10:00
|
|
|
'help' => pht(
|
|
|
|
'With %s, use uglier (but more efficient) formatting.',
|
|
|
|
'--json'),
|
2012-12-17 12:56:41 -08:00
|
|
|
),
|
2011-01-09 15:22:25 -08:00
|
|
|
'*' => 'paths',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-08 17:36:20 -07:00
|
|
|
public function getEngine() {
|
|
|
|
return $this->engine;
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
public function run() {
|
|
|
|
|
|
|
|
$working_copy = $this->getWorkingCopy();
|
|
|
|
|
|
|
|
$engine_class = $this->getArgument(
|
|
|
|
'engine',
|
2013-10-18 16:10:06 -07:00
|
|
|
$this->getConfigurationManager()->getConfigFromAnySource('unit.engine'));
|
2011-01-09 15:22:25 -08:00
|
|
|
|
|
|
|
if (!$engine_class) {
|
|
|
|
throw new ArcanistNoEngineException(
|
2015-05-13 18:05:15 +10:00
|
|
|
pht(
|
|
|
|
'No unit test engine is configured for this project. Edit %s '.
|
|
|
|
'to specify a unit test engine.',
|
|
|
|
'.arcconfig'));
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
|
Unify arguments for 'arc lint', 'arc unit'
Summary: See T645. These commands take inconsistent and overly-magical arguments
right now. Instead, make them behave consistently and allow them both to operate
on "arc <workflow> path path2 path3 ...", which is a generally useful workflow.
Test Plan: Ran "arc lint <path>", "arc unit <path>", "arc lint --rev
HEAD^^^^^^", "arc unit --rev HEAD^^^^^^^^^^^^", etc. Ran "arc diff --trace" and
verified --rev argument to child workflows.
Reviewers: btrahan, jungejason
Reviewed By: btrahan
CC: aran, epriestley, btrahan
Maniphest Tasks: T645
Differential Revision: https://secure.phabricator.com/D1348
2012-01-09 12:40:50 -08:00
|
|
|
$paths = $this->getArgument('paths');
|
|
|
|
$rev = $this->getArgument('rev');
|
2012-12-17 12:56:41 -08:00
|
|
|
$everything = $this->getArgument('everything');
|
|
|
|
if ($everything && $paths) {
|
|
|
|
throw new ArcanistUsageException(
|
2015-05-13 18:05:15 +10:00
|
|
|
pht(
|
|
|
|
'You can not specify paths with %s. The %s flag runs every test.',
|
|
|
|
'--everything',
|
|
|
|
'--everything'));
|
2012-12-17 12:56:41 -08:00
|
|
|
}
|
2011-02-18 17:08:10 -08:00
|
|
|
|
2015-01-23 07:21:53 +11:00
|
|
|
if ($everything) {
|
|
|
|
$paths = iterator_to_array($this->getRepositoryApi()->getAllFiles());
|
|
|
|
} else {
|
|
|
|
$paths = $this->selectPathsForWorkflow($paths, $rev);
|
|
|
|
}
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2012-05-30 15:47:16 -07:00
|
|
|
if (!class_exists($engine_class) ||
|
2014-07-22 07:49:15 +10:00
|
|
|
!is_subclass_of($engine_class, 'ArcanistUnitTestEngine')) {
|
2011-12-21 08:51:34 -08:00
|
|
|
throw new ArcanistUsageException(
|
2015-05-13 18:05:15 +10:00
|
|
|
pht(
|
|
|
|
"Configured unit test engine '%s' is not a subclass of '%s'.",
|
|
|
|
$engine_class,
|
|
|
|
'ArcanistUnitTestEngine'));
|
2011-12-21 08:51:34 -08:00
|
|
|
}
|
|
|
|
|
2011-05-27 16:15:43 -07:00
|
|
|
$this->engine = newv($engine_class, array());
|
|
|
|
$this->engine->setWorkingCopy($working_copy);
|
2013-10-22 13:58:32 -07:00
|
|
|
$this->engine->setConfigurationManager($this->getConfigurationManager());
|
2012-12-17 12:56:41 -08:00
|
|
|
if ($everything) {
|
|
|
|
$this->engine->setRunAllTests(true);
|
|
|
|
} else {
|
|
|
|
$this->engine->setPaths($paths);
|
|
|
|
}
|
2011-05-27 16:15:43 -07:00
|
|
|
$this->engine->setArguments($this->getPassthruArgumentsAsMap('unit'));
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2013-02-27 13:59:12 -08:00
|
|
|
$renderer = new ArcanistUnitConsoleRenderer();
|
|
|
|
$this->engine->setRenderer($renderer);
|
|
|
|
|
2012-01-31 12:07:19 -08:00
|
|
|
$enable_coverage = null; // Means "default".
|
|
|
|
if ($this->getArgument('coverage') ||
|
|
|
|
$this->getArgument('detailed-coverage')) {
|
|
|
|
$enable_coverage = true;
|
|
|
|
} else if ($this->getArgument('no-coverage')) {
|
|
|
|
$enable_coverage = false;
|
|
|
|
}
|
|
|
|
$this->engine->setEnableCoverage($enable_coverage);
|
|
|
|
|
2011-06-10 12:40:01 -07:00
|
|
|
// Enable possible async tests only for 'arc diff' not 'arc unit'
|
|
|
|
if ($this->getParentWorkflow()) {
|
|
|
|
$this->engine->setEnableAsyncTests(true);
|
|
|
|
} else {
|
|
|
|
$this->engine->setEnableAsyncTests(false);
|
|
|
|
}
|
|
|
|
|
2011-05-27 16:15:43 -07:00
|
|
|
$results = $this->engine->run();
|
2015-07-01 04:48:52 -07:00
|
|
|
|
|
|
|
$this->validateUnitEngineResults($this->engine, $results);
|
|
|
|
|
2012-01-31 12:07:19 -08:00
|
|
|
$this->testResults = $results;
|
2011-01-09 15:22:25 -08:00
|
|
|
|
2012-08-04 19:23:53 -07:00
|
|
|
$console = PhutilConsole::getConsole();
|
|
|
|
|
2013-08-01 12:07:11 -07:00
|
|
|
$output_format = $this->getOutputFormat();
|
2012-12-17 12:56:41 -08:00
|
|
|
|
2013-08-01 12:07:11 -07:00
|
|
|
if ($output_format !== 'full') {
|
2012-12-17 12:56:41 -08:00
|
|
|
$console->disableOut();
|
|
|
|
}
|
|
|
|
|
2011-01-11 22:13:31 -08:00
|
|
|
$unresolved = array();
|
2012-01-31 12:07:19 -08:00
|
|
|
$coverage = array();
|
2011-04-28 11:46:20 -07:00
|
|
|
$postponed_count = 0;
|
2011-01-09 15:22:25 -08:00
|
|
|
foreach ($results as $result) {
|
|
|
|
$result_code = $result->getResult();
|
2011-04-28 11:46:20 -07:00
|
|
|
if ($result_code == ArcanistUnitTestResult::RESULT_POSTPONED) {
|
|
|
|
$postponed_count++;
|
2011-06-08 16:36:17 -07:00
|
|
|
$unresolved[] = $result;
|
2011-04-28 11:46:20 -07:00
|
|
|
} else {
|
2011-06-06 16:43:36 -07:00
|
|
|
if ($this->engine->shouldEchoTestResults()) {
|
2013-02-27 13:59:12 -08:00
|
|
|
$console->writeOut('%s', $renderer->renderUnitResult($result));
|
2011-06-06 16:43:36 -07:00
|
|
|
}
|
2011-04-28 11:46:20 -07:00
|
|
|
if ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
|
|
|
|
$unresolved[] = $result;
|
|
|
|
}
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
2012-01-31 12:07:19 -08:00
|
|
|
if ($result->getCoverage()) {
|
|
|
|
foreach ($result->getCoverage() as $file => $report) {
|
|
|
|
$coverage[$file][] = $report;
|
|
|
|
}
|
|
|
|
}
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
2011-04-28 11:46:20 -07:00
|
|
|
if ($postponed_count) {
|
2012-08-04 19:23:53 -07:00
|
|
|
$console->writeOut(
|
2013-02-27 13:59:12 -08:00
|
|
|
'%s',
|
|
|
|
$renderer->renderPostponedResult($postponed_count));
|
2011-04-28 11:46:20 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 12:07:19 -08:00
|
|
|
if ($coverage) {
|
2012-02-01 17:36:25 -08:00
|
|
|
$file_coverage = array_fill_keys(
|
|
|
|
$paths,
|
|
|
|
0);
|
2012-01-31 12:07:19 -08:00
|
|
|
$file_reports = array();
|
|
|
|
foreach ($coverage as $file => $reports) {
|
|
|
|
$report = ArcanistUnitTestResult::mergeCoverage($reports);
|
|
|
|
$cov = substr_count($report, 'C');
|
|
|
|
$uncov = substr_count($report, 'U');
|
|
|
|
if ($cov + $uncov) {
|
|
|
|
$coverage = $cov / ($cov + $uncov);
|
|
|
|
} else {
|
|
|
|
$coverage = 0;
|
|
|
|
}
|
|
|
|
$file_coverage[$file] = $coverage;
|
|
|
|
$file_reports[$file] = $report;
|
|
|
|
}
|
2015-05-13 18:05:15 +10:00
|
|
|
$console->writeOut("\n__%s__\n", pht('COVERAGE REPORT'));
|
2012-01-31 12:07:19 -08:00
|
|
|
|
|
|
|
asort($file_coverage);
|
|
|
|
foreach ($file_coverage as $file => $coverage) {
|
2012-08-04 19:23:53 -07:00
|
|
|
$console->writeOut(
|
2012-01-31 12:07:19 -08:00
|
|
|
" **%s%%** %s\n",
|
|
|
|
sprintf('% 3d', (int)(100 * $coverage)),
|
|
|
|
$file);
|
|
|
|
|
2012-02-01 17:36:25 -08:00
|
|
|
$full_path = $working_copy->getProjectRoot().'/'.$file;
|
|
|
|
if ($this->getArgument('detailed-coverage') &&
|
|
|
|
Filesystem::pathExists($full_path) &&
|
2013-09-20 09:18:02 -07:00
|
|
|
is_file($full_path) &&
|
|
|
|
array_key_exists($file, $file_reports)) {
|
2012-08-04 19:23:53 -07:00
|
|
|
$console->writeOut(
|
|
|
|
'%s',
|
|
|
|
$this->renderDetailedCoverageReport(
|
|
|
|
Filesystem::readFile($full_path),
|
|
|
|
$file_reports[$file]));
|
2012-01-31 12:07:19 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-11 22:13:31 -08:00
|
|
|
$this->unresolvedTests = $unresolved;
|
2011-01-09 15:22:25 -08:00
|
|
|
|
|
|
|
$overall_result = self::RESULT_OKAY;
|
|
|
|
foreach ($results as $result) {
|
|
|
|
$result_code = $result->getResult();
|
|
|
|
if ($result_code == ArcanistUnitTestResult::RESULT_FAIL ||
|
|
|
|
$result_code == ArcanistUnitTestResult::RESULT_BROKEN) {
|
|
|
|
$overall_result = self::RESULT_FAIL;
|
|
|
|
break;
|
2011-01-11 22:13:31 -08:00
|
|
|
} else if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
|
2011-01-09 15:22:25 -08:00
|
|
|
$overall_result = self::RESULT_UNSOUND;
|
2011-06-08 16:36:17 -07:00
|
|
|
} else if ($result_code == ArcanistUnitTestResult::RESULT_POSTPONED &&
|
|
|
|
$overall_result != self::RESULT_UNSOUND) {
|
|
|
|
$overall_result = self::RESULT_POSTPONED;
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-01 12:07:11 -07:00
|
|
|
if ($output_format !== 'full') {
|
2012-12-17 12:56:41 -08:00
|
|
|
$console->enableOut();
|
2013-08-01 12:07:11 -07:00
|
|
|
}
|
|
|
|
$data = array_values(mpull($results, 'toDictionary'));
|
|
|
|
switch ($output_format) {
|
|
|
|
case 'ugly':
|
2012-12-17 12:56:41 -08:00
|
|
|
$console->writeOut('%s', json_encode($data));
|
2013-08-01 12:07:11 -07:00
|
|
|
break;
|
|
|
|
case 'json':
|
2012-12-17 12:56:41 -08:00
|
|
|
$json = new PhutilJSON();
|
|
|
|
$console->writeOut('%s', $json->encodeFormatted($data));
|
2013-08-01 12:07:11 -07:00
|
|
|
break;
|
|
|
|
case 'full':
|
|
|
|
// already printed
|
|
|
|
break;
|
|
|
|
case 'none':
|
|
|
|
// do nothing
|
|
|
|
break;
|
2012-12-17 12:56:41 -08:00
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
return $overall_result;
|
|
|
|
}
|
2011-01-11 22:13:31 -08:00
|
|
|
|
|
|
|
public function getUnresolvedTests() {
|
|
|
|
return $this->unresolvedTests;
|
|
|
|
}
|
|
|
|
|
2012-01-31 12:07:19 -08:00
|
|
|
public function getTestResults() {
|
|
|
|
return $this->testResults;
|
|
|
|
}
|
|
|
|
|
2012-02-01 17:36:25 -08:00
|
|
|
private function renderDetailedCoverageReport($data, $report) {
|
2012-01-31 12:07:19 -08:00
|
|
|
$data = explode("\n", $data);
|
|
|
|
|
|
|
|
$out = '';
|
|
|
|
|
|
|
|
$n = 0;
|
|
|
|
foreach ($data as $line) {
|
|
|
|
$out .= sprintf('% 5d ', $n + 1);
|
|
|
|
$line = str_pad($line, 80, ' ');
|
|
|
|
if (empty($report[$n])) {
|
|
|
|
$c = 'N';
|
|
|
|
} else {
|
|
|
|
$c = $report[$n];
|
|
|
|
}
|
|
|
|
switch ($c) {
|
|
|
|
case 'C':
|
|
|
|
$out .= phutil_console_format(
|
|
|
|
'<bg:green> %s </bg>',
|
|
|
|
$line);
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
$out .= phutil_console_format(
|
|
|
|
'<bg:red> %s </bg>',
|
|
|
|
$line);
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
$out .= phutil_console_format(
|
|
|
|
'<bg:magenta> %s </bg>',
|
|
|
|
$line);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$out .= ' '.$line.' ';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$out .= "\n";
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
2013-08-01 12:07:11 -07:00
|
|
|
|
|
|
|
private function getOutputFormat() {
|
|
|
|
if ($this->getArgument('ugly')) {
|
|
|
|
return 'ugly';
|
|
|
|
}
|
|
|
|
if ($this->getArgument('json')) {
|
|
|
|
return 'json';
|
|
|
|
}
|
|
|
|
$format = $this->getArgument('output');
|
|
|
|
$known_formats = array(
|
|
|
|
'none' => 'none',
|
|
|
|
'json' => 'json',
|
|
|
|
'ugly' => 'ugly',
|
|
|
|
'full' => 'full',
|
|
|
|
);
|
|
|
|
return idx($known_formats, $format, 'full');
|
|
|
|
}
|
2014-07-09 09:12:13 +10:00
|
|
|
|
2015-07-01 04:48:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Raise a tailored error when a unit test engine returns results in an
|
|
|
|
* invalid format.
|
|
|
|
*
|
|
|
|
* @param ArcanistUnitTestEngine The engine.
|
|
|
|
* @param wild Results from the engine.
|
|
|
|
*/
|
|
|
|
private function validateUnitEngineResults(
|
|
|
|
ArcanistUnitTestEngine $engine,
|
|
|
|
$results) {
|
|
|
|
|
|
|
|
if (!is_array($results)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Unit test engine (of class "%s") returned invalid results when '.
|
|
|
|
'run (with method "%s"). Expected a list of "%s" objects as results.',
|
|
|
|
get_class($engine),
|
|
|
|
'run()',
|
|
|
|
'ArcanistUnitTestResult'));
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($results as $key => $result) {
|
|
|
|
if (!($result instanceof ArcanistUnitTestResult)) {
|
|
|
|
throw new Exception(
|
|
|
|
pht(
|
|
|
|
'Unit test engine (of class "%s") returned invalid results when '.
|
|
|
|
'run (with method "%s"). Expected a list of "%s" objects as '.
|
|
|
|
'results, but value with key "%s" is not valid.',
|
|
|
|
get_class($engine),
|
|
|
|
'run()',
|
|
|
|
'ArcanistUnitTestResult',
|
|
|
|
$key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-09 15:22:25 -08:00
|
|
|
}
|