1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-29 10:12:41 +01:00

allow either (<time> seconds) or (<time>s) format for test result time

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
This commit is contained in:
ArtemTitoulenko 2015-04-21 12:02:32 -07:00 committed by epriestley
parent c56e4a56dc
commit a9ebe1cb4f
7 changed files with 138 additions and 2 deletions

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>.+) 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);

View 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());
}
}

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,2 @@
ok package/subpackage1 0.042s
ok package/subpackage2 0.021s

View file

@ -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

View file

@ -0,0 +1,6 @@
=== RUN TestFoo
--- PASS: TestFoo (0.03s)
=== RUN TestBar
--- PASS: TestBar (0.01s)
PASS
ok package/subpackage 0.042s