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

Ship unresolved unit test information to Differential.

Summary:

Test Plan:

Reviewers:

CC:
This commit is contained in:
epriestley 2011-01-11 22:13:31 -08:00
parent bb7e649fa5
commit 7d36705215
5 changed files with 92 additions and 11 deletions

View file

@ -63,6 +63,7 @@ phutil_register_library_map(array(
'PhutilLintEngine' => 'lint/engine/phutil', 'PhutilLintEngine' => 'lint/engine/phutil',
'PhutilModuleRequirements' => 'staticanalysis/parsers/phutilmodule', 'PhutilModuleRequirements' => 'staticanalysis/parsers/phutilmodule',
'PhutilUnitTestEngine' => 'unit/engine/phutil', 'PhutilUnitTestEngine' => 'unit/engine/phutil',
'PhutilUnitTestEngineTestCase' => 'unit/engine/phutil/__tests__',
'UnitTestableArcanistLintEngine' => 'lint/engine/test', 'UnitTestableArcanistLintEngine' => 'lint/engine/test',
), ),
'function' => 'function' =>
@ -98,6 +99,7 @@ phutil_register_library_map(array(
'ArcanistXHPASTLinterTestCase' => 'ArcanistPhutilTestCase', 'ArcanistXHPASTLinterTestCase' => 'ArcanistPhutilTestCase',
'PhutilLintEngine' => 'ArcanistLintEngine', 'PhutilLintEngine' => 'ArcanistLintEngine',
'PhutilUnitTestEngine' => 'ArcanistBaseUnitTestEngine', 'PhutilUnitTestEngine' => 'ArcanistBaseUnitTestEngine',
'PhutilUnitTestEngineTestCase' => 'ArcanistPhutilTestCase',
'UnitTestableArcanistLintEngine' => 'ArcanistLintEngine', 'UnitTestableArcanistLintEngine' => 'ArcanistLintEngine',
), ),
'requires_interface' => 'requires_interface' =>

View file

@ -0,0 +1,29 @@
<?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.
*/
class PhutilUnitTestEngineTestCase extends ArcanistPhutilTestCase {
public function testPass() {
$this->assertEqual(1, 1, 'This test is expected to pass.');
}
public function testFail() {
$this->assertEqual(1, 2, 'This test is expected to fail.');
}
}

View file

@ -0,0 +1,12 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('arcanist', 'unit/engine/phutil/testcase');
phutil_require_source('PhutilUnitTestEngineTestCase.php');

View file

