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
extends ArcanistArcanistLinterTestCase {
public function testCSSLintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/csslint/',
- new ArcanistCSSLintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/csslint/');
}
}
$linter = new ArcanistClosureLinter();
$linter->setFlags(array('--additional_extensions=lint-test'));
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/gjslint/',
- $linter);
+ $this->executeTestsInDirectory(dirname(__FILE__).'/gjslint/', $linter);
}
}
extends ArcanistArcanistLinterTestCase {
public function testCoffeeLintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/coffeelint/',
- new ArcanistCoffeeLintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/coffeelint/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testCommitLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/commit/',
- new ArcanistCommitLinter());
+ return $this->executeTestsInDirectory(dirname(__FILE__).'/commit/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testCppcheckLint() {
- return $this->executeTestsInDirectory(
- dirname(__FILE__).'/cppcheck/',
- new ArcanistCppcheckLinter());
+ return $this->executeTestsInDirectory(dirname(__FILE__).'/cppcheck/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testCpplintLint() {
- return $this->executeTestsInDirectory(
- dirname(__FILE__).'/cpplint/',
- new ArcanistCpplintLinter());
+ return $this->executeTestsInDirectory(dirname(__FILE__).'/cpplint/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testFlake8Lint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/flake8/',
- new ArcanistFlake8Linter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/flake8/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testGoLintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/golint/',
- new ArcanistGoLintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/golint/');
}
}
<?php
final class ArcanistHLintLinterTestCase extends ArcanistArcanistLinterTestCase {
+
public function testHlintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/hlint/',
- new ArcanistHLintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/hlint/');
}
+
}
extends ArcanistArcanistLinterTestCase {
public function testJSHintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/jshint/',
- new ArcanistJSHintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/jshint/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testJSONLintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/jsonlint/',
- new ArcanistJSONLintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/jsonlint/');
}
}
final class ArcanistJSONLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testJSONLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/jsonlint/',
- new ArcanistJSONLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/jsonlint/');
}
}
final class ArcanistJscsLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testJscsLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/jscs/',
- new ArcanistJscsLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/jscs/');
}
}
final class ArcanistLesscLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testLesscLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/lessc/',
- new ArcanistLesscLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/lessc/');
}
}
*/
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')
extends ArcanistArcanistLinterTestCase {
public function testMergeConflictLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/mergeconflict/',
- new ArcanistMergeConflictLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/mergeconflict/');
}
}
final class ArcanistPEP8LinterTestCase extends ArcanistArcanistLinterTestCase {
public function testPEP8Linter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/pep8/',
- new ArcanistPEP8Linter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/pep8/');
}
}
final class ArcanistPhpLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testPHPLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/php/',
- new ArcanistPhpLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/php/');
}
}
final class ArcanistPhpcsLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testPHPCSLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/phpcs/',
- new ArcanistPhpcsLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/phpcs/');
}
}
'deprecated_function' => 'This function is most likely deprecated.',
));
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/phlxhp/',
- $linter);
+ $this->executeTestsInDirectory(dirname(__FILE__).'/phlxhp/', $linter);
}
}
extends ArcanistArcanistLinterTestCase {
public function testPuppetLintLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/puppet-lint/',
- new ArcanistPuppetLintLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/puppet-lint/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testPyflakesLinter() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/pyflakes/',
- new ArcanistPyFlakesLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/pyflakes/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testPyLintLinter() {
- return $this->executeTestsInDirectory(
- dirname(__FILE__).'/pylint/',
- new ArcanistPyLintLinter());
+ return $this->executeTestsInDirectory(dirname(__FILE__).'/pylint/');
}
}
final class ArcanistRubyLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testRubyLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/ruby/',
- new ArcanistRubyLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/ruby/');
}
}
final class ArcanistTextLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testTextLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/text/',
- new ArcanistTextLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/text/');
}
}
extends ArcanistArcanistLinterTestCase {
public function testXHPASTLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/xhpast/',
- new ArcanistXHPASTLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/xhpast/');
}
}
final class ArcanistXMLLinterTestCase extends ArcanistArcanistLinterTestCase {
public function testXMLLint() {
- $this->executeTestsInDirectory(
- dirname(__FILE__).'/xml/',
- new ArcanistXMLLinter());
+ $this->executeTestsInDirectory(dirname(__FILE__).'/xml/');
}
}