mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-26 00:32:41 +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:
parent
97ad54ed00
commit
f18130a6aa
9 changed files with 32 additions and 38 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue