1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-25 08:12:40 +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 {
public function testCSSLintLinter() {
$this->executeTestsInDirectory(
dirname(__FILE__).'/csslint/',
new ArcanistCSSLintLinter());
$this->executeTestsInDirectory(dirname(__FILE__).'/csslint/');
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -5,7 +5,33 @@
*/
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))
->withType('f')
->withSuffix('lint-test')

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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