@ -212,8 +212,10 @@ EOTEXT
if ($lint_result === ArcanistLintWorkflow::RESULT_OKAY) { if ($lint_result === ArcanistLintWorkflow::RESULT_OKAY) {
$lint = 'okay'; $lint = 'okay';
} else if ($lint_result === ArcanistLintWorkflow::RESULT_WARNINGS) { } else if ($lint_result === ArcanistLintWorkflow::RESULT_ERRORS) {
$lint = 'fail'; $lint = 'fail';
} else if ($lint_result === ArcanistLintWorkflow::RESULT_WARNINGS) {
$lint = 'warn';
} else if ($lint_result === ArcanistLintWorkflow::RESULT_SKIP) { } else if ($lint_result === ArcanistLintWorkflow::RESULT_SKIP) {
$lint = 'skip'; $lint = 'skip';
} else { } else {
@ -222,9 +224,10 @@ EOTEXT
if ($unit_result === ArcanistUnitWorkflow::RESULT_OKAY) { if ($unit_result === ArcanistUnitWorkflow::RESULT_OKAY) {
$unit = 'okay'; $unit = 'okay';
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_UNSOUND || } else if ($unit_result === ArcanistUnitWorkflow::RESULT_FAIL) {
$unit_result === ArcanistUnitWorkflow::RESULT_FAIL) {
$unit = 'fail'; $unit = 'fail';
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_UNSOUND) {
$unit = 'warn';
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_SKIP) { } else if ($unit_result === ArcanistUnitWorkflow::RESULT_SKIP) {
$unit = 'skip'; $unit = 'skip';
} else { } else {
@ -271,6 +274,24 @@ EOTEXT
)); ));
} }
if ($this->unresolvedTests) {
$data = array();
foreach ($this->unresolvedTests as $test) {
$data[] = array(
'name' => $test->getName(),
'result' => $test->getResult(),
'userdata' => $test->getUserData(),
);
}
$conduit->callMethodSynchronous(
'differential.setdiffproperty',
array(
'diff_id' => $diff_info['diffid'],
'name' => 'arc:unit',
'data' => json_encode($data),
));
}
if ($this->shouldOnlyCreateDiff()) { if ($this->shouldOnlyCreateDiff()) {
echo phutil_console_format( echo phutil_console_format(
"Created a new Differential diff:\n". "Created a new Differential diff:\n".
@ -840,16 +861,20 @@ EOTEXT
if (!$continue) { if (!$continue) {
throw new ArcanistUserAbortException(); throw new ArcanistUserAbortException();
} }
$this->unresolvedLint = $lint_workflow->getUnresolvedMessages();
break; break;
case ArcanistLintWorkflow::RESULT_ERRORS: case ArcanistLintWorkflow::RESULT_ERRORS:
echo phutil_console_format( echo phutil_console_format(
"<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n"); "<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n");
throw new ArcanistUsageException( $continue = phutil_console_confirm(
"Resolve lint errors or run with --nolint."); "Lint issued unresolved errors! Ignore lint errors?");
if (!$continue) {
throw new ArcanistUserAbortException();
}
break; break;
} }
$this->unresolvedLint = $lint_workflow->getUnresolvedMessages();
return $lint_result; return $lint_result;
} catch (ArcanistNoEngineException $ex) { } catch (ArcanistNoEngineException $ex) {
echo "No lint engine configured for this project.\n"; echo "No lint engine configured for this project.\n";
@ -892,11 +917,16 @@ EOTEXT
case ArcanistUnitWorkflow::RESULT_FAIL: case ArcanistUnitWorkflow::RESULT_FAIL:
echo phutil_console_format( echo phutil_console_format(
"<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n"); "<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n");
throw new ArcanistUsageException( $continue = phutil_console_confirm(
"Resolve unit test errors or run with --nounit."); "Unit test results include failures! Ignore test failures?");
if (!$continue) {
throw new ArcanistUserAbortException();
}
break; break;
} }
$this->unresolvedTests = $unit_workflow->getUnresolvedTests();
return $unit_result; return $unit_result;
} catch (ArcanistNoEngineException $ex) { } catch (ArcanistNoEngineException $ex) {
echo "No unit test engine is configured for this project.\n"; echo "No unit test engine is configured for this project.\n";

View file

@ -23,6 +23,8 @@ class ArcanistUnitWorkflow extends ArcanistBaseWorkflow {
const RESULT_FAIL = 2; const RESULT_FAIL = 2;
const RESULT_SKIP = 3; const RESULT_SKIP = 3;
private $unresolvedTests;
public function getCommandHelp() { public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT return phutil_console_format(<<<EOTEXT
**unit** **unit**
@ -96,13 +98,16 @@ EOTEXT
' <bg:yellow>** UNSOUND **</bg>'), ' <bg:yellow>** UNSOUND **</bg>'),
); );
$unresolved = array();
foreach ($results as $result) { foreach ($results as $result) {
$result_code = $result->getResult(); $result_code = $result->getResult();
echo $status_codes[$result_code].' '.$result->getName()."\n"; echo $status_codes[$result_code].' '.$result->getName()."\n";
if ($result_code != ArcanistUnitTestResult::RESULT_PASS) { if ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
echo $result->getUserData()."\n"; echo $result->getUserData()."\n";
$unresolved[] = $result;
} }
} }
$this->unresolvedTests = $unresolved;
$overall_result = self::RESULT_OKAY; $overall_result = self::RESULT_OKAY;
foreach ($results as $result) { foreach ($results as $result) {
@ -111,13 +116,16 @@ EOTEXT
$result_code == ArcanistUnitTestResult::RESULT_BROKEN) { $result_code == ArcanistUnitTestResult::RESULT_BROKEN) {
$overall_result = self::RESULT_FAIL; $overall_result = self::RESULT_FAIL;
break; break;
} } else if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
$overall_result = self::RESULT_UNSOUND; $overall_result = self::RESULT_UNSOUND;
break;
} }
} }
return $overall_result; return $overall_result;
} }
public function getUnresolvedTests() {
return $this->unresolvedTests;
}
} }