Changeset View
Changeset View
Standalone View
Standalone View
src/unit/engine/ArcanistXUnitTestResultParser.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Parser for JUnit, NUnit, etc results format - https://gist.github.com/959290 | * Parser for JUnit, NUnit, etc results format - https://gist.github.com/959290 | ||||
| * | |||||
| * @group unitrun | |||||
| */ | */ | ||||
| final class ArcanistXUnitTestResultParser { | final class ArcanistXUnitTestResultParser { | ||||
| /** | /** | ||||
| * Parse test results from provided input and return an array | * Parse test results from provided input and return an array | ||||
| * of ArcanistUnitTestResult | * of @{class:ArcanistUnitTestResult}. | ||||
| * | * | ||||
| * @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( | ||||
| Show All 16 Lines | 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) | // mechanisms (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 mechanisms 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"); | ||||
| } | } | ||||
| Show All 16 Lines | |||||