2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Runs unit tests which cover your changes.
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
2011-01-10 00:22:25 +01:00
|
|
|
class ArcanistUnitWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
|
|
|
const RESULT_OKAY = 0;
|
|
|
|
const RESULT_UNSOUND = 1;
|
|
|
|
const RESULT_FAIL = 2;
|
|
|
|
const RESULT_SKIP = 3;
|
|
|
|
|
2011-01-12 07:13:31 +01:00
|
|
|
private $unresolvedTests;
|
2011-05-28 01:15:43 +02:00
|
|
|
private $engine;
|
2011-01-12 07:13:31 +01:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**unit**
|
|
|
|
Supports: git, svn
|
|
|
|
Run unit tests that cover local changes.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
2011-02-16 20:53:13 +01:00
|
|
|
'engine' => array(
|
|
|
|
'param' => 'classname',
|
|
|
|
'help' =>
|
|
|
|
"Override configured unit engine for this project."
|
|
|
|
),
|
2011-01-10 00:22:25 +01:00
|
|
|
'*' => 'paths',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresWorkingCopy() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
|
|
|
|
$working_copy = $this->getWorkingCopy();
|
|
|
|
|
|
|
|
$engine_class = $this->getArgument(
|
|
|
|
'engine',
|
|
|
|
$working_copy->getConfig('unit_engine'));
|
|
|
|
|
|
|
|
if (!$engine_class) {
|
|
|
|
throw new ArcanistNoEngineException(
|
|
|
|
"No unit test engine is configured for this project. Edit .arcconfig ".
|
|
|
|
"to specify a unit test engine.");
|
|
|
|
}
|
|
|
|
|
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
if ($this->getArgument('paths')) {
|
|
|
|
// TODO: deal with git stuff
|
|
|
|
$paths = $this->getArgument('paths');
|
|
|
|
} else {
|
|
|
|
$paths = $repository_api->getWorkingCopyStatus();
|
2011-02-19 02:08:10 +01:00
|
|
|
|
|
|
|
// TODO: clean this up
|
|
|
|
foreach ($paths as $path => $mask) {
|
|
|
|
if ($mask & ArcanistRepositoryAPI::FLAG_UNTRACKED) {
|
|
|
|
unset($paths[$path]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
$paths = array_keys($paths);
|
|
|
|
}
|
|
|
|
|
2011-02-19 02:08:10 +01:00
|
|
|
|
2011-01-13 00:45:17 +01:00
|
|
|
PhutilSymbolLoader::loadClass($engine_class);
|
2011-05-28 01:15:43 +02:00
|
|
|
$this->engine = newv($engine_class, array());
|
|
|
|
$this->engine->setWorkingCopy($working_copy);
|
|
|
|
$this->engine->setPaths($paths);
|
|
|
|
$this->engine->setArguments($this->getPassthruArgumentsAsMap('unit'));
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2011-05-28 01:15:43 +02:00
|
|
|
$results = $this->engine->run();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
$status_codes = array(
|
|
|
|
ArcanistUnitTestResult::RESULT_PASS => phutil_console_format(
|
2011-06-07 19:48:16 +02:00
|
|
|
'<bg:green>** PASS **</bg>'),
|
2011-01-10 00:22:25 +01:00
|
|
|
ArcanistUnitTestResult::RESULT_FAIL => phutil_console_format(
|
2011-06-07 19:48:16 +02:00
|
|
|
'<bg:red>** FAIL **</bg>'),
|
2011-01-10 00:22:25 +01:00
|
|
|
ArcanistUnitTestResult::RESULT_SKIP => phutil_console_format(
|
2011-06-07 19:48:16 +02:00
|
|
|
'<bg:yellow>** SKIP **</bg>'),
|
2011-01-10 00:22:25 +01:00
|
|
|
ArcanistUnitTestResult::RESULT_BROKEN => phutil_console_format(
|
2011-06-07 19:48:16 +02:00
|
|
|
'<bg:red>** BROKEN **</bg>'),
|
2011-01-10 00:22:25 +01:00
|
|
|
ArcanistUnitTestResult::RESULT_UNSOUND => phutil_console_format(
|
2011-06-07 19:48:16 +02:00
|
|
|
'<bg:yellow>** UNSOUND **</bg>'),
|
2011-03-22 01:29:12 +01:00
|
|
|
ArcanistUnitTestResult::RESULT_POSTPONED => phutil_console_format(
|
2011-06-07 19:48:16 +02:00
|
|
|
'<bg:yellow>** POSTPONED **</bg>'),
|
2011-01-10 00:22:25 +01:00
|
|
|
);
|
|
|
|
|
2011-01-12 07:13:31 +01:00
|
|
|
$unresolved = array();
|
2011-04-28 20:46:20 +02:00
|
|
|
$postponed_count = 0;
|
2011-01-10 00:22:25 +01:00
|
|
|
foreach ($results as $result) {
|
|
|
|
$result_code = $result->getResult();
|
2011-04-28 20:46:20 +02:00
|
|
|
if ($result_code == ArcanistUnitTestResult::RESULT_POSTPONED) {
|
|
|
|
$postponed_count++;
|
|
|
|
} else {
|
2011-06-07 19:48:16 +02:00
|
|
|
echo ' '.$status_codes[$result_code].' '.$result->getName()."\n";
|
2011-04-28 20:46:20 +02:00
|
|
|
if ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
|
|
|
|
echo $result->getUserData()."\n";
|
|
|
|
$unresolved[] = $result;
|
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-28 20:46:20 +02:00
|
|
|
if ($postponed_count) {
|
|
|
|
echo sprintf("%s %d %s\n",
|
|
|
|
$status_codes[ArcanistUnitTestResult::RESULT_POSTPONED],
|
|
|
|
$postponed_count,
|
|
|
|
($postponed_count > 1)?'tests':'test');
|
|
|
|
}
|
|
|
|
|
2011-01-12 07:13:31 +01:00
|
|
|
$this->unresolvedTests = $unresolved;
|
2011-01-10 00:22:25 +01: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-12 07:13:31 +01:00
|
|
|
} else if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
|
2011-01-10 00:22:25 +01:00
|
|
|
$overall_result = self::RESULT_UNSOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $overall_result;
|
|
|
|
}
|
2011-01-12 07:13:31 +01:00
|
|
|
|
|
|
|
public function getUnresolvedTests() {
|
|
|
|
return $this->unresolvedTests;
|
|
|
|
}
|
|
|
|
|
2011-05-28 01:15:43 +02:00
|
|
|
public function setDifferentialDiffID($id) {
|
|
|
|
if ($this->engine) {
|
|
|
|
$this->engine->setDifferentialDiffID($id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|