]> khamidou — GitHub mirrors - arcanist.git/commitdiff
allow either (<time> seconds) or (<time>s) format for test result time
authorArtemTitoulenko <artem.titoulenko@gmail.com>
Tue, 21 Apr 2015 19:02:32 +0000 (12:02 -0700)
committerepriestley <git@epriestley.com>
Tue, 21 Apr 2015 19:02:32 +0000 (12:02 -0700)
Summary: The default Go Test Parser stopped showing the test function name at the end of the package after some Go upgrade. We fixed it locally and wanted to share it upstream.

Test Plan: We ran it on our test suite using go1.4.2 darwin/amd64. We have version-dependent code which cannot be compiled with earlier versions of Go, unfortunately.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: avivey, Korvin, epriestley

Maniphest Tasks: T7845

Differential Revision: https://secure.phabricator.com/D12436

src/unit/parser/ArcanistGoTestResultParser.php
src/unit/parser/__tests__/ArcanistGoTestResultParserTestCase.php
src/unit/parser/__tests__/testresults/go.multiple-test-cases-failure-go1.4 [new file with mode: 0644]
src/unit/parser/__tests__/testresults/go.multiple-test-cases-successful-go1.4 [new file with mode: 0644]
src/unit/parser/__tests__/testresults/go.nonverbose-go1.4 [new file with mode: 0644]
src/unit/parser/__tests__/testresults/go.single-test-case-failure-go1.4 [new file with mode: 0644]
src/unit/parser/__tests__/testresults/go.single-test-case-successful-go1.4 [new file with mode: 0644]

index c57294163f41b9962ad5c6e2a2a621edcc4105f9..41463f108dcb3b4f55503509917a90be9fced69a 100644 (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>.+) seconds\).*/',
+          '/^--- PASS: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds)?\).*/',
           $line,
           $meta);
 
@@ -51,7 +51,7 @@ final class ArcanistGoTestResultParser extends ArcanistTestResultParser {
         $reason = trim($test_results[$i + 1]);
         $meta = array();
         preg_match(
-          '/^--- FAIL: (?P<test_name>.+) \((?P<time>.+) seconds\).*/',
+          '/^--- FAIL: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds)?\).*/',
           $line,
           $meta);
 
index abf62108bae606404ba72d5ebaacd9b13148e63d..0c04f94fce7af2b1b0651d2e59b7b88268310537 100644 (file)
@@ -103,4 +103,102 @@ final class ArcanistGoTestResultParserTestCase extends ArcanistTestCase {
     }
   }
 
+  public function testSingleTestCaseSuccessfulGo14() {
+    $stubbed_results = Filesystem::readFile(
+      dirname(__FILE__).'/testresults/go.single-test-case-successful-go1.4');
+
+    $parsed_results = id(new ArcanistGoTestResultParser())
+      ->parseTestResults('subpackage_test.go', $stubbed_results);
+
+    $this->assertEqual(2, count($parsed_results));
+    $this->assertEqual(
+      'Go::Test::package::subpackage::TestFoo',
+      $parsed_results[0]->getName());
+    foreach ($parsed_results as $result) {
+      $this->assertEqual(
+        ArcanistUnitTestResult::RESULT_PASS,
+        $result->getResult());
+    }
+  }
+
+  public function testSingleTestCaseFailureGo14() {
+    $stubbed_results = Filesystem::readFile(
+      dirname(__FILE__).'/testresults/go.single-test-case-failure-go1.4');
+
+    $parsed_results = id(new ArcanistGoTestResultParser())
+      ->parseTestResults('subpackage_test.go', $stubbed_results);
+
+    $this->assertEqual(2, count($parsed_results));
+    $this->assertEqual(
+      ArcanistUnitTestResult::RESULT_FAIL,
+      $parsed_results[0]->getResult());
+    $this->assertEqual(
+      ArcanistUnitTestResult::RESULT_PASS,
+      $parsed_results[1]->getResult());
+  }
+
+  public function testNonVerboseOutputGo14() {
+    $stubbed_results = Filesystem::readFile(
+      dirname(__FILE__).'/testresults/go.nonverbose-go1.4');
+
+    $parsed_results = id(new ArcanistGoTestResultParser())
+      ->parseTestResults('package', $stubbed_results);
+
+    $this->assertEqual(2, count($parsed_results));
+    $this->assertEqual(
+      'Go::TestCase::package::subpackage1',
+      $parsed_results[0]->getName());
+    $this->assertEqual(
+      'Go::TestCase::package::subpackage2',
+      $parsed_results[1]->getName());
+    foreach ($parsed_results as $result) {
+      $this->assertEqual(
+        ArcanistUnitTestResult::RESULT_PASS,
+        $result->getResult());
+    }
+  }
+
+  public function testMultipleTestCasesSuccessfulGo14() {
+    $stubbed_results = Filesystem::readFile(
+      dirname(__FILE__).'/testresults/go.multiple-test-cases-successful-go1.4');
+
+    $parsed_results = id(new ArcanistGoTestResultParser())
+      ->parseTestResults('package', $stubbed_results);
+
+    $this->assertEqual(3, count($parsed_results));
+    $this->assertEqual(
+      'Go::Test::package::subpackage1::TestFoo1',
+      $parsed_results[0]->getName());
+    $this->assertEqual(
+      'Go::Test::package::subpackage2::TestFoo2',
+      $parsed_results[2]->getName());
+    foreach ($parsed_results as $result) {
+      $this->assertEqual(
+        ArcanistUnitTestResult::RESULT_PASS,
+        $result->getResult());
+    }
+  }
+
+
+  public function testMultipleTestCasesFailureGo14() {
+    $stubbed_results = Filesystem::readFile(
+      dirname(__FILE__).'/testresults/go.multiple-test-cases-failure-go1.4');
+
+    $parsed_results = id(new ArcanistGoTestResultParser())
+      ->parseTestResults('package', $stubbed_results);
+
+    $this->assertEqual(3, count($parsed_results));
+    $this->assertEqual(
+      'Go::Test::package::subpackage1::TestFoo1',
+      $parsed_results[0]->getName());
+    $this->assertEqual(
+      'Go::Test::package::subpackage2::TestFoo2',
+      $parsed_results[2]->getName());
+    $this->assertEqual(
+      ArcanistUnitTestResult::RESULT_PASS,
+      $parsed_results[0]->getResult());
+    $this->assertEqual(
+      ArcanistUnitTestResult::RESULT_FAIL,
+      $parsed_results[2]->getResult());
+  }
 }
