From: Joshua Spence Date: Wed, 14 Jan 2015 19:58:10 +0000 (+1100) Subject: Add unit tests for `ArcanistChmodLinter` X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=afc53ed32211df462c4e16adbf93009e82b5dfcc;p=arcanist.git Add unit tests for `ArcanistChmodLinter` 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 --- diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index f75c0a5a..bf304b37 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/lint/linter/ArcanistChmodLinter.php b/src/lint/linter/ArcanistChmodLinter.php index 71e8a1be..a8825e72 100644 --- a/src/lint/linter/ArcanistChmodLinter.php +++ b/src/lint/linter/ArcanistChmodLinter.php @@ -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 index 00000000..819c76c7 --- /dev/null +++ b/src/lint/linter/__tests__/ArcanistChmodLinterTestCase.php @@ -0,0 +1,9 @@ +executeTestsInDirectory(dirname(__FILE__).'/chmod/'); + } + +} diff --git a/src/lint/linter/__tests__/ArcanistLinterTestCase.php b/src/lint/linter/__tests__/ArcanistLinterTestCase.php index 4de8005c..68581a7d 100644 --- a/src/lint/linter/__tests__/ArcanistLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistLinterTestCase.php @@ -86,6 +86,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase { 'hook' => 'optional bool', 'config' => 'optional map', '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 index 00000000..54e5a85c --- /dev/null +++ b/src/lint/linter/__tests__/chmod/empty_executable.lint-test @@ -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 index 00000000..2eb89565 --- /dev/null +++ b/src/lint/linter/__tests__/chmod/shebang.lint-test @@ -0,0 +1,5 @@ +#!/bin/bash +~~~~~~~~~~ +~~~~~~~~~~ +~~~~~~~~~~ +{"mode": "0755"}