]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow tests to be skipped
authorEdward Speyer <edward@fb.com>
Wed, 25 Apr 2012 02:16:45 +0000 (19:16 -0700)
committerEdward Speyer <edward@fb.com>
Wed, 25 Apr 2012 04:45:22 +0000 (21:45 -0700)
Summary:
Allow tests to be skipped by calling assertSkipped().  It's not really
an assertion of anything tangible; more like "assert that we can't
really assert anything right now".

Test Plan: Added a new test to the PhutilUnitTestEngineTestCase.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin
Differential Revision: https://secure.phabricator.com/D2312

src/__phutil_library_map__.php
src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php
src/unit/engine/phutil/testcase/ArcanistPhutilTestCase.php
src/unit/engine/phutil/testcase/exception/ArcanistPhutilTestSkippedException.php [new file with mode: 0644]
src/unit/engine/phutil/testcase/exception/__init__.php

index 930431b7d3abe217c8ac1e8c1647a659851eb4fe..5b9b023942fef854da1300885ad4d61dd0eecf91 100644 (file)
@@ -82,6 +82,7 @@ phutil_register_library_map(array(
     'ArcanistPatchWorkflow' => 'workflow/patch',
     'ArcanistPhutilModuleLinter' => 'lint/linter/phutilmodule',
     'ArcanistPhutilTestCase' => 'unit/engine/phutil/testcase',
+    'ArcanistPhutilTestSkippedException' => 'unit/engine/phutil/testcase/exception',
     'ArcanistPhutilTestTerminatedException' => 'unit/engine/phutil/testcase/exception',
     'ArcanistPyFlakesLinter' => 'lint/linter/pyflakes',
     'ArcanistPyLintLinter' => 'lint/linter/pylint',
index 327230291d3867e4c7d7869282615429f36d64e3..d7efb573a086b9da94f8adb1e6c38433c1064ef2 100644 (file)
@@ -40,7 +40,7 @@ final class PhutilUnitTestEngineTestCase extends ArcanistPhutilTestCase {
 
     self::$allTestsCounter--;
 
-    $actual_test_count = 4;
+    $actual_test_count = 5;
 
     $this->assertEqual(
       $actual_test_count,
@@ -86,6 +86,10 @@ final class PhutilUnitTestEngineTestCase extends ArcanistPhutilTestCase {
     $this->assertFailure('This test is expected to fail.');
   }
 
+  public function testSkip() {
+    $this->assertSkipped('This test is expected to skip.');
+  }
+
   public function testTryTestCases() {
     $this->tryTestCases(
       array(
index a6b1dc019ef989c1af7b474f6cc94a1fdc565c2c..9d46e457b2b7d3fd54b35003541a91e88b8b9b6f 100644 (file)
@@ -109,6 +109,19 @@ abstract class ArcanistPhutilTestCase {
     throw new ArcanistPhutilTestTerminatedException($message);
   }
 
+  /**
+   * End this test by asserting that the test should be skipped for some
+   * reason.
+   *
+   * @param   string  Reason for skipping this test.
+   * @return  void
+   * @task    assert
+   */
+  final protected function assertSkipped($message) {
+    $this->skipTest($message);
+    throw new ArcanistPhutilTestTerminatedException($message);
+  }
+
 
 /* -(  Exception Handling  )------------------------------------------------- */
 
@@ -367,6 +380,26 @@ abstract class ArcanistPhutilTestCase {
   }
 
 
+  /**
+   * Mark the current running test as skipped.
+   *
+   * @param string  Description for why this test was skipped.
+   * @return void
+   * @task internal
+   */
+  final private function skipTest($reason) {
+    $coverage = $this->endCoverage();
+
+    $result = new ArcanistUnitTestResult();
+    $result->setCoverage($coverage);
+    $result->setName($this->runningTest);
+    $result->setResult(ArcanistUnitTestResult::RESULT_SKIP);
+    $result->setDuration(microtime(true) - $this->testStartTime);
+    $result->setUserData($reason);
+    $this->results[] = $result;
+  }
+
+
   /**
    * Execute the tests in this test case. You should not call this directly;
    * use @{class:PhutilUnitTestEngine} to orchestrate test execution.
@@ -411,6 +444,8 @@ abstract class ArcanistPhutilTestCase {
           }
         } catch (ArcanistPhutilTestTerminatedException $ex) {
           // Continue with the next test.
+        } catch (ArcanistPhutilTestSkippedException $ex) {
+          // Continue with the next test.
         } catch (Exception $ex) {
           $ex_class = get_class($ex);
           $ex_message = $ex->getMessage();
diff --git a/src/unit/engine/phutil/testcase/exception/ArcanistPhutilTestSkippedException.php b/src/unit/engine/phutil/testcase/exception/ArcanistPhutilTestSkippedException.php
new file mode 100644 (file)
index 0000000..a9cf91a
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * Copyright 2012 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.
+ */
+
+/**
+ * Thrown to skip test execution.
+ *
+ * @group unitrun
+ */
+final class ArcanistPhutilTestSkippedException extends Exception {}
index d0365cd83f61490f95d5df98be9885618d3b46fd..75ef520e85905b2c994b344b47cf3b239124f320 100644 (file)
@@ -7,4 +7,5 @@
 
 
 
+phutil_require_source('ArcanistPhutilTestSkippedException.php');
 phutil_require_source('ArcanistPhutilTestTerminatedException.php');