Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/GoTestResultParser.php
| Show All 22 Lines | final class GoTestResultParser extends ArcanistBaseTestResultParser { | ||||
| * @return array | * @return array | ||||
| */ | */ | ||||
| public function parseTestResults($path, $test_results) { | public function parseTestResults($path, $test_results) { | ||||
| $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) { | foreach ($test_results as $i => $line) { | ||||
| 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>.+) seconds\).*/', | '/^--- PASS: (?P<test_name>.+) \((?P<time>.+) seconds\).*/', | ||||
| $line, | $line, | ||||
| $meta); | $meta); | ||||
| $result = new ArcanistUnitTestResult(); | $result = new ArcanistUnitTestResult(); | ||||
| // For now set name without test case, we'll add it later | // For now set name without test case, we'll add it later | ||||
| $result->setName($meta['test_name']); | $result->setName($meta['test_name']); | ||||
| $result->setResult(ArcanistUnitTestResult::RESULT_PASS); | $result->setResult(ArcanistUnitTestResult::RESULT_PASS); | ||||
| $result->setDuration($meta['time']); | $result->setDuration($meta['time']); | ||||
| $test_case_results[] = $result; | $test_case_results[] = $result; | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (strncmp($line, "--- FAIL", 8) === 0) { | if (strncmp($line, '--- FAIL', 8) === 0) { | ||||
| // We have a failing test | // We have a failing test | ||||
| $reason = trim($test_results[$i + 1]); | $reason = trim($test_results[$i + 1]); | ||||
| $meta = array(); | $meta = array(); | ||||
| preg_match( | preg_match( | ||||
| '/^--- FAIL: (?P<test_name>.+) \((?P<time>.+) seconds\).*/', | '/^--- FAIL: (?P<test_name>.+) \((?P<time>.+) seconds\).*/', | ||||
| $line, | $line, | ||||
| $meta); | $meta); | ||||
| $result = new ArcanistUnitTestResult(); | $result = new ArcanistUnitTestResult(); | ||||
| $result->setName($meta['test_name']); | $result->setName($meta['test_name']); | ||||
| $result->setResult(ArcanistUnitTestResult::RESULT_FAIL); | $result->setResult(ArcanistUnitTestResult::RESULT_FAIL); | ||||
| $result->setDuration($meta['time']); | $result->setDuration($meta['time']); | ||||
| $result->setUserData($reason."\n"); | $result->setUserData($reason."\n"); | ||||
| $test_case_results[] = $result; | $test_case_results[] = $result; | ||||
| continue; | continue; | ||||
| } | } | ||||
| if (strncmp($line, "ok", 2) === 0) { | if (strncmp($line, 'ok', 2) === 0) { | ||||
| $meta = array(); | $meta = array(); | ||||
| preg_match( | preg_match( | ||||
| '/^ok[\s\t]+(?P<test_name>\w.*)[\s\t]+(?P<time>.*)s.*/', | '/^ok[\s\t]+(?P<test_name>\w.*)[\s\t]+(?P<time>.*)s.*/', | ||||
| $line, | $line, | ||||
| $meta); | $meta); | ||||
| $test_case_name = str_replace("/", "::", $meta['test_name']); | $test_case_name = str_replace('/', '::', $meta['test_name']); | ||||
| // Our test case passed | // Our test case passed | ||||
| // check to make sure we were in verbose (-v) mode | // check to make sure we were in verbose (-v) mode | ||||
| if (empty($test_case_results)) { | if (empty($test_case_results)) { | ||||
| // We weren't in verbose mode | // We weren't in verbose mode | ||||
| // create one successful result for the whole test case | // create one successful result for the whole test case | ||||
| $test_name = "Go::TestCase::".$test_case_name; | $test_name = 'Go::TestCase::'.$test_case_name; | ||||
| $result = new ArcanistUnitTestResult(); | $result = new ArcanistUnitTestResult(); | ||||
| $result->setName($test_name); | $result->setName($test_name); | ||||
| $result->setResult(ArcanistUnitTestResult::RESULT_PASS); | $result->setResult(ArcanistUnitTestResult::RESULT_PASS); | ||||
| $result->setDuration($meta['time']); | $result->setDuration($meta['time']); | ||||
| $results[] = $result; | $results[] = $result; | ||||
| } else { | } else { | ||||
| Show All 9 Lines | foreach ($test_results as $i => $line) { | ||||
| if (strncmp($line, "FAIL\t", 5) === 0) { | if (strncmp($line, "FAIL\t", 5) === 0) { | ||||
| $meta = array(); | $meta = array(); | ||||
| preg_match( | preg_match( | ||||
| '/^FAIL[\s\t]+(?P<test_name>\w.*)[\s\t]+.*/', | '/^FAIL[\s\t]+(?P<test_name>\w.*)[\s\t]+.*/', | ||||
| $line, | $line, | ||||
| $meta); | $meta); | ||||
| $test_case_name = str_replace("/", "::", $meta['test_name']); | $test_case_name = str_replace('/', '::', $meta['test_name']); | ||||
| $test_case_results = $this->fixNames( | $test_case_results = $this->fixNames( | ||||
| $test_case_results, | $test_case_results, | ||||
| $test_case_name); | $test_case_name); | ||||
| $results = array_merge($results, $test_case_results); | $results = array_merge($results, $test_case_results); | ||||
| $test_case_results = array(); | $test_case_results = array(); | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| private function fixNames($test_case_results, $test_case_name) { | private function fixNames($test_case_results, $test_case_name) { | ||||
| foreach ($test_case_results as &$result) { | foreach ($test_case_results as &$result) { | ||||
| $test_name = $result->getName(); | $test_name = $result->getName(); | ||||
| $result->setName("Go::Test::".$test_case_name."::".$test_name); | $result->setName('Go::Test::'.$test_case_name.'::'.$test_name); | ||||
| } | } | ||||
| return $test_case_results; | return $test_case_results; | ||||
| } | } | ||||
| } | } | ||||