Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistUnitWorkflow.php
Show First 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | public function run() { | ||||
// Enable possible async tests only for 'arc diff' not 'arc unit' | // Enable possible async tests only for 'arc diff' not 'arc unit' | ||||
if ($this->getParentWorkflow()) { | if ($this->getParentWorkflow()) { | ||||
$this->engine->setEnableAsyncTests(true); | $this->engine->setEnableAsyncTests(true); | ||||
} else { | } else { | ||||
$this->engine->setEnableAsyncTests(false); | $this->engine->setEnableAsyncTests(false); | ||||
} | } | ||||
$results = $this->engine->run(); | $results = $this->engine->run(); | ||||
$this->validateUnitEngineResults($this->engine, $results); | |||||
$this->testResults = $results; | $this->testResults = $results; | ||||
$console = PhutilConsole::getConsole(); | $console = PhutilConsole::getConsole(); | ||||
$output_format = $this->getOutputFormat(); | $output_format = $this->getOutputFormat(); | ||||
if ($output_format !== 'full') { | if ($output_format !== 'full') { | ||||
$console->disableOut(); | $console->disableOut(); | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | $known_formats = array( | ||||
'none' => 'none', | 'none' => 'none', | ||||
'json' => 'json', | 'json' => 'json', | ||||
'ugly' => 'ugly', | 'ugly' => 'ugly', | ||||
'full' => 'full', | 'full' => 'full', | ||||
); | ); | ||||
return idx($known_formats, $format, 'full'); | return idx($known_formats, $format, 'full'); | ||||
} | } | ||||
/** | |||||
* 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)); | |||||
} | |||||
} | |||||
} | |||||
} | } |