From 538115bd0ef68381c37a3d1d208decdffde081cb Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 22 Oct 2012 11:41:33 -0700 Subject: [PATCH] Use PhutilAggregateException to aggregate unit test exceptions Summary: Currently, a shutdown exception ("script exited with open transactions!") overwhelms the actual test failure exception, which is the one that needs to be fixed. Test Plan: Ran a fixture test which opens a transaction and then throws. Got diagnostically useful output after this patch. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Differential Revision: https://secure.phabricator.com/D3780 --- .../engine/phutil/ArcanistPhutilTestCase.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/unit/engine/phutil/ArcanistPhutilTestCase.php b/src/unit/engine/phutil/ArcanistPhutilTestCase.php index 17ad7574..fed0f5ee 100644 --- a/src/unit/engine/phutil/ArcanistPhutilTestCase.php +++ b/src/unit/engine/phutil/ArcanistPhutilTestCase.php @@ -421,19 +421,30 @@ abstract class ArcanistPhutilTestCase { $this->willRunOneTest($name); $this->beginCoverage(); - $test_exception = null; + $exceptions = array(); try { call_user_func_array( array($this, $name), array()); $this->passTest(pht('%d assertion(s) passed.', $this->assertions)); } catch (Exception $ex) { - $test_exception = $ex; + $exceptions['Execution'] = $ex; } - $this->didRunOneTest($name); - if ($test_exception) { - throw $test_exception; + try { + $this->didRunOneTest($name); + } catch (Exception $ex) { + $exceptions['Shutdown'] = $ex; + } + + if ($exceptions) { + if (count($exceptions) == 1) { + throw head($exceptions); + } else { + throw new PhutilAggregateException( + "Multiple exceptions were raised during test execution.", + $exceptions); + } } } catch (ArcanistPhutilTestTerminatedException $ex) { // Continue with the next test.