]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add unit tests for implicit fallthrough lint rule
authorvrana <jakubv@fb.com>
Sat, 23 Feb 2013 05:12:29 +0000 (21:12 -0800)
committervrana <jakubv@fb.com>
Sat, 23 Feb 2013 17:07:28 +0000 (09:07 -0800)
Summary:
The perf fix actually catches some real problems.
I didn't find anything in libphutil, Arcanist and Phabricator though.

Also bump version.

Also allow configuring the hook.

Test Plan:
Added a test, saw it fail with the old code.
Repeat for hook.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Differential Revision: https://secure.phabricator.com/D5097

src/__phutil_library_map__.php
src/lint/linter/ArcanistXHPASTLinter.php
src/lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php [new file with mode: 0644]
src/lint/linter/__tests__/xhpast/switches.lint-test

index bdc96826a88413761fc92ef3a5084aef15d212bb..546cdac8686f58cb0db585c66628d4174fa37c89 100644 (file)
@@ -149,6 +149,7 @@ phutil_register_library_map(array(
     'ArcanistXHPASTLintNamingHook' => 'lint/linter/xhpast/ArcanistXHPASTLintNamingHook.php',
     'ArcanistXHPASTLintNamingHookTestCase' => 'lint/linter/xhpast/__tests__/ArcanistXHPASTLintNamingHookTestCase.php',
     'ArcanistXHPASTLintSwitchHook' => 'lint/linter/xhpast/ArcanistXHPASTLintSwitchHook.php',
+    'ArcanistXHPASTLintTestSwitchHook' => 'lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php',
     'ArcanistXHPASTLinter' => 'lint/linter/ArcanistXHPASTLinter.php',
     'ArcanistXHPASTLinterTestCase' => 'lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php',
     'ComprehensiveLintEngine' => 'lint/engine/ComprehensiveLintEngine.php',
@@ -275,6 +276,7 @@ phutil_register_library_map(array(
     'ArcanistUserAbortException' => 'ArcanistUsageException',
     'ArcanistWhichWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistXHPASTLintNamingHookTestCase' => 'ArcanistTestCase',
+    'ArcanistXHPASTLintTestSwitchHook' => 'ArcanistXHPASTLintSwitchHook',
     'ArcanistXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
     'ArcanistXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase',
     'ComprehensiveLintEngine' => 'ArcanistLintEngine',
index 886236be7c98120cb98b31ff8c8e79dcac5308da..5501cd1f52e7cc25cbf44459712c9caf73ebd71a 100644 (file)
@@ -157,7 +157,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
   }
 
   public function getCacheVersion() {
-    $version = '3';
+    $version = '4';
     $path = xhpast_get_binary_path();
     if (Filesystem::pathExists($path)) {
       $version .= '-'.md5_file($path);
@@ -480,6 +480,7 @@ final class ArcanistXHPASTLinter extends ArcanistBaseXHPASTLinter {
     $working_copy = $this->getEngine()->getWorkingCopy();
     if ($working_copy) {
       $hook_class = $working_copy->getConfig('lint.xhpast.switchhook');
+      $hook_class = $this->getConfig('switchhook', $hook_class);
       if ($hook_class) {
         $hook_obj = newv($hook_class, array());
         assert_instances_of(array($hook_obj), 'ArcanistXHPASTLintSwitchHook');
diff --git a/src/lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php b/src/lint/linter/__tests__/ArcanistXHPASTLintTestSwitchHook.php
new file mode 100644 (file)
index 0000000..35997eb
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+final class ArcanistXHPASTLintTestSwitchHook
+  extends ArcanistXHPASTLintSwitchHook {
+
+  public function checkSwitchToken(XHPASTToken $token) {
+    if ($token->getTypeName() == 'T_STRING') {
+      switch (strtolower($token->getValue())) {
+        case 'throw_exception':
+          return true;
+      }
+    }
+    return false;
+  }
+
+}
index 0e4aafeded5180cb644dd51896005785b38a7cea..b32d55cd87fbf94e5dfeedc31e28879f8acdf788 100644 (file)
@@ -78,6 +78,10 @@ switch ($x) {
     do {
       break 2;
     } while (true);
+  case 7:
+    /* fallthrough */
+  case 8:
+    throw_exception();
 }
 ~~~~~~~~~~
 warning:41:3
@@ -87,4 +91,7 @@ warning:57:3
 warning:66:3
 disabled:68:7 # PHP 5.3 features
 warning:71:3
-warning:75:3
\ No newline at end of file
+warning:75:3
+~~~~~~~~~~
+~~~~~~~~~~
+{"config":{"switchhook":"ArcanistXHPASTLintTestSwitchHook"}}