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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,6 +5,30 @@
*/ */
abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase { 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 * 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. * 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) { ArcanistLinter $linter = null) {
if (!$linter) { if (!$linter) {
// Infer the linter from the class name. This is a little magical, but $linter = $this->getLinter();
// 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();
} }
$files = id(new FileFinder($root)) $files = id(new FileFinder($root))

View file

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

View file

@ -3,4 +3,4 @@
/** /**
* Not a real test... meant to fail lint if @nolint is not respected. * 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 <?php
final class ArcanistPEP8LinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistPEP8LinterTestCase extends ArcanistExternalLinterTestCase {
public function testPEP8Linter() { public function testLinter() {
$this->executeTestsInDirectory(dirname(__FILE__).'/pep8/'); $this->executeTestsInDirectory(dirname(__FILE__).'/pep8/');
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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