Changeset View
Changeset View
Standalone View
Standalone View
src/unit/parser/ArcanistXUnitTestResultParser.php
| Show All 10 Lines | final class ArcanistXUnitTestResultParser { | ||||
| * | * | ||||
| * @param string $test_results String containing test results | * @param string $test_results String containing test results | ||||
| * | * | ||||
| * @return array ArcanistUnitTestResult | * @return array ArcanistUnitTestResult | ||||
| */ | */ | ||||
| public function parseTestResults($test_results) { | public function parseTestResults($test_results) { | ||||
| if (!strlen($test_results)) { | if (!strlen($test_results)) { | ||||
| throw new Exception( | throw new Exception( | ||||
| 'test_results argument to parseTestResults must not be empty'); | pht( | ||||
| '%s argument to %s must not be empty', | |||||
| 'test_results', | |||||
| 'parseTestResults()')); | |||||
| } | } | ||||
| // xunit xsd: https://gist.github.com/959290 | // xunit xsd: https://gist.github.com/959290 | ||||
| $xunit_dom = new DOMDocument(); | $xunit_dom = new DOMDocument(); | ||||
| $load_success = @$xunit_dom->loadXML($test_results); | $load_success = @$xunit_dom->loadXML($test_results); | ||||
| if (!$load_success) { | if (!$load_success) { | ||||
| $input_start = id(new PhutilUTF8StringTruncator()) | $input_start = id(new PhutilUTF8StringTruncator()) | ||||
| ->setMaximumGlyphs(150) | ->setMaximumGlyphs(150) | ||||
| ->truncateString($test_results); | ->truncateString($test_results); | ||||
| throw new Exception( | throw new Exception( | ||||
| "Failed to load XUnit report; Input starts with:\n\n {$input_start}"); | sprintf( | ||||
| "%s\n\n%s", | |||||
| pht('Failed to load XUnit report; Input starts with:'), | |||||
| $input_start)); | |||||
| } | } | ||||
| $results = array(); | $results = array(); | ||||
| $testcases = $xunit_dom->getElementsByTagName('testcase'); | $testcases = $xunit_dom->getElementsByTagName('testcase'); | ||||
| foreach ($testcases as $testcase) { | foreach ($testcases as $testcase) { | ||||
| $classname = $testcase->getAttribute('classname'); | $classname = $testcase->getAttribute('classname'); | ||||
| $name = $testcase->getAttribute('name'); | $name = $testcase->getAttribute('name'); | ||||
| $time = $testcase->getAttribute('time'); | $time = $testcase->getAttribute('time'); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines | |||||