1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 08:42:40 +01:00

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
This commit is contained in:
epriestley 2013-08-22 16:02:41 -07:00
parent 97ad54ed00
commit f18130a6aa
9 changed files with 32 additions and 38 deletions

View file

@ -8,12 +8,9 @@ final class ArcanistCpplintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testCpplintLint() { public function testCpplintLint() {
$linter = new ArcanistCpplintLinter();
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/cpp/', dirname(__FILE__).'/cpp/',
$linter, new ArcanistCpplintLinter());
$working_copy);
} }
} }

View file

@ -8,12 +8,9 @@ final class ArcanistFlake8LinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testFlake8Lint() { public function testFlake8Lint() {
$linter = new ArcanistFlake8Linter();
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/python/', dirname(__FILE__).'/python/',
$linter, new ArcanistFlake8Linter());
$working_copy);
} }
} }

View file

@ -7,13 +7,13 @@
*/ */
abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase { 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) { 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; $linter = clone $linter;
$contents = Filesystem::readFile($file); $contents = Filesystem::readFile($file);
@ -39,17 +39,13 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
$config = array(); $config = array();
} }
/* TODO: ? PhutilTypeSpec::checkMap(
validate_parameter_list(
$config, $config,
array( array(
), 'project' => 'optional string',
array( 'hook' => 'optional bool',
'project' => true, 'config' => 'optional wild',
'path' => true,
'hook' => true,
)); ));
*/
$exception = null; $exception = null;
$after_lint = null; $after_lint = null;
@ -58,7 +54,16 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
$caught_exception = false; $caught_exception = false;
try { 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 = new UnitTestableArcanistLintEngine();
$engine->setWorkingCopy($working_copy); $engine->setWorkingCopy($working_copy);
@ -74,6 +79,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
$engine->addFileData($path, $data); $engine->addFileData($path, $data);
$results = $engine->run(); $results = $engine->run();
$this->assertEqual( $this->assertEqual(
1, 1,
count($results), count($results),

View file

@ -13,11 +13,9 @@ final class ArcanistPhutilXHPASTLinterTestCase
'deprecated_function' => 'This function is most likely deprecated.', 'deprecated_function' => 'This function is most likely deprecated.',
)); ));
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/phlxhp/', dirname(__FILE__).'/phlxhp/',
$linter, $linter);
$working_copy);
} }
} }

View file

@ -8,12 +8,9 @@
final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testRubyLint() { public function testRubyLint() {
$linter = new ArcanistRubyLinter();
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/ruby/', dirname(__FILE__).'/ruby/',
$linter, new ArcanistRubyLinter());
$working_copy);
} }
} }

View file

@ -13,11 +13,10 @@ final class ArcanistSpellingLinterTestCase
$linter->removeLintRule('acc'.'out'); $linter->removeLintRule('acc'.'out');
$linter->addPartialWordRule('supermn', 'superman'); $linter->addPartialWordRule('supermn', 'superman');
$linter->addWholeWordRule('batmn', 'batman'); $linter->addWholeWordRule('batmn', 'batman');
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/spelling/', dirname(__FILE__).'/spelling/',
$linter, $linter);
$working_copy);
} }
public function testFixLetterCase() { public function testFixLetterCase() {

View file

@ -8,12 +8,9 @@
final class ArcanistTextLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistTextLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testTextLint() { public function testTextLint() {
$linter = new ArcanistTextLinter();
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/text/', dirname(__FILE__).'/text/',
$linter, new ArcanistTextLinter());
$working_copy);
} }
} }

View file

@ -17,11 +17,9 @@ final class ArcanistXHPASTLinterTestCase
=> ArcanistLintSeverity::SEVERITY_WARNING, => ArcanistLintSeverity::SEVERITY_WARNING,
)); ));
$working_copy = ArcanistWorkingCopyIdentity::newFromPath(__FILE__);
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(
dirname(__FILE__).'/xhpast/', dirname(__FILE__).'/xhpast/',
$linter, $linter);
$working_copy);
} }
} }

View file

@ -58,7 +58,12 @@ final class ArcanistWorkingCopyIdentity {
$config_raw, $config_raw,
$from_where) { $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); return new ArcanistWorkingCopyIdentity($root, $config);
} }