2014-02-27 20:06:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialUnitField
|
2015-06-23 22:33:09 +02:00
|
|
|
extends DifferentialHarbormasterField {
|
2014-02-27 20:06:37 +01:00
|
|
|
|
|
|
|
public function getFieldKey() {
|
|
|
|
return 'differential:unit';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldName() {
|
|
|
|
return pht('Unit');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFieldDescription() {
|
|
|
|
return pht('Shows unit test results.');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAppearInPropertyView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-06-16 17:53:40 +02:00
|
|
|
public function renderPropertyViewValue(array $handles) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function shouldAppearInDiffPropertyView() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderDiffPropertyViewLabel(DifferentialDiff $diff) {
|
2014-02-27 20:06:37 +01:00
|
|
|
return $this->getFieldName();
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:33:09 +02:00
|
|
|
protected function getLegacyProperty() {
|
|
|
|
return 'arc:unit';
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getDiffPropertyKeys() {
|
|
|
|
return array(
|
2014-02-27 20:06:37 +01:00
|
|
|
'arc:unit',
|
|
|
|
'arc:unit-excuse',
|
|
|
|
);
|
2015-06-23 22:33:09 +02:00
|
|
|
}
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-23 22:33:09 +02:00
|
|
|
protected function loadHarbormasterTargetMessages(array $target_phids) {
|
|
|
|
return id(new HarbormasterBuildUnitMessage())->loadAllWhere(
|
2015-06-23 22:34:25 +02:00
|
|
|
'buildTargetPHID IN (%Ls)',
|
2015-06-23 22:33:09 +02:00
|
|
|
$target_phids);
|
|
|
|
}
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-23 22:33:09 +02:00
|
|
|
protected function newModernMessage(array $message) {
|
|
|
|
return HarbormasterBuildUnitMessage::newFromDictionary(
|
|
|
|
new HarbormasterBuildTarget(),
|
|
|
|
$this->getModernUnitMessageDictionary($message));
|
|
|
|
}
|
2014-02-27 20:06:37 +01:00
|
|
|
|
2015-06-23 22:33:09 +02:00
|
|
|
protected function newHarbormasterMessageView(array $messages) {
|
2015-06-23 22:34:25 +02:00
|
|
|
foreach ($messages as $key => $message) {
|
|
|
|
if ($message->getResult() == ArcanistUnitTestResult::RESULT_PASS) {
|
|
|
|
unset($messages[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$messages) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:33:09 +02:00
|
|
|
return id(new HarbormasterUnitPropertyView())
|
2015-06-23 22:34:25 +02:00
|
|
|
->setLimit(10)
|
2015-06-23 22:33:09 +02:00
|
|
|
->setUnitMessages($messages);
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|
|
|
|
|
2014-03-09 21:18:17 +01:00
|
|
|
public function getWarningsForDetailView() {
|
|
|
|
$status = $this->getObject()->getActiveDiff()->getUnitStatus();
|
|
|
|
|
|
|
|
$warnings = array();
|
|
|
|
if ($status < DifferentialUnitStatus::UNIT_WARN) {
|
|
|
|
// Don't show any warnings.
|
2014-09-16 21:11:54 +02:00
|
|
|
} else if ($status == DifferentialUnitStatus::UNIT_AUTO_SKIP) {
|
|
|
|
// Don't show any warnings.
|
2014-03-09 21:18:17 +01:00
|
|
|
} else if ($status == DifferentialUnitStatus::UNIT_POSTPONED) {
|
|
|
|
$warnings[] = pht(
|
|
|
|
'Background tests have not finished executing on these changes.');
|
|
|
|
} else if ($status == DifferentialUnitStatus::UNIT_SKIP) {
|
|
|
|
$warnings[] = pht(
|
|
|
|
'Unit tests were skipped when generating these changes.');
|
|
|
|
} else {
|
|
|
|
$warnings[] = pht('These changes have unit test problems.');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $warnings;
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:33:09 +02:00
|
|
|
protected function renderHarbormasterStatus(
|
|
|
|
DifferentialDiff $diff,
|
|
|
|
array $messages) {
|
2014-03-09 21:18:17 +01:00
|
|
|
|
2015-06-21 19:37:55 +02:00
|
|
|
$colors = array(
|
|
|
|
DifferentialUnitStatus::UNIT_NONE => 'grey',
|
|
|
|
DifferentialUnitStatus::UNIT_OKAY => 'green',
|
|
|
|
DifferentialUnitStatus::UNIT_WARN => 'yellow',
|
|
|
|
DifferentialUnitStatus::UNIT_FAIL => 'red',
|
|
|
|
DifferentialUnitStatus::UNIT_SKIP => 'blue',
|
|
|
|
DifferentialUnitStatus::UNIT_AUTO_SKIP => 'blue',
|
|
|
|
DifferentialUnitStatus::UNIT_POSTPONED => 'blue',
|
|
|
|
);
|
|
|
|
$icon_color = idx($colors, $diff->getUnitStatus(), 'grey');
|
|
|
|
|
|
|
|
$message = DifferentialRevisionUpdateHistoryView::getDiffUnitMessage($diff);
|
|
|
|
|
2015-06-23 22:34:25 +02:00
|
|
|
$note = array();
|
|
|
|
|
|
|
|
$groups = mgroup($messages, 'getResult');
|
|
|
|
|
|
|
|
$groups = array_select_keys(
|
|
|
|
$groups,
|
|
|
|
array(
|
|
|
|
ArcanistUnitTestResult::RESULT_FAIL,
|
|
|
|
ArcanistUnitTestResult::RESULT_BROKEN,
|
|
|
|
ArcanistUnitTestResult::RESULT_UNSOUND,
|
|
|
|
ArcanistUnitTestResult::RESULT_SKIP,
|
|
|
|
ArcanistUnitTestResult::RESULT_PASS,
|
|
|
|
)) + $groups;
|
|
|
|
|
|
|
|
foreach ($groups as $result => $group) {
|
|
|
|
$count = new PhutilNumber(count($group));
|
|
|
|
switch ($result) {
|
|
|
|
case ArcanistUnitTestResult::RESULT_PASS:
|
|
|
|
$note[] = pht('%s Passed Test(s)', $count);
|
|
|
|
break;
|
|
|
|
case ArcanistUnitTestResult::RESULT_FAIL:
|
|
|
|
$note[] = pht('%s Failed Test(s)', $count);
|
|
|
|
break;
|
|
|
|
case ArcanistUnitTestResult::RESULT_SKIP:
|
|
|
|
$note[] = pht('%s Skipped Test(s)', $count);
|
|
|
|
break;
|
|
|
|
case ArcanistUnitTestResult::RESULT_BROKEN:
|
|
|
|
$note[] = pht('%s Broken Test(s)', $count);
|
|
|
|
break;
|
|
|
|
case ArcanistUnitTestResult::RESULT_UNSOUND:
|
|
|
|
$note[] = pht('%s Unsound Test(s)', $count);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$note[] = pht('%s Other Test(s)', $count);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$buildable = $diff->getBuildable();
|
|
|
|
if ($buildable) {
|
|
|
|
$full_results = '/harbormaster/unit/'.$buildable->getID().'/';
|
|
|
|
$note[] = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $full_results,
|
|
|
|
),
|
|
|
|
pht('View Full Results'));
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:37:55 +02:00
|
|
|
$excuse = $diff->getProperty('arc:unit-excuse');
|
|
|
|
if (strlen($excuse)) {
|
|
|
|
$excuse = array(
|
|
|
|
phutil_tag('strong', array(), pht('Excuse:')),
|
|
|
|
' ',
|
|
|
|
phutil_escape_html_newlines($excuse),
|
|
|
|
);
|
2015-06-23 22:34:25 +02:00
|
|
|
$note[] = $excuse;
|
2015-06-21 19:37:55 +02:00
|
|
|
}
|
|
|
|
|
2015-06-23 22:34:25 +02:00
|
|
|
$note = phutil_implode_html(" \xC2\xB7 ", $note);
|
|
|
|
|
2015-06-21 19:37:55 +02:00
|
|
|
$status = id(new PHUIStatusListView())
|
|
|
|
->addItem(
|
|
|
|
id(new PHUIStatusItemView())
|
|
|
|
->setIcon(PHUIStatusItemView::ICON_STAR, $icon_color)
|
|
|
|
->setTarget($message)
|
2015-06-23 22:34:25 +02:00
|
|
|
->setNote($note));
|
2015-06-21 19:37:55 +02:00
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getModernUnitMessageDictionary(array $map) {
|
|
|
|
// Strip out `null` values to satisfy stricter typechecks.
|
|
|
|
foreach ($map as $key => $value) {
|
|
|
|
if ($value === null) {
|
|
|
|
unset($map[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Remap more stuff here?
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-27 20:06:37 +01:00
|
|
|
}
|