1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 08:12:40 +01:00

Make test result parsing stricter about duration formats

Summary: Fixes T8805. Explicitly require int/float for duration. Adjust XUnit/Go parsers to provide one.

Test Plan: Ran unit tests.

Reviewers: btrahan, joshuaspence, chad

Reviewed By: chad

Subscribers: jsotuyod, champo, epriestley

Maniphest Tasks: T8805

Differential Revision: https://secure.phabricator.com/D13637
This commit is contained in:
epriestley 2015-07-15 13:26:15 -07:00
parent 407954dddd
commit 5e578fb847
3 changed files with 25 additions and 7 deletions

View file

@ -57,11 +57,30 @@ final class ArcanistUnitTestResult extends Phobject {
return $this->result;
}
/**
* Set the number of seconds spent executing this test.
*
* Reporting this information can help users identify slow tests and reduce
* the total cost of running a test suite.
*
* Callers should pass an integer or a float. For example, pass `3` for
* 3 seconds, or `0.125` for 125 milliseconds.
*
* @param int|float Duration, in seconds.
* @return this
*/
public function setDuration($duration) {
if (!is_int($duration) && !is_float($duration)) {
throw new Exception(
pht(
'Parameter passed to setDuration() must be an integer or a float.'));
}
$this->duration = $duration;
return $this;
}
public function getDuration() {
return $this->duration;
}

View file

@ -31,7 +31,7 @@ final class ArcanistGoTestResultParser extends ArcanistTestResultParser {
// We have a passing test
$meta = array();
preg_match(
'/^--- PASS: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds)?\).*/',
'/^--- PASS: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds?)?\).*/',
$line,
$meta);
@ -39,8 +39,7 @@ final class ArcanistGoTestResultParser extends ArcanistTestResultParser {
// For now set name without test case, we'll add it later
$result->setName($meta['test_name']);
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
$result->setDuration($meta['time']);
$result->setDuration((float)$meta['time']);
$test_case_results[] = $result;
continue;
@ -51,14 +50,14 @@ final class ArcanistGoTestResultParser extends ArcanistTestResultParser {
$reason = trim($test_results[$i + 1]);
$meta = array();
preg_match(
'/^--- FAIL: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds)?\).*/',
'/^--- FAIL: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds?)?\).*/',
$line,
$meta);
$result = new ArcanistUnitTestResult();
$result->setName($meta['test_name']);
$result->setResult(ArcanistUnitTestResult::RESULT_FAIL);
$result->setDuration($meta['time']);
$result->setDuration((float)$meta['time']);
$result->setUserData($reason."\n");
$test_case_results[] = $result;
@ -85,7 +84,7 @@ final class ArcanistGoTestResultParser extends ArcanistTestResultParser {
$result = new ArcanistUnitTestResult();
$result->setName($test_name);
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
$result->setDuration($meta['time']);
$result->setDuration((float)$meta['time']);
$results[] = $result;
} else {

View file

@ -89,7 +89,7 @@ final class ArcanistXUnitTestResultParser extends Phobject {
$result = new ArcanistUnitTestResult();
$result->setName($classname.'.'.$name);
$result->setResult($status);
$result->setDuration($time);
$result->setDuration((float)$time);
$result->setUserData($user_data);
$results[] = $result;