]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Raise a more tailored error message when a third-party test engine returns bad results
authorepriestley <git@epriestley.com>
Wed, 1 Jul 2015 11:48:52 +0000 (04:48 -0700)
committerepriestley <git@epriestley.com>
Wed, 1 Jul 2015 11:48:52 +0000 (04:48 -0700)
Summary: Fixes T8714. When a test engine isn't returning the correct result type, shift suspicion onto it.

Test Plan: Faked error, got exception blaming test engine.

Reviewers: joshuaspence, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8714

Differential Revision: https://secure.phabricator.com/D13486

src/workflow/ArcanistUnitWorkflow.php

index 2d3d8a7abfad482dfecc968560d9b70e09bb8e18..567b772e0da37cc4b6090f84ee0f546043300d73 100644 (file)
@@ -184,6 +184,9 @@ EOTEXT
     }
 
     $results = $this->engine->run();
+
+    $this->validateUnitEngineResults($this->engine, $results);
+
     $this->testResults = $results;
 
     $console = PhutilConsole::getConsole();
@@ -368,4 +371,42 @@ EOTEXT
     return idx($known_formats, $format, 'full');
   }
 
+
+  /**
+   * Raise a tailored error when a unit test engine returns results in an
+   * invalid format.
+   *
+   * @param ArcanistUnitTestEngine The engine.
+   * @param wild Results from the engine.
+   */
+  private function validateUnitEngineResults(
+    ArcanistUnitTestEngine $engine,
+    $results) {
+
+    if (!is_array($results)) {
+      throw new Exception(
+        pht(
+          'Unit test engine (of class "%s") returned invalid results when '.
+          'run (with method "%s"). Expected a list of "%s" objects as results.',
+          get_class($engine),
+          'run()',
+          'ArcanistUnitTestResult'));
+    }
+
+    foreach ($results as $key => $result) {
+      if (!($result instanceof ArcanistUnitTestResult)) {
+        throw new Exception(
+          pht(
+            'Unit test engine (of class "%s") returned invalid results when '.
+            'run (with method "%s"). Expected a list of "%s" objects as '.
+            'results, but value with key "%s" is not valid.',
+            get_class($engine),
+            'run()',
+            'ArcanistUnitTestResult',
+            $key));
+      }
+    }
+
+  }
+
 }