Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/__tests__/ArcanistLinterTestCase.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Facilitates implementation of test cases for @{class:ArcanistLinter}s. | * Facilitates implementation of test cases for @{class:ArcanistLinter}s. | ||||
| */ | */ | ||||
| abstract class ArcanistLinterTestCase extends PhutilTestCase { | abstract class ArcanistLinterTestCase extends PhutilTestCase { | ||||
| /** | /** | ||||
| * Returns an instance of the linter being tested. | * Returns an instance of the linter being tested. | ||||
| * | * | ||||
| * @return ArcanistLinter | * @return ArcanistLinter | ||||
| */ | */ | ||||
| final protected function getLinter() { | protected function getLinter() { | ||||
| $matches = null; | $matches = null; | ||||
| if (!preg_match('/^(\w+Linter)TestCase$/', get_class($this), $matches) || | if (!preg_match('/^(\w+Linter)TestCase$/', get_class($this), $matches) || | ||||
| !is_subclass_of($matches[1], 'ArcanistLinter')) { | !is_subclass_of($matches[1], 'ArcanistLinter')) { | ||||
| throw new Exception(pht('Unable to infer linter class name.')); | throw new Exception(pht('Unable to infer linter class name.')); | ||||
| } | } | ||||
| return newv($matches[1], array()); | return newv($matches[1], array()); | ||||
| } | } | ||||
| abstract public function testLinter(); | abstract public 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. | ||||
| */ | */ | ||||
| public function executeTestsInDirectory( | protected function executeTestsInDirectory($root) { | ||||
| $root, | |||||
| ArcanistLinter $linter = null) { | |||||
| if (!$linter) { | |||||
| $linter = $this->getLinter(); | $linter = $this->getLinter(); | ||||
| } | |||||
| $files = id(new FileFinder($root)) | $files = id(new FileFinder($root)) | ||||
| ->withType('f') | ->withType('f') | ||||
| ->withSuffix('lint-test') | ->withSuffix('lint-test') | ||||
| ->find(); | ->find(); | ||||
| $test_count = 0; | $test_count = 0; | ||||
| foreach ($files as $file) { | foreach ($files as $file) { | ||||
| ▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines | |||||