1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 16:22:42 +01:00

Reduce boilerplate code in ArcanistLinterTestCase subclasses

Summary: This is a bit magical and is maybe a terrible idea, but it seems okayish.

Test Plan: `arc unit`

Reviewers: chad, #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D11172
This commit is contained in:
Joshua Spence 2015-01-04 18:38:32 +11:00
parent a10002adec
commit f5db41917b
27 changed files with 55 additions and 79 deletions

View file

@ -4,9 +4,7 @@ final class ArcanistCSSLintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testCSSLintLinter() { public function testCSSLintLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/csslint/');
dirname(__FILE__).'/csslint/',
new ArcanistCSSLintLinter());
} }
} }

View file

@ -7,9 +7,7 @@ final class ArcanistClosureLinterTestCase
$linter = new ArcanistClosureLinter(); $linter = new ArcanistClosureLinter();
$linter->setFlags(array('--additional_extensions=lint-test')); $linter->setFlags(array('--additional_extensions=lint-test'));
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/gjslint/', $linter);
dirname(__FILE__).'/gjslint/',
$linter);
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistCoffeeLintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testCoffeeLintLinter() { public function testCoffeeLintLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/coffeelint/');
dirname(__FILE__).'/coffeelint/',
new ArcanistCoffeeLintLinter());
} }
} }

View file

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

View file

@ -4,9 +4,7 @@ final class ArcanistCppcheckLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testCppcheckLint() { public function testCppcheckLint() {
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(dirname(__FILE__).'/cppcheck/');
dirname(__FILE__).'/cppcheck/',
new ArcanistCppcheckLinter());
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistCpplintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testCpplintLint() { public function testCpplintLint() {
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(dirname(__FILE__).'/cpplint/');
dirname(__FILE__).'/cpplint/',
new ArcanistCpplintLinter());
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistFlake8LinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testFlake8Lint() { public function testFlake8Lint() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/flake8/');
dirname(__FILE__).'/flake8/',
new ArcanistFlake8Linter());
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistGoLintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testGoLintLinter() { public function testGoLintLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/golint/');
dirname(__FILE__).'/golint/',
new ArcanistGoLintLinter());
} }
} }

View file

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

View file

@ -4,9 +4,7 @@ final class ArcanistJSHintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testJSHintLinter() { public function testJSHintLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/jshint/');
dirname(__FILE__).'/jshint/',
new ArcanistJSHintLinter());
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistJSONLintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testJSONLintLinter() { public function testJSONLintLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/jsonlint/');
dirname(__FILE__).'/jsonlint/',
new ArcanistJSONLintLinter());
} }
} }

View file

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

View file

@ -3,9 +3,7 @@
final class ArcanistJscsLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistJscsLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testJscsLinter() { public function testJscsLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/jscs/');
dirname(__FILE__).'/jscs/',
new ArcanistJscsLinter());
} }
} }

View file

@ -3,9 +3,7 @@
final class ArcanistLesscLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistLesscLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testLesscLinter() { public function testLesscLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/lessc/');
dirname(__FILE__).'/lessc/',
new ArcanistLesscLinter());
} }
} }

View file

@ -5,7 +5,33 @@
*/ */
abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase { abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
public function executeTestsInDirectory($root, ArcanistLinter $linter) { /**
* 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.
*/
public function executeTestsInDirectory(
$root,
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();
}
$files = id(new FileFinder($root)) $files = id(new FileFinder($root))
->withType('f') ->withType('f')
->withSuffix('lint-test') ->withSuffix('lint-test')

View file

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

View file

@ -3,9 +3,7 @@
final class ArcanistPEP8LinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistPEP8LinterTestCase extends ArcanistArcanistLinterTestCase {
public function testPEP8Linter() { public function testPEP8Linter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/pep8/');
dirname(__FILE__).'/pep8/',
new ArcanistPEP8Linter());
} }
} }

View file

@ -3,9 +3,7 @@
final class ArcanistPhpLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistPhpLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testPHPLint() { public function testPHPLint() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/php/');
dirname(__FILE__).'/php/',
new ArcanistPhpLinter());
} }
} }

View file

@ -3,9 +3,7 @@
final class ArcanistPhpcsLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistPhpcsLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testPHPCSLint() { public function testPHPCSLint() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/phpcs/');
dirname(__FILE__).'/phpcs/',
new ArcanistPhpcsLinter());
} }
} }

View file

@ -9,9 +9,7 @@ final class ArcanistPhutilXHPASTLinterTestCase
'deprecated_function' => 'This function is most likely deprecated.', 'deprecated_function' => 'This function is most likely deprecated.',
)); ));
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/phlxhp/', $linter);
dirname(__FILE__).'/phlxhp/',
$linter);
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistPuppetLintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testPuppetLintLinter() { public function testPuppetLintLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/puppet-lint/');
dirname(__FILE__).'/puppet-lint/',
new ArcanistPuppetLintLinter());
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistPyFlakesLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testPyflakesLinter() { public function testPyflakesLinter() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/pyflakes/');
dirname(__FILE__).'/pyflakes/',
new ArcanistPyFlakesLinter());
} }
} }

View file

@ -4,9 +4,7 @@ final class ArcanistPyLintLinterTestCase
extends ArcanistArcanistLinterTestCase { extends ArcanistArcanistLinterTestCase {
public function testPyLintLinter() { public function testPyLintLinter() {
return $this->executeTestsInDirectory( return $this->executeTestsInDirectory(dirname(__FILE__).'/pylint/');
dirname(__FILE__).'/pylint/',
new ArcanistPyLintLinter());
} }
} }

View file

@ -3,9 +3,7 @@
final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase { final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testRubyLint() { public function testRubyLint() {
$this->executeTestsInDirectory( $this->executeTestsInDirectory(dirname(__FILE__).'/ruby/');
dirname(__FILE__).'/ruby/',
new ArcanistRubyLinter());
} }
} }

View file

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

View file

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

View file

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