4
* Go Test Result Parsing utility
6
* (To generate test output, run something like: `go test -v`)
8
final class GoTestResultParser extends ArcanistTestResultParser {
11
* Parse test results from Go test report
14
* @param string $path Path to test
15
* @param string $test_results String containing Go test output
19
public function parseTestResults($path, $test_results) {
20
$test_results = explode("\n", $test_results);
23
// We'll get our full test case name at the end and add it back in
26
// Temp store for test case results (in case we run multiple test cases)
27
$test_case_results = array();
28
foreach ($test_results as $i => $line) {
30
if (strncmp($line, '--- PASS', 8) === 0) {
31
// We have a passing test
34
'/^--- PASS: (?P<test_name>.+) \((?P<time>.+) seconds\).*/',
38
$result = new ArcanistUnitTestResult();
39
// For now set name without test case, we'll add it later
40
$result->setName($meta['test_name']);
41
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
42
$result->setDuration($meta['time']);
44
$test_case_results[] = $result;
49
if (strncmp($line, '--- FAIL', 8) === 0) {
50
// We have a failing test
51
$reason = trim($test_results[$i + 1]);
54
'/^--- FAIL: (?P<test_name>.+) \((?P<time>.+) seconds\).*/',
58
$result = new ArcanistUnitTestResult();
59
$result->setName($meta['test_name']);
60
$result->setResult(ArcanistUnitTestResult::RESULT_FAIL);
61
$result->setDuration($meta['time']);
62
$result->setUserData($reason."\n");
64
$test_case_results[] = $result;
69
if (strncmp($line, 'ok', 2) === 0) {
72
'/^ok[\s\t]+(?P<test_name>\w.*)[\s\t]+(?P<time>.*)s.*/',
76
$test_case_name = str_replace('/', '::', $meta['test_name']);
78
// Our test case passed
79
// check to make sure we were in verbose (-v) mode
80
if (empty($test_case_results)) {
81
// We weren't in verbose mode
82
// create one successful result for the whole test case
83
$test_name = 'Go::TestCase::'.$test_case_name;
85
$result = new ArcanistUnitTestResult();
86
$result->setName($test_name);
87
$result->setResult(ArcanistUnitTestResult::RESULT_PASS);
88
$result->setDuration($meta['time']);
92
$test_case_results = $this->fixNames(
95
$results = array_merge($results, $test_case_results);
96
$test_case_results = array();
102
if (strncmp($line, "FAIL\t", 5) === 0) {
105
'/^FAIL[\s\t]+(?P<test_name>\w.*)[\s\t]+.*/',
109
$test_case_name = str_replace('/', '::', $meta['test_name']);
111
$test_case_results = $this->fixNames(
114
$results = array_merge($results, $test_case_results);
115
$test_case_results = array();
124
private function fixNames($test_case_results, $test_case_name) {
126
foreach ($test_case_results as &$result) {
127
$test_name = $result->getName();
128
$result->setName('Go::Test::'.$test_case_name.'::'.$test_name);
131
return $test_case_results;