Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/ArcanistXUnitTestResultParser.php
| Show All 26 Lines | public function parseTestResults($test_results) { | ||||
| if (!$load_success) { | if (!$load_success) { | ||||
| $input_start = phutil_utf8_shorten($test_results, 150); | $input_start = phutil_utf8_shorten($test_results, 150); | ||||
| throw new Exception( | throw new Exception( | ||||
| "Failed to load XUnit report; Input starts with:\n\n {$input_start}"); | "Failed to load XUnit report; Input starts with:\n\n {$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'); | ||||
| $status = ArcanistUnitTestResult::RESULT_PASS; | $status = ArcanistUnitTestResult::RESULT_PASS; | ||||
| $user_data = ""; | $user_data = ''; | ||||
| // A skipped test is a test which was ignored using framework | // A skipped test is a test which was ignored using framework | ||||
| // mechanizms (e.g. @skip decorator) | // mechanizms (e.g. @skip decorator) | ||||
| $skipped = $testcase->getElementsByTagName("skipped"); | $skipped = $testcase->getElementsByTagName('skipped'); | ||||
| if ($skipped->length > 0) { | if ($skipped->length > 0) { | ||||
| $status = ArcanistUnitTestResult::RESULT_SKIP; | $status = ArcanistUnitTestResult::RESULT_SKIP; | ||||
| $messages = array(); | $messages = array(); | ||||
| for ($ii = 0; $ii < $skipped->length; $ii++) { | for ($ii = 0; $ii < $skipped->length; $ii++) { | ||||
| $messages[] = trim($skipped->item($ii)->nodeValue, " \n"); | $messages[] = trim($skipped->item($ii)->nodeValue, " \n"); | ||||
| } | } | ||||
| $user_data .= implode("\n", $messages); | $user_data .= implode("\n", $messages); | ||||
| } | } | ||||
| // Failure is a test which the code has explicitly failed by using | // Failure is a test which the code has explicitly failed by using | ||||
| // the mechanizms for that purpose. e.g., via an assertEquals | // the mechanizms for that purpose. e.g., via an assertEquals | ||||
| $failures = $testcase->getElementsByTagName("failure"); | $failures = $testcase->getElementsByTagName('failure'); | ||||
| if ($failures->length > 0) { | if ($failures->length > 0) { | ||||
| $status = ArcanistUnitTestResult::RESULT_FAIL; | $status = ArcanistUnitTestResult::RESULT_FAIL; | ||||
| $messages = array(); | $messages = array(); | ||||
| for ($ii = 0; $ii < $failures->length; $ii++) { | for ($ii = 0; $ii < $failures->length; $ii++) { | ||||
| $messages[] = trim($failures->item($ii)->nodeValue, " \n"); | $messages[] = trim($failures->item($ii)->nodeValue, " \n"); | ||||
| } | } | ||||
| $user_data .= implode("\n", $messages)."\n"; | $user_data .= implode("\n", $messages)."\n"; | ||||
| } | } | ||||
| // An errored test is one that had an unanticipated problem. e.g., an | // An errored test is one that had an unanticipated problem. e.g., an | ||||
| // unchecked throwable, or a problem with an implementation of the | // unchecked throwable, or a problem with an implementation of the | ||||
| // test. | // test. | ||||
| $errors = $testcase->getElementsByTagName("error"); | $errors = $testcase->getElementsByTagName('error'); | ||||
| if ($errors->length > 0) { | if ($errors->length > 0) { | ||||
| $status = ArcanistUnitTestResult::RESULT_BROKEN; | $status = ArcanistUnitTestResult::RESULT_BROKEN; | ||||
| $messages = array(); | $messages = array(); | ||||
| for ($ii = 0; $ii < $errors->length; $ii++) { | for ($ii = 0; $ii < $errors->length; $ii++) { | ||||
| $messages[] = trim($errors->item($ii)->nodeValue, " \n"); | $messages[] = trim($errors->item($ii)->nodeValue, " \n"); | ||||
| } | } | ||||
| $user_data .= implode("\n", $messages)."\n"; | $user_data .= implode("\n", $messages)."\n"; | ||||
| } | } | ||||
| $result = new ArcanistUnitTestResult(); | $result = new ArcanistUnitTestResult(); | ||||
| $result->setName($classname.".".$name); | $result->setName($classname.'.'.$name); | ||||
| $result->setResult($status); | $result->setResult($status); | ||||
| $result->setDuration($time); | $result->setDuration($time); | ||||
| $result->setUserData($user_data); | $result->setUserData($user_data); | ||||
| $results[] = $result; | $results[] = $result; | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| } | } | ||||