Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F34166170
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
13 KB
Subscribers
None
View Options
diff --git a/src/unit/parser/ArcanistGoTestResultParser.php b/src/unit/parser/ArcanistGoTestResultParser.php
index c5729416..41463f10 100644
--- a/src/unit/parser/ArcanistGoTestResultParser.php
+++ b/src/unit/parser/ArcanistGoTestResultParser.php
@@ -1,134 +1,134 @@
<?php
/**
* Go Test Result Parsing utility
*
* (To generate test output, run something like: `go test -v`)
*/
final class ArcanistGoTestResultParser extends ArcanistTestResultParser {
/**
* Parse test results from Go test report
* (e.g. `go test -v`)
*
* @param string $path Path to test
* @param string $test_results String containing Go test output
*
* @return array
*/
public function parseTestResults($path, $test_results) {
$test_results = explode("\n", $test_results);
$results = array();
// We'll get our full test case name at the end and add it back in
$test_case_name = '';
// Temp store for test case results (in case we run multiple test cases)
$test_case_results = array();
foreach ($test_results as $i => $line) {
if (strncmp($line, '--- PASS', 8) === 0) {
// 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);
$result = new ArcanistUnitTestResult();
// 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']);
$test_case_results[] = $result;
continue;
}
if (strncmp($line, '--- FAIL', 8) === 0) {
// We have a failing test
$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);
$result = new ArcanistUnitTestResult();
$result->setName($meta['test_name']);
$result->setResult(ArcanistUnitTestResult::RESULT_FAIL);
$result->setDuration($meta['time']);
$result->setUserData($reason."\n");
$test_case_results[] = $result;
continue;
}
if (strncmp($line, 'ok', 2) === 0) {
$meta = array();
preg_match(
'/^ok[\s\t]+(?P<test_name>\w.*)[\s\t]+(?P<time>.*)s.*/',
$line,
$meta);
$test_case_name = str_replace('/', '::', $meta['test_name']);
// Our test case passed
// check to make sure we were in verbose (-v) mode
if (empty($test_case_results)) {
// We weren't in verbose mode
// create one successful result for the whole test case
$test_name = 'Go::TestCase::'.$test_case_name;
$result = new ArcanistUnitTestResult();
$result->setName($test_name);
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
$result->setDuration($meta['time']);
$results[] = $result;
} else {
$test_case_results = $this->fixNames(
$test_case_results,
$test_case_name);
$results = array_merge($results, $test_case_results);
$test_case_results = array();
}
continue;
}
if (strncmp($line, "FAIL\t", 5) === 0) {
$meta = array();
preg_match(
'/^FAIL[\s\t]+(?P<test_name>\w.*)[\s\t]+.*/',
$line,
$meta);
$test_case_name = str_replace('/', '::', $meta['test_name']);
$test_case_results = $this->fixNames(
$test_case_results,
$test_case_name);
$results = array_merge($results, $test_case_results);
$test_case_results = array();
continue;
}
}
return $results;
}
private function fixNames($test_case_results, $test_case_name) {
foreach ($test_case_results as &$result) {
$test_name = $result->getName();
$result->setName('Go::Test::'.$test_case_name.'::'.$test_name);
}
return $test_case_results;
}
}
diff --git a/src/unit/parser/__tests__/ArcanistGoTestResultParserTestCase.php b/src/unit/parser/__tests__/ArcanistGoTestResultParserTestCase.php
index abf62108..0c04f94f 100644
--- a/src/unit/parser/__tests__/ArcanistGoTestResultParserTestCase.php
+++ b/src/unit/parser/__tests__/ArcanistGoTestResultParserTestCase.php
@@ -1,106 +1,204 @@
<?php
/**
* Test for @{class:ArcanistGoTestResultParser}.
*/
final class ArcanistGoTestResultParserTestCase extends ArcanistTestCase {
public function testSingleTestCaseSuccessful() {
$stubbed_results = Filesystem::readFile(
dirname(__FILE__).'/testresults/go.single-test-case-successful');
$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 testSingleTestCaseFailure() {
$stubbed_results = Filesystem::readFile(
dirname(__FILE__).'/testresults/go.single-test-case-failure');
$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 testMultipleTestCasesSuccessful() {
$stubbed_results = Filesystem::readFile(
dirname(__FILE__).'/testresults/go.multiple-test-cases-successful');
$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 testMultipleTestCasesFailure() {
$stubbed_results = Filesystem::readFile(
dirname(__FILE__).'/testresults/go.multiple-test-cases-failure');
$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());
}
public function testNonVerboseOutput() {
$stubbed_results = Filesystem::readFile(
dirname(__FILE__).'/testresults/go.nonverbose');
$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 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
index 00000000..2bb27f38
--- /dev/null
+++ b/src/unit/parser/__tests__/testresults/go.multiple-test-cases-failure-go1.4
@@ -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
index 00000000..0816ef0f
--- /dev/null
+++ b/src/unit/parser/__tests__/testresults/go.multiple-test-cases-successful-go1.4
@@ -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
index 00000000..c6cd12b2
--- /dev/null
+++ b/src/unit/parser/__tests__/testresults/go.nonverbose-go1.4
@@ -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
index 00000000..87c6bd2d
--- /dev/null
+++ b/src/unit/parser/__tests__/testresults/go.single-test-case-failure-go1.4
@@ -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
index 00000000..b37f92ce
--- /dev/null
+++ b/src/unit/parser/__tests__/testresults/go.single-test-case-successful-go1.4
@@ -0,0 +1,6 @@
+=== RUN TestFoo
+--- PASS: TestFoo (0.03s)
+=== RUN TestBar
+--- PASS: TestBar (0.01s)
+PASS
+ok package/subpackage 0.042s
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Dec 12, 11:32 AM (1 d, 22 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
bb/a2/69562df6412bfd0813f03cefdffa
Attached To
rARC Arcanist
Event Timeline
Log In to Comment