]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Use PhutilAggregateException to aggregate unit test exceptions
authorepriestley <git@epriestley.com>
Mon, 22 Oct 2012 18:41:33 +0000 (11:41 -0700)
committerepriestley <git@epriestley.com>
Mon, 22 Oct 2012 18:41:33 +0000 (11:41 -0700)
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

src/unit/engine/phutil/ArcanistPhutilTestCase.php

index 17ad75749d1f14ee97583633101f1930696ccdd9..fed0f5ee5d2cd6136c5678ce79b9dcdd500ae021 100644 (file)
@@ -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.