diff --git a/src/unit/parser/__tests__/testresults/go.multiple-test-cases-failure-go1.4 b/src/unit/parser/__tests__/testresults/go.multiple-test-cases-failure-go1.4
new file mode 100644 (file)
index 0000000..2bb27f3
--- /dev/null
@@ -0,0 +1,12 @@
+=== RUN TestFoo1
+--- PASS: TestFoo1 (0.03s)
+=== RUN TestBar1
+--- PASS: TestBar1 (0.01s)
+PASS
+ok     package/subpackage1     0.042s
+=== RUN TestFoo2
+--- FAIL: TestFoo2 (0.02s)
+       subpackage2_test.go:53: got: 2, want: 1
+FAIL
+exit status 1
+FAIL   package/subpackage2     0.020s
diff --git a/src/unit/parser/__tests__/testresults/go.multiple-test-cases-successful-go1.4 b/src/unit/parser/__tests__/testresults/go.multiple-test-cases-successful-go1.4
new file mode 100644 (file)
index 0000000..0816ef0
--- /dev/null
@@ -0,0 +1,10 @@
+=== RUN TestFoo1
+--- PASS: TestFoo1 (0.03s)
+=== RUN TestBar1
+--- PASS: TestBar1 (0.01s)
+PASS
+ok     package/subpackage1     0.042s
+=== RUN TestFoo2
+--- PASS: TestFoo2 (0.02s)
+PASS
+ok     package/subpackage2     0.021s
diff --git a/src/unit/parser/__tests__/testresults/go.nonverbose-go1.4 b/src/unit/parser/__tests__/testresults/go.nonverbose-go1.4
new file mode 100644 (file)
index 0000000..c6cd12b
--- /dev/null
@@ -0,0 +1,2 @@
+ok     package/subpackage1     0.042s
+ok     package/subpackage2     0.021s
diff --git a/src/unit/parser/__tests__/testresults/go.single-test-case-failure-go1.4 b/src/unit/parser/__tests__/testresults/go.single-test-case-failure-go1.4
new file mode 100644 (file)
index 0000000..87c6bd2
--- /dev/null
@@ -0,0 +1,8 @@
+=== RUN TestFoo
+--- FAIL: TestFoo (0.03s)
+       subpackage_test.go:53: got: 2, want: 1
+=== RUN TestBar
+--- PASS: TestBar (0.01s)
+FAIL
+exit status 1
+FAIL   package/subpackage      0.042s
diff --git a/src/unit/parser/__tests__/testresults/go.single-test-case-successful-go1.4 b/src/unit/parser/__tests__/testresults/go.single-test-case-successful-go1.4
new file mode 100644 (file)
index 0000000..b37f92c
--- /dev/null
@@ -0,0 +1,6 @@
+=== RUN TestFoo
+--- PASS: TestFoo (0.03s)
+=== RUN TestBar
+--- PASS: TestBar (0.01s)
+PASS
+ok     package/subpackage      0.042s