1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 14:52:40 +01:00

Create an ArcanistExternalLinterTestCase class

Summary: Creates a new base class for unit testing `ArcanistExternalLinter` subclasses. Specifically, add a test case for verifying that we are correctly parsing the output of `$external_linter --version`.

Test Plan: `arc unit`

Reviewers: chad, #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11197
This commit is contained in:
Joshua Spence 2015-01-05 06:41:59 +11:00
parent f6b3f3c46a
commit da02add6c8
31 changed files with 110 additions and 83 deletions

View file

@ -71,6 +71,7 @@ phutil_register_library_map(array(
'ArcanistEventType' => 'events/constant/ArcanistEventType.php',
'ArcanistExportWorkflow' => 'workflow/ArcanistExportWorkflow.php',
'ArcanistExternalLinter' => 'lint/linter/ArcanistExternalLinter.php',
'ArcanistExternalLinterTestCase' => 'lint/linter/__tests__/ArcanistExternalLinterTestCase.php',
'ArcanistFeatureWorkflow' => 'workflow/ArcanistFeatureWorkflow.php',
'ArcanistFilenameLinter' => 'lint/linter/ArcanistFilenameLinter.php',
'ArcanistFlagWorkflow' => 'workflow/ArcanistFlagWorkflow.php',
@ -230,7 +231,7 @@ phutil_register_library_map(array(
'ArcanistBrowseWorkflow' => 'ArcanistWorkflow',
'ArcanistBundleTestCase' => 'ArcanistTestCase',
'ArcanistCSSLintLinter' => 'ArcanistExternalLinter',
'ArcanistCSSLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistCSSLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCSharpLinter' => 'ArcanistLinter',
'ArcanistCallConduitWorkflow' => 'ArcanistWorkflow',
'ArcanistCapabilityNotSupportedException' => 'Exception',
@ -239,9 +240,9 @@ phutil_register_library_map(array(
'ArcanistCloseRevisionWorkflow' => 'ArcanistWorkflow',
'ArcanistCloseWorkflow' => 'ArcanistWorkflow',
'ArcanistClosureLinter' => 'ArcanistExternalLinter',
'ArcanistClosureLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistClosureLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCoffeeLintLinter' => 'ArcanistExternalLinter',
'ArcanistCoffeeLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistCoffeeLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCommentRemoverTestCase' => 'ArcanistTestCase',
'ArcanistCommitLinter' => 'ArcanistLinter',
'ArcanistCommitLinterTestCase' => 'ArcanistArcanistLinterTestCase',
@ -252,9 +253,9 @@ phutil_register_library_map(array(
'ArcanistConsoleLintRenderer' => 'ArcanistLintRenderer',
'ArcanistCoverWorkflow' => 'ArcanistWorkflow',
'ArcanistCppcheckLinter' => 'ArcanistExternalLinter',
'ArcanistCppcheckLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistCppcheckLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistCpplintLinter' => 'ArcanistExternalLinter',
'ArcanistCpplintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistCpplintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistDiffParserTestCase' => 'ArcanistTestCase',
'ArcanistDiffUtilsTestCase' => 'ArcanistTestCase',
'ArcanistDiffWorkflow' => 'ArcanistWorkflow',
@ -264,37 +265,38 @@ phutil_register_library_map(array(
'ArcanistEventType' => 'PhutilEventType',
'ArcanistExportWorkflow' => 'ArcanistWorkflow',
'ArcanistExternalLinter' => 'ArcanistFutureLinter',
'ArcanistExternalLinterTestCase' => 'ArcanistLinterTestCase',
'ArcanistFeatureWorkflow' => 'ArcanistWorkflow',
'ArcanistFilenameLinter' => 'ArcanistLinter',
'ArcanistFlagWorkflow' => 'ArcanistWorkflow',
'ArcanistFlake8Linter' => 'ArcanistExternalLinter',
'ArcanistFlake8LinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistFlake8LinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistFutureLinter' => 'ArcanistLinter',
'ArcanistGeneratedLinter' => 'ArcanistLinter',
'ArcanistGetConfigWorkflow' => 'ArcanistWorkflow',
'ArcanistGitAPI' => 'ArcanistRepositoryAPI',
'ArcanistGitHookPreReceiveWorkflow' => 'ArcanistWorkflow',
'ArcanistGoLintLinter' => 'ArcanistExternalLinter',
'ArcanistGoLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistGoLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistHLintLinter' => 'ArcanistExternalLinter',
'ArcanistHLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistHLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistHelpWorkflow' => 'ArcanistWorkflow',
'ArcanistHgClientChannel' => 'PhutilProtocolChannel',
'ArcanistHgServerChannel' => 'PhutilProtocolChannel',
'ArcanistInfrastructureTestCase' => 'ArcanistTestCase',
'ArcanistInstallCertificateWorkflow' => 'ArcanistWorkflow',
'ArcanistJSHintLinter' => 'ArcanistExternalLinter',
'ArcanistJSHintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJSHintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistJSONLintLinter' => 'ArcanistExternalLinter',
'ArcanistJSONLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJSONLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistJSONLintRenderer' => 'ArcanistLintRenderer',
'ArcanistJSONLinter' => 'ArcanistLinter',
'ArcanistJSONLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJscsLinter' => 'ArcanistExternalLinter',
'ArcanistJscsLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistJscsLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistLandWorkflow' => 'ArcanistWorkflow',
'ArcanistLesscLinter' => 'ArcanistExternalLinter',
'ArcanistLesscLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistLesscLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistLiberateWorkflow' => 'ArcanistWorkflow',
'ArcanistLintWorkflow' => 'ArcanistWorkflow',
'ArcanistLinterTestCase' => 'ArcanistPhutilTestCase',
@ -307,16 +309,16 @@ phutil_register_library_map(array(
'ArcanistNoEffectException' => 'ArcanistUsageException',
'ArcanistNoEngineException' => 'ArcanistUsageException',
'ArcanistNoLintLinter' => 'ArcanistLinter',
'ArcanistNoLintTestCaseMisnamed' => 'ArcanistLinterTestCase',
'ArcanistNoLintTestCaseMisnamed' => 'ArcanistPhutilTestCase',
'ArcanistNoneLintRenderer' => 'ArcanistLintRenderer',
'ArcanistPEP8Linter' => 'ArcanistExternalLinter',
'ArcanistPEP8LinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPEP8LinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistPasteWorkflow' => 'ArcanistWorkflow',
'ArcanistPatchWorkflow' => 'ArcanistWorkflow',
'ArcanistPhpLinter' => 'ArcanistExternalLinter',
'ArcanistPhpLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPhpLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistPhpcsLinter' => 'ArcanistExternalLinter',
'ArcanistPhpcsLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPhpcsLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistPhrequentWorkflow' => 'ArcanistWorkflow',
'ArcanistPhutilLibraryLinter' => 'ArcanistLinter',
'ArcanistPhutilTestCaseTestCase' => 'ArcanistPhutilTestCase',
@ -325,16 +327,16 @@ phutil_register_library_map(array(
'ArcanistPhutilXHPASTLinter' => 'ArcanistBaseXHPASTLinter',
'ArcanistPhutilXHPASTLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPuppetLintLinter' => 'ArcanistExternalLinter',
'ArcanistPuppetLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPuppetLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistPyFlakesLinter' => 'ArcanistExternalLinter',
'ArcanistPyFlakesLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPyFlakesLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistPyLintLinter' => 'ArcanistLinter',
'ArcanistPyLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistPyLintLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistRepositoryAPIMiscTestCase' => 'ArcanistTestCase',
'ArcanistRepositoryAPIStateTestCase' => 'ArcanistTestCase',
'ArcanistRevertWorkflow' => 'ArcanistWorkflow',
'ArcanistRubyLinter' => 'ArcanistExternalLinter',
'ArcanistRubyLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistRubyLinterTestCase' => 'ArcanistExternalLinterTestCase',
'ArcanistScriptAndRegexLinter' => 'ArcanistLinter',
'ArcanistSetConfigWorkflow' => 'ArcanistWorkflow',
'ArcanistShellCompleteWorkflow' => 'ArcanistWorkflow',

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistCSSLintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testCSSLintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/csslint/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistClosureLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testClosureLinter() {
public function testLinter() {
$linter = new ArcanistClosureLinter();
$linter->setFlags(array('--additional_extensions=lint-test'));

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistCoffeeLintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testCoffeeLintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/coffeelint/');
}

View file

@ -3,7 +3,7 @@
final class ArcanistCommitLinterTestCase
extends ArcanistArcanistLinterTestCase {
public function testCommitLint() {
public function testLinter() {
return $this->executeTestsInDirectory(dirname(__FILE__).'/commit/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistCppcheckLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testCppcheckLint() {
public function testLinter() {
return $this->executeTestsInDirectory(dirname(__FILE__).'/cppcheck/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistCpplintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testCpplintLint() {
public function testLinter() {
return $this->executeTestsInDirectory(dirname(__FILE__).'/cpplint/');
}

View file

@ -0,0 +1,16 @@
<?php
abstract class ArcanistExternalLinterTestCase extends ArcanistLinterTestCase {
public final function testVersion() {
try {
$version = $this->getLinter()->getVersion();
$this->assertTrue(
$version !== false,
pht('Failed to parse version from command.'));
} catch (ArcanistUsageException $ex) {
$this->assertSkipped($ex->getMessage());
}
}
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistFlake8LinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testFlake8Lint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/flake8/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistGoLintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testGoLintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/golint/');
}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistHLintLinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistHLintLinterTestCase extends ArcanistExternalLinterTestCase {
public function testHlintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/hlint/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistJSHintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testJSHintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/jshint/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistJSONLintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testJSONLintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/jsonlint/');
}

View file

@ -2,7 +2,7 @@
final class ArcanistJSONLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testJSONLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/jsonlint/');
}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistJscsLinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistJscsLinterTestCase extends ArcanistExternalLinterTestCase {
public function testJscsLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/jscs/');
}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistLesscLinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistLesscLinterTestCase extends ArcanistExternalLinterTestCase {
public function testLesscLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/lessc/');
}

View file

@ -5,6 +5,30 @@
*/
abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
/**
* Returns an instance of the linter being tested.
*
* @return ArcanistLinter
*/
protected final function getLinter() {
$matches = array();
if (!preg_match('/^(\w+Linter)TestCase$/', get_class($this), $matches)) {
throw new Exception(pht('Unable to infer linter class name.'));
}
$linter = id(new ReflectionClass($matches[1]))
->newInstanceWithoutConstructor();
if (!$linter instanceof ArcanistLinter) {
throw new Exception(pht('Unable to infer linter class name.'));
}
return $linter;
}
public abstract function testLinter();
/**
* Executes all tests from the specified subdirectory. If a linter is not
* explicitly specified, it will be inferred from the name of the test class.
@ -14,22 +38,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
ArcanistLinter $linter = null) {
if (!$linter) {
// Infer the linter from the class name. This is a little magical, but
// reduces the amount of boiler plate code.
$count = 0;
$linter_name = preg_replace(
'/^(\w+Linter)TestCase$/',
'$1',
get_class($this),
1,
$count);
if (!$count) {
throw new Exception(pht('Unable to infer linter class name.'));
}
$linter = id(new ReflectionClass($linter_name))
->newInstanceWithoutConstructor();
$linter = $this->getLinter();
}
$files = id(new FileFinder($root))

View file

@ -3,7 +3,7 @@
final class ArcanistMergeConflictLinterTestCase
extends ArcanistArcanistLinterTestCase {
public function testMergeConflictLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/mergeconflict/');
}

View file

@ -3,4 +3,4 @@
/**
* Not a real test... meant to fail lint if @nolint is not respected.
*/
final class ArcanistNoLintTestCaseMisnamed extends ArcanistLinterTestCase {}
final class ArcanistNoLintTestCaseMisnamed extends ArcanistPhutilTestCase {}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistPEP8LinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistPEP8LinterTestCase extends ArcanistExternalLinterTestCase {
public function testPEP8Linter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/pep8/');
}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistPhpLinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistPhpLinterTestCase extends ArcanistExternalLinterTestCase {
public function testPHPLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/php/');
}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistPhpcsLinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistPhpcsLinterTestCase extends ArcanistExternalLinterTestCase {
public function testPHPCSLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/phpcs/');
}

View file

@ -3,7 +3,7 @@
final class ArcanistPhutilXHPASTLinterTestCase
extends ArcanistArcanistLinterTestCase {
public function testPhutilXHPASTLint() {
public function testLinter() {
$linter = new ArcanistPhutilXHPASTLinter();
$linter->setDeprecatedFunctions(array(
'deprecated_function' => 'This function is most likely deprecated.',

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistPuppetLintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testPuppetLintLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/puppet-lint/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistPyFlakesLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testPyflakesLinter() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/pyflakes/');
}

View file

@ -1,9 +1,9 @@
<?php
final class ArcanistPyLintLinterTestCase
extends ArcanistArcanistLinterTestCase {
extends ArcanistExternalLinterTestCase {
public function testPyLintLinter() {
public function testLinter() {
return $this->executeTestsInDirectory(dirname(__FILE__).'/pylint/');
}

View file

@ -1,8 +1,8 @@
<?php
final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase {
final class ArcanistRubyLinterTestCase extends ArcanistExternalLinterTestCase {
public function testRubyLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/ruby/');
}

View file

@ -3,7 +3,7 @@
final class ArcanistSpellingLinterTestCase
extends ArcanistArcanistLinterTestCase {
public function testSpellingLint() {
public function testLinter() {
$linter = new ArcanistSpellingLinter();
$linter->addPartialWordRule('supermn', 'superman');
$linter->addExactWordRule('batmn', 'batman');

View file

@ -2,7 +2,7 @@
final class ArcanistTextLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testTextLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/text/');
}

View file

@ -3,7 +3,7 @@
final class ArcanistXHPASTLinterTestCase
extends ArcanistArcanistLinterTestCase {
public function testXHPASTLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/xhpast/');
}

View file

@ -6,7 +6,7 @@
*/
final class ArcanistXMLLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testXMLLint() {
public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/xml/');
}