From f18130a6aa7a8666be959ce9f6ec4867fb76fdf9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 22 Aug 2013 16:02:41 -0700 Subject: [PATCH] Simplify and demuck some of the linter test cases 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 --- .../ArcanistCpplintLinterTestCase.php | 5 +--- .../ArcanistFlake8LinterTestCase.php | 5 +--- .../__tests__/ArcanistLinterTestCase.php | 30 +++++++++++-------- .../ArcanistPhutilXHPASTLinterTestCase.php | 4 +-- .../__tests__/ArcanistRubyLinterTestCase.php | 5 +--- .../ArcanistSpellingLinterTestCase.php | 5 ++-- .../__tests__/ArcanistTextLinterTestCase.php | 5 +--- .../ArcanistXHPASTLinterTestCase.php | 4 +-- .../ArcanistWorkingCopyIdentity.php | 7 ++++- 9 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/lint/linter/__tests__/ArcanistCpplintLinterTestCase.php b/src/lint/linter/__tests__/ArcanistCpplintLinterTestCase.php index acef3f62..e3de1642 100644 --- a/src/lint/linter/__tests__/ArcanistCpplintLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistCpplintLinterTestCase.php @@ -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()); } } diff --git a/src/lint/linter/__tests__/ArcanistFlake8LinterTestCase.php b/src/lint/linter/__tests__/ArcanistFlake8LinterTestCase.php index d09fd78e..48a0f5c3 100644 --- a/src/lint/linter/__tests__/ArcanistFlake8LinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistFlake8LinterTestCase.php @@ -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()); } } diff --git a/src/lint/linter/__tests__/ArcanistLinterTestCase.php b/src/lint/linter/__tests__/ArcanistLinterTestCase.php index dc0785c4..6679f022 100644 --- a/src/lint/linter/__tests__/ArcanistLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistLinterTestCase.php @@ -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), diff --git a/src/lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php b/src/lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php index 01c9fa45..32e5a4f9 100644 --- a/src/lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistPhutilXHPASTLinterTestCase.php @@ -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); } } diff --git a/src/lint/linter/__tests__/ArcanistRubyLinterTestCase.php b/src/lint/linter/__tests__/ArcanistRubyLinterTestCase.php index a2373003..4056f35d 100644 --- a/src/lint/linter/__tests__/ArcanistRubyLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistRubyLinterTestCase.php @@ -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()); } } diff --git a/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php b/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php index 57045519..a8c26970 100644 --- a/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistSpellingLinterTestCase.php @@ -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() { diff --git a/src/lint/linter/__tests__/ArcanistTextLinterTestCase.php b/src/lint/linter/__tests__/ArcanistTextLinterTestCase.php index da6bc8b1..c9129c6f 100644 --- a/src/lint/linter/__tests__/ArcanistTextLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistTextLinterTestCase.php @@ -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()); } } diff --git a/src/lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php b/src/lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php index 492467c3..6d3c53c6 100644 --- a/src/lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php +++ b/src/lint/linter/__tests__/ArcanistXHPASTLinterTestCase.php @@ -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); } } diff --git a/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php b/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php index 1e21b248..7e731067 100644 --- a/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php +++ b/src/workingcopyidentity/ArcanistWorkingCopyIdentity.php @@ -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); } -- 2.43.0