]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add unit tests for `ArcanistChmodLinter`
authorJoshua Spence <josh@joshuaspence.com>
Wed, 14 Jan 2015 19:58:10 +0000 (06:58 +1100)
committerJoshua Spence <josh@joshuaspence.com>
Wed, 14 Jan 2015 19:58:11 +0000 (06:58 +1100)
Summary: Moar test coverage.

Test Plan: `arc unit`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

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

src/__phutil_library_map__.php
src/lint/linter/ArcanistChmodLinter.php
src/lint/linter/__tests__/ArcanistChmodLinterTestCase.php [new file with mode: 0644]
src/lint/linter/__tests__/ArcanistLinterTestCase.php
src/lint/linter/__tests__/chmod/empty_executable.lint-test [new file with mode: 0644]
src/lint/linter/__tests__/chmod/shebang.lint-test [new file with mode: 0644]

index f75c0a5a55532abd6fddd27b2c04d65b39a5a413..bf304b3772f590314d9e9d798efa33669d3d6766 100644 (file)
@@ -32,6 +32,7 @@ phutil_register_library_map(array(
     'ArcanistCapabilityNotSupportedException' => 'workflow/exception/ArcanistCapabilityNotSupportedException.php',
     'ArcanistCheckstyleXMLLintRenderer' => 'lint/renderer/ArcanistCheckstyleXMLLintRenderer.php',
     'ArcanistChmodLinter' => 'lint/linter/ArcanistChmodLinter.php',
+    'ArcanistChmodLinterTestCase' => 'lint/linter/__tests__/ArcanistChmodLinterTestCase.php',
     'ArcanistCloseRevisionWorkflow' => 'workflow/ArcanistCloseRevisionWorkflow.php',
     'ArcanistCloseWorkflow' => 'workflow/ArcanistCloseWorkflow.php',
     'ArcanistClosureLinter' => 'lint/linter/ArcanistClosureLinter.php',
@@ -239,6 +240,7 @@ phutil_register_library_map(array(
     'ArcanistCapabilityNotSupportedException' => 'Exception',
     'ArcanistCheckstyleXMLLintRenderer' => 'ArcanistLintRenderer',
     'ArcanistChmodLinter' => 'ArcanistLinter',
+    'ArcanistChmodLinterTestCase' => 'ArcanistArcanistLinterTestCase',
     'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
     'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
     'ArcanistClosureLinter' => 'ArcanistExternalLinter',
index 71e8a1be2b8be2d3cfc5b9773eadaa00a1ac72c4..a8825e7256c03eca22fdf33bc3667e3a3c0c94db 100644 (file)
@@ -42,9 +42,11 @@ final class ArcanistChmodLinter extends ArcanistLinter {
   }
 
   public function lintPath($path) {
-    if (is_executable($path)) {
-      if ($this->getEngine()->isBinaryFile($path)) {
-        $mime = Filesystem::getMimeType($path);
+    $engine = $this->getEngine();
+
+    if (is_executable($engine->getFilePathOnDisk($path))) {
+      if ($engine->isBinaryFile($path)) {
+        $mime = Filesystem::getMimeType($engine->getFilePathOnDisk($path));
 
         switch ($mime) {
           // Archives
diff --git a/src/lint/linter/__tests__/ArcanistChmodLinterTestCase.php b/src/lint/linter/__tests__/ArcanistChmodLinterTestCase.php
new file mode 100644 (file)
index 0000000..819c76c
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+final class ArcanistChmodLinterTestCase extends ArcanistArcanistLinterTestCase {
+
+  public function testLinter() {
+    $this->executeTestsInDirectory(dirname(__FILE__).'/chmod/');
+  }
+
+}
index 4de8005c7a0818603dc48e7f5a1005dec163e5d6..68581a7df8c5563cb05f851a3a69542aa51f891f 100644 (file)
@@ -86,6 +86,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
         'hook' => 'optional bool',
         'config' => 'optional map<string, wild>',
         'path' => 'optional string',
+        'mode' => 'optional string',
       ));
 
     $exception = null;
@@ -99,6 +100,11 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
       Filesystem::writeFile($tmp, $data);
       $full_path = (string)$tmp;
 
+      $mode = idx($config, 'mode');
+      if ($mode) {
+        Filesystem::changePermissions($tmp, octdec($mode));
+      }
+
       $dir = dirname($full_path);
       $path = basename($full_path);
 
diff --git a/src/lint/linter/__tests__/chmod/empty_executable.lint-test b/src/lint/linter/__tests__/chmod/empty_executable.lint-test
new file mode 100644 (file)
index 0000000..54e5a85
--- /dev/null
@@ -0,0 +1,5 @@
+~~~~~~~~~~
+warning::
+~~~~~~~~~~
+~~~~~~~~~~
+{"mode": "0755"}
diff --git a/src/lint/linter/__tests__/chmod/shebang.lint-test b/src/lint/linter/__tests__/chmod/shebang.lint-test
new file mode 100644 (file)
index 0000000..2eb8956
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+~~~~~~~~~~
+~~~~~~~~~~
+~~~~~~~~~~
+{"mode": "0755"}