Page MenuHomePhabricator

D13637.id32959.diff
No OneTemporary

D13637.id32959.diff

diff --git a/src/unit/ArcanistUnitTestResult.php b/src/unit/ArcanistUnitTestResult.php
--- a/src/unit/ArcanistUnitTestResult.php
+++ b/src/unit/ArcanistUnitTestResult.php
@@ -57,11 +57,30 @@
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;
}
diff --git a/src/unit/parser/ArcanistGoTestResultParser.php b/src/unit/parser/ArcanistGoTestResultParser.php
--- a/src/unit/parser/ArcanistGoTestResultParser.php
+++ b/src/unit/parser/ArcanistGoTestResultParser.php
@@ -31,7 +31,7 @@
// 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 @@
// 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 @@
$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 @@
$result = new ArcanistUnitTestResult();
$result->setName($test_name);
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
- $result->setDuration($meta['time']);
+ $result->setDuration((float)$meta['time']);
$results[] = $result;
} else {
diff --git a/src/unit/parser/ArcanistXUnitTestResultParser.php b/src/unit/parser/ArcanistXUnitTestResultParser.php
--- a/src/unit/parser/ArcanistXUnitTestResultParser.php
+++ b/src/unit/parser/ArcanistXUnitTestResultParser.php
@@ -89,7 +89,7 @@
$result = new ArcanistUnitTestResult();
$result->setName($classname.'.'.$name);
$result->setResult($status);
- $result->setDuration($time);
+ $result->setDuration((float)$time);
$result->setUserData($user_data);
$results[] = $result;

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 3, 11:17 AM (19 h, 32 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7086821
Default Alt Text
D13637.id32959.diff (3 KB)

Event Timeline