]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Ship unresolved unit test information to Differential.
authorepriestley <epriestley@javelinjs.com>
Wed, 12 Jan 2011 06:13:31 +0000 (22:13 -0800)
committerepriestley <epriestley@javelinjs.com>
Wed, 12 Jan 2011 06:37:06 +0000 (22:37 -0800)
Summary:

Test Plan:

Reviewers:

CC:

src/__phutil_library_map__.php
src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php [new file with mode: 0644]
src/unit/engine/phutil/__tests__/__init__.php [new file with mode: 0644]
src/workflow/diff/ArcanistDiffWorkflow.php
src/workflow/unit/ArcanistUnitWorkflow.php

index e81845611503e469771145a13e414373edf9c053..4811d8c62fa71e5e3f46a6fba403a9cdfc536b9e 100644 (file)
@@ -63,6 +63,7 @@ phutil_register_library_map(array(
     'PhutilLintEngine' => 'lint/engine/phutil',
     'PhutilModuleRequirements' => 'staticanalysis/parsers/phutilmodule',
     'PhutilUnitTestEngine' => 'unit/engine/phutil',
+    'PhutilUnitTestEngineTestCase' => 'unit/engine/phutil/__tests__',
     'UnitTestableArcanistLintEngine' => 'lint/engine/test',
   ),
   'function' =>
@@ -98,6 +99,7 @@ phutil_register_library_map(array(
     'ArcanistXHPASTLinterTestCase' => 'ArcanistPhutilTestCase',
     'PhutilLintEngine' => 'ArcanistLintEngine',
     'PhutilUnitTestEngine' => 'ArcanistBaseUnitTestEngine',
+    'PhutilUnitTestEngineTestCase' => 'ArcanistPhutilTestCase',
     'UnitTestableArcanistLintEngine' => 'ArcanistLintEngine',
   ),
   'requires_interface' =>
diff --git a/src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php b/src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php
new file mode 100644 (file)
index 0000000..db3af08
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+
+/*
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+class PhutilUnitTestEngineTestCase extends ArcanistPhutilTestCase {
+
+  public function testPass() {
+    $this->assertEqual(1, 1, 'This test is expected to pass.');
+  }
+
+  public function testFail() {
+    $this->assertEqual(1, 2, 'This test is expected to fail.');
+  }
+
+}
diff --git a/src/unit/engine/phutil/__tests__/__init__.php b/src/unit/engine/phutil/__tests__/__init__.php
new file mode 100644 (file)
index 0000000..8e4ac28
--- /dev/null
@@ -0,0 +1,12 @@
+<?php
+/**
+ * This file is automatically generated. Lint this module to rebuild it.
+ * @generated
+ */
+
+
+
+phutil_require_module('arcanist', 'unit/engine/phutil/testcase');
+
+
+phutil_require_source('PhutilUnitTestEngineTestCase.php');
index cee3b70fdb1faf0725d3ac1e572badb22952238e..6e928ea44a6f9fde019e9cc8aab37c13e034b46b 100644 (file)
@@ -212,8 +212,10 @@ EOTEXT
 
     if ($lint_result === ArcanistLintWorkflow::RESULT_OKAY) {
       $lint = 'okay';
-    } else if ($lint_result === ArcanistLintWorkflow::RESULT_WARNINGS) {
+    } else if ($lint_result === ArcanistLintWorkflow::RESULT_ERRORS) {
       $lint = 'fail';
+    } else if ($lint_result === ArcanistLintWorkflow::RESULT_WARNINGS) {
+      $lint = 'warn';
     } else if ($lint_result === ArcanistLintWorkflow::RESULT_SKIP) {
       $lint = 'skip';
     } else {
@@ -222,9 +224,10 @@ EOTEXT
 
     if ($unit_result === ArcanistUnitWorkflow::RESULT_OKAY) {
       $unit = 'okay';
-    } else if ($unit_result === ArcanistUnitWorkflow::RESULT_UNSOUND ||
-               $unit_result === ArcanistUnitWorkflow::RESULT_FAIL) {
+    } else if ($unit_result === ArcanistUnitWorkflow::RESULT_FAIL) {
       $unit = 'fail';
+    } else if ($unit_result === ArcanistUnitWorkflow::RESULT_UNSOUND) {
+      $unit = 'warn';
     } else if ($unit_result === ArcanistUnitWorkflow::RESULT_SKIP) {
       $unit = 'skip';
     } else {
@@ -271,6 +274,24 @@ EOTEXT
         ));
     }
 
+    if ($this->unresolvedTests) {
+      $data = array();
+      foreach ($this->unresolvedTests as $test) {
+        $data[] = array(
+          'name'      => $test->getName(),
+          'result'    => $test->getResult(),
+          'userdata'  => $test->getUserData(),
+        );
+      }
+      $conduit->callMethodSynchronous(
+        'differential.setdiffproperty',
+        array(
+          'diff_id' => $diff_info['diffid'],
+          'name'    => 'arc:unit',
+          'data'    => json_encode($data),
+        ));
+    }
+
     if ($this->shouldOnlyCreateDiff()) {
       echo phutil_console_format(
         "Created a new Differential diff:\n".
@@ -840,16 +861,20 @@ EOTEXT
           if (!$continue) {
             throw new ArcanistUserAbortException();
           }
-          $this->unresolvedLint = $lint_workflow->getUnresolvedMessages();
           break;
         case ArcanistLintWorkflow::RESULT_ERRORS:
           echo phutil_console_format(
             "<bg:red>** LINT ERRORS **</bg> Lint raised errors!\n");
-          throw new ArcanistUsageException(
-            "Resolve lint errors or run with --nolint.");
+          $continue = phutil_console_confirm(
+            "Lint issued unresolved errors! Ignore lint errors?");
+          if (!$continue) {
+            throw new ArcanistUserAbortException();
+          }
           break;
       }
 
+      $this->unresolvedLint = $lint_workflow->getUnresolvedMessages();
+
       return $lint_result;
     } catch (ArcanistNoEngineException $ex) {
       echo "No lint engine configured for this project.\n";
@@ -892,11 +917,16 @@ EOTEXT
         case ArcanistUnitWorkflow::RESULT_FAIL:
           echo phutil_console_format(
             "<bg:red>** UNIT ERRORS **</bg> Unit testing raised errors!\n");
-          throw new ArcanistUsageException(
-            "Resolve unit test errors or run with --nounit.");
+          $continue = phutil_console_confirm(
+            "Unit test results include failures! Ignore test failures?");
+          if (!$continue) {
+            throw new ArcanistUserAbortException();
+          }
           break;
       }
 
+      $this->unresolvedTests = $unit_workflow->getUnresolvedTests();
+
       return $unit_result;
     } catch (ArcanistNoEngineException $ex) {
       echo "No unit test engine is configured for this project.\n";
index ceedcad713a107145a81e84cad93950ea929fa65..0424afbfd65f698628d8b2ff8310d4fea21f71c3 100644 (file)
@@ -23,6 +23,8 @@ class ArcanistUnitWorkflow extends ArcanistBaseWorkflow {
   const RESULT_FAIL     = 2;
   const RESULT_SKIP     = 3;
 
+  private $unresolvedTests;
+
   public function getCommandHelp() {
     return phutil_console_format(<<<EOTEXT
       **unit**
@@ -96,13 +98,16 @@ EOTEXT
         ' <bg:yellow>** UNSOUND **</bg>'),
       );
 
+    $unresolved = array();
     foreach ($results as $result) {
       $result_code = $result->getResult();
       echo $status_codes[$result_code].' '.$result->getName()."\n";
       if ($result_code != ArcanistUnitTestResult::RESULT_PASS) {
         echo $result->getUserData()."\n";
+        $unresolved[] = $result;
       }
     }
+    $this->unresolvedTests = $unresolved;
 
     $overall_result = self::RESULT_OKAY;
     foreach ($results as $result) {
@@ -111,13 +116,16 @@ EOTEXT
           $result_code == ArcanistUnitTestResult::RESULT_BROKEN) {
         $overall_result = self::RESULT_FAIL;
         break;
-      }
-      if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
+      } else if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) {
         $overall_result = self::RESULT_UNSOUND;
-        break;
       }
     }
 
     return $overall_result;
   }
+
+  public function getUnresolvedTests() {
+    return $this->unresolvedTests;
+  }
+
 }