Changeset View
Changeset View
Standalone View
Standalone View
src/unit/parser/ArcanistGoTestResultParser.php
<?php | <?php | ||||
/** | /** | ||||
* Go Test Result Parsing utility | * Go Test Result Parsing utility | ||||
* | * | ||||
* (To generate test output, run something like: `go test -v`) | * (To generate test output, run something like: `go test -v`) | ||||
*/ | */ | ||||
final class ArcanistGoTestResultParser extends ArcanistTestResultParser { | final class ArcanistGoTestResultParser extends ArcanistTestResultParser { | ||||
/** | /** | ||||
* Parse test results from Go test report | * Parse test results from Go test report | ||||
* (e.g. `go test -v`) | * (e.g. `go test -v`) | ||||
* | * | ||||
* @param string $path Path to test | * @param string $path Path to test | ||||
* @param string $test_results String containing Go test output | * @param string $stdout the Stdout of the command. | ||||
* @param string $stderr the Stderr of the command. | |||||
* | * | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
public function parseTestResults($path, $test_results) { | public function parseTestResults($path, $stdout, $stderr = '') { | ||||
rayzyar: build failure is not handled here,
I tried to detect by `[build failed]`, but some build… | |||||
$test_results = $stderr.$stdout; | |||||
$test_results = explode("\n", $test_results); | $test_results = explode("\n", $test_results); | ||||
$results = array(); | $results = array(); | ||||
// We'll get our full test case name at the end and add it back in | // We'll get our full test case name at the end and add it back in | ||||
$test_case_name = ''; | $test_case_name = ''; | ||||
// Temp store for test case results (in case we run multiple test cases) | // Temp store for test case results (in case we run multiple test cases) | ||||
$test_case_results = array(); | $test_case_results = array(); | ||||
foreach ($test_results as $i => $line) { | for ($i = 0; $i < count($test_results); $i++) { | ||||
$line = $test_results[$i]; | |||||
if (strlen($line) >= 18 | |||||
&& strncmp($line, '==================', 18) === 0 | |||||
&& strncmp($test_results[$i + 1], 'WARNING: DATA RACE', 18) === 0) { | |||||
// We have a race condition | |||||
$i++; // Advance to WARNING: DATA RACE | |||||
$reason = ''; | |||||
$test_name = ''; | |||||
// loop to collect all data and move to the === line | |||||
while (strncmp($test_results[$i], '==================', 18) !== 0) { | |||||
if (strncmp($test_results[$i], 'Goroutine', 9) === 0) { | |||||
$meta = array(); | |||||
preg_match( | |||||
'/^.*\.(?P<test_name>[^\.]+)$/', | |||||
$test_results[$i + 1], | |||||
$meta); | |||||
$test_name = $meta['test_name'].' Race Detected'; | |||||
} | |||||
$reason .= $test_results[$i++]."\n"; | |||||
// Are we out of lines? | |||||
if ($i > count($test_results)) { | |||||
return false; | |||||
} | |||||
} | |||||
$result = new ArcanistUnitTestResult(); | |||||
$result->setName($test_name); | |||||
$result->setResult(ArcanistUnitTestResult::RESULT_FAIL); | |||||
$result->setUserData($reason); | |||||
$test_case_results[] = $result; | |||||
continue; | |||||
} | |||||
if (strncmp($line, '--- PASS', 8) === 0) { | if (strncmp($line, '--- PASS', 8) === 0) { | ||||
// We have a passing test | // We have a passing test | ||||
$meta = array(); | $meta = array(); | ||||
preg_match( | preg_match( | ||||
'/^--- PASS: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds)?\).*/', | '/^--- PASS: (?P<test_name>.+) \((?P<time>.+)\s*s(?:econds)?\).*/', | ||||
$line, | $line, | ||||
$meta); | $meta); | ||||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
build failure is not handled here,
I tried to detect by [build failed], but some build failure case does not print this