1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-21 22:32: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',
'PhutilModuleRequirements' => 'staticanalysis/parsers/phutilmodule',
'PhutilUnitTestEngine' => 'unit/engine/phutil',
'PhutilUnitTestEngineTestCase' => 'unit/engine/phutil/__tests__',
'UnitTestableArcanistLintEngine' => 'lint/engine/test',
),
'function' =>
@ -98,6 +99,7 @@ phutil_register_library_map(array(
'ArcanistXHPASTLinterTestCase' => 'ArcanistPhutilTestCase',
'PhutilLintEngine' => 'ArcanistLintEngine',
'PhutilUnitTestEngine' => 'ArcanistBaseUnitTestEngine',
'PhutilUnitTestEngineTestCase' => 'ArcanistPhutilTestCase',
'UnitTestableArcanistLintEngine' => 'ArcanistLintEngine',
),
'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) {
$lint = 'okay';
} else if ($lint_result === ArcanistLintWorkflow::RESULT_WARNINGS) {
} else if ($lint_result === ArcanistLintWorkflow::RESULT_ERRORS) {
$lint = 'fail';
} else if ($lint_result === ArcanistLintWorkflow::RESULT_WARNINGS) {
$lint = 'warn';
} else if ($lint_result === ArcanistLintWorkflow::RESULT_SKIP) {
$lint = 'skip';
} else {
@ -222,9 +224,10 @@ EOTEXT
if ($unit_result === ArcanistUnitWorkflow::RESULT_OKAY) {
$unit = 'okay';
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_UNSOUND ||
$unit_result === ArcanistUnitWorkflow::RESULT_FAIL) {
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_FAIL) {
$unit = 'fail';
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_UNSOUND) {
$unit = 'warn';
} else if ($unit_result === ArcanistUnitWorkflow::RESULT_SKIP) {
$unit = 'skip';
} 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()) {
echo phutil_console_format(
"Created a new Differential diff:\n".
@ -840,16 +861,20 @@ EOTEXT
if (!$continue) {
throw new ArcanistUserAbortException();
}
$this->unresolvedLint = $lint_workflow->getUnresolvedMessages();
break;
case ArcanistLintWorkflow::RESULT_ERRORS:
echo phutil_console_format(
"<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n");
throw new ArcanistUsageException(
"Resolve lint errors or run with --nolint.");
$continue = phutil_console_confirm(
"Lint issued unresolved errors! Ignore lint errors?");
if (!$continue) {
throw new ArcanistUserAbortException();
}
break;
}
$this->unresolvedLint = $lint_workflow->getUnresolvedMessages();
return $lint_result;
} catch (ArcanistNoEngineException $ex) {
echo "No lint engine configured for this project.\n";
@ -892,11 +917,16 @@ EOTEXT
case ArcanistUnitWorkflow::RESULT_FAIL:
echo phutil_console_format(
"<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n");
throw new ArcanistUsageException(
"Resolve unit test errors or run with --nounit.");
$continue = phutil_console_confirm(
"Unit test results include failures! Ignore test failures?");
if (!$continue) {
throw new ArcanistUserAbortException();
}
break;
}
$this->unresolvedTests = $unit_workflow->getUnresolvedTests();
return $unit_result;
} catch (ArcanistNoEngineException $ex) {
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_SKIP = 3;
private $unresolvedTests;
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
**unit**
@ -96,13 +98,16 @@ EOTEXT
' <bg:yellow>** UNSOUND **</bg>'),
);
$unresolved = array();
foreach ($results as $result) {
$result_code = $result->getResult();
echo $status_codes[$result_code].' '.$result->getName()."\n";
if ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
echo $result->getUserData()."\n";
$unresolved[] = $result;
}
}
$this->unresolvedTests = $unresolved;
$overall_result = self::RESULT_OKAY;
foreach ($results as $result) {
@ -111,13 +116,16 @@ EOTEXT
$result_code == ArcanistUnitTestResult::RESULT_BROKEN) {
$overall_result = self::RESULT_FAIL;
break;
}
if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
} else if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
$overall_result = self::RESULT_UNSOUND;
break;
}
}
return $overall_result;
}
public function getUnresolvedTests() {
return $this->unresolvedTests;
}
}