From 5e578fb847b3810270a4bc480f5e6a15b5078a8c Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 15 Jul 2015 13:26:15 -0700 Subject: [PATCH] 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 --- src/unit/ArcanistUnitTestResult.php | 19 +++++++++++++++++++ .../parser/ArcanistGoTestResultParser.php | 11 +++++------ .../parser/ArcanistXUnitTestResultParser.php | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/unit/ArcanistUnitTestResult.php b/src/unit/ArcanistUnitTestResult.php index 74805581..f570c072 100644 --- a/src/unit/ArcanistUnitTestResult.php +++ b/src/unit/ArcanistUnitTestResult.php @@ -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; } diff --git a/src/unit/parser/ArcanistGoTestResultParser.php b/src/unit/parser/ArcanistGoTestResultParser.php index fa0a2672..ce6451f5 100644 --- a/src/unit/parser/ArcanistGoTestResultParser.php +++ b/src/unit/parser/ArcanistGoTestResultParser.php @@ -31,7 +31,7 @@ final class ArcanistGoTestResultParser extends ArcanistTestResultParser { // We have a passing test $meta = array(); preg_match( - '/^--- PASS: (?P.+) \((?P