]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Simplify and demuck some of the linter test cases
authorepriestley <git@epriestley.com>
Thu, 22 Aug 2013 23:02:41 +0000 (16:02 -0700)
committerepriestley <git@epriestley.com>
Thu, 22 Aug 2013 23:02:41 +0000 (16:02 -0700)
Summary:
Ref T3186.

  - Every linter builds a WorkingCopyIdentity in the same way, with no specialized data. Don't do that.
  - Linters get passed a goofy hardcoded ".php" path. Don't do that.
  - Linters generally run on an imaginary path, which might not work. Just give them a real path by building a tiny working copy in `/tmp`.
  - Fix a TODO now that we have better typechecking.

Test Plan: `arc unit --everything`, intentionally broke a test to make sure that still works.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran
Maniphest Tasks: T3186

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

src/lint/linter/__tests__/ArcanistCpplintLinterTestCase.php
src/lint/linter/__tests__/ArcanistFlake8LinterTestCase.php
src/lint/linter/__tests__/ArcanistLinterTestCase.php
src/lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php
src/lint/linter/__tests__/ArcanistRubyLinterTestCase.php
src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php
src/lint/linter/__tests__/ArcanistTextLinterTestCase.php
src/lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php
src/workingcopyidentity/ArcanistWorkingCopyIdentity.php

index acef3f62080ec86008350cefdefe4c69cde1a1ff..e3de16424e93ae2daa16593578c0d28cfac65488 100644 (file)
@@ -8,12 +8,9 @@ final class ArcanistCpplintLinterTestCase
   extends ArcanistArcanistLinterTestCase {
 
   public function testCpplintLint() {
-    $linter = new ArcanistCpplintLinter();
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/cpp/',
-      $linter,
-      $working_copy);
+      new ArcanistCpplintLinter());
   }
 
 }
index d09fd78eb53fc3db589d222ace412492a8953e36..48a0f5c3044008f7ea8b306fbcba2eb1787b1ef9 100644 (file)
@@ -8,12 +8,9 @@ final class ArcanistFlake8LinterTestCase
   extends ArcanistArcanistLinterTestCase {
 
   public function testFlake8Lint() {
-    $linter = new ArcanistFlake8Linter();
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/python/',
-      $linter,
-      $working_copy);
+      new ArcanistFlake8Linter());
   }
 
 }
index dc0785c4c0918daf0fd54f71b9ce99ebef1ebe9a..6679f022436d8aa2bbc0ac58b1948d4a386a38a7 100644 (file)
@@ -7,13 +7,13 @@
  */
 abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
 
-  public function executeTestsInDirectory($root, $linter, $working_copy) {
+  public function executeTestsInDirectory($root, ArcanistLinter $linter) {
     foreach (Filesystem::listDirectory($root, $hidden = false) as $file) {
-      $this->lintFile($root.$file, $linter, $working_copy);
+      $this->lintFile($root.$file, $linter);
     }
   }
 
-  private function lintFile($file, $linter, $working_copy) {
+  private function lintFile($file, $linter) {
     $linter = clone $linter;
 
     $contents = Filesystem::readFile($file);
@@ -39,17 +39,13 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
       $config = array();
     }
 
-    /* TODO: ?
-    validate_parameter_list(
+    PhutilTypeSpec::checkMap(
       $config,
       array(
-      ),
-      array(
-        'project' => true,
-        'path' => true,
-        'hook' => true,
+        'project' => 'optional string',
+        'hook' => 'optional bool',
+        'config' => 'optional wild',
       ));
-    */
 
     $exception = null;
     $after_lint = null;
@@ -58,7 +54,16 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
     $caught_exception = false;
     try {
 
-      $path = idx($config, 'path', 'lint/'.$basename.'.php');
+      $tmp = new TempFile($basename);
+      Filesystem::writeFile($tmp, $data);
+      $full_path = (string)$tmp;
+
+      $dir = dirname($full_path);
+      $path = basename($full_path);
+      $working_copy = ArcanistWorkingCopyIdentity::newFromRootAndConfigFile(
+        $dir,
+        null,
+        'Unit Test');
 
       $engine = new UnitTestableArcanistLintEngine();
       $engine->setWorkingCopy($working_copy);
@@ -74,6 +79,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
       $engine->addFileData($path, $data);
 
       $results = $engine->run();
+
       $this->assertEqual(
         1,
         count($results),
index 01c9fa459efaca22fa6efbebcc520f70fb5250c7..32e5a4f91e0c7dfbf9eca7b7654868df9c491e8f 100644 (file)
@@ -13,11 +13,9 @@ final class ArcanistPhutilXHPASTLinterTestCase
       'deprecated_function' => 'This function is most likely deprecated.',
     ));
 
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/phlxhp/',
-      $linter,
-      $working_copy);
+      $linter);
   }
 
 }
index a2373003b2fd2ff795fdf4b5f97bc3c28f2ba82b..4056f35d906a35016e46a3411999c82c30334d1e 100644 (file)
@@ -8,12 +8,9 @@
 final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase {
 
   public function testRubyLint() {
-    $linter = new ArcanistRubyLinter();
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/ruby/',
-      $linter,
-      $working_copy);
+      new ArcanistRubyLinter());
   }
 
 }
index 5704551998163217cd263d5e8abfd0fbd447bbda..a8c26970bcceacf5ea53c36e8174f7d81687b686 100644 (file)
@@ -13,11 +13,10 @@ final class ArcanistSpellingLinterTestCase
     $linter->removeLintRule('acc'.'out');
     $linter->addPartialWordRule('supermn', 'superman');
     $linter->addWholeWordRule('batmn', 'batman');
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
+
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/spelling/',
-      $linter,
-      $working_copy);
+      $linter);
   }
 
   public function testFixLetterCase() {
index da6bc8b1d66613340ee7fde760961fa3b33f6d4b..c9129c6fd14d60e7f2cab9164bd61869ec06c158 100644 (file)
@@ -8,12 +8,9 @@
 final class ArcanistTextLinterTestCase extends ArcanistArcanistLinterTestCase {
 
   public function testTextLint() {
-    $linter = new ArcanistTextLinter();
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/text/',
-      $linter,
-      $working_copy);
+      new ArcanistTextLinter());
   }
 
 }
index 492467c3dbb2b80b52c491c9e11b9869fd62ac2a..6d3c53c63a7442f3b2b8aa5ee9c8d0f56d14b4b6 100644 (file)
@@ -17,11 +17,9 @@ final class ArcanistXHPASTLinterTestCase
           => ArcanistLintSeverity::SEVERITY_WARNING,
       ));
 
-    $working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
     return $this->executeTestsInDirectory(
       dirname(__FILE__).'/xhpast/',
-      $linter,
-      $working_copy);
+      $linter);
   }
 
 }
index 1e21b2489474f99050c9787ab0466e2a0d39ff3f..7e73106708e85d965f60b6f0a2ee439f89e8f35e 100644 (file)
@@ -58,7 +58,12 @@ final class ArcanistWorkingCopyIdentity {
     $config_raw,
     $from_where) {
 
-    $config = self::parseRawConfigFile($config_raw, $from_where);
+    if ($config_raw === null) {
+      $config = array();
+    } else {
+      $config = self::parseRawConfigFile($config_raw, $from_where);
+    }
+
     return new ArcanistWorkingCopyIdentity($root, $config);
   }