Changeset View
Changeset View
Standalone View
Standalone View
src/lint/linter/__tests__/ArcanistLinterTestCase.php
| Show All 22 Lines | abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase { | ||||
| public abstract function testLinter(); | 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. | ||||
| */ | */ | ||||
| public function executeTestsInDirectory( | public function executeTestsInDirectory( | ||||
| $root, | $root, | ||||
| ArcanistLinter $linter = null) { | ArcanistLinter $linter = null, $tempFileSuffix = null) { | ||||
| if (!$linter) { | 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) { | ||||
| $this->lintFile($root.$file, $linter); | $this->lintFile($root.$file, $linter, $tempFileSuffix); | ||||
| $test_count++; | $test_count++; | ||||
| } | } | ||||
| $this->assertTrue( | $this->assertTrue( | ||||
| ($test_count > 0), | ($test_count > 0), | ||||
| pht('Expected to find some .lint-test tests in directory %s!', $root)); | pht('Expected to find some .lint-test tests in directory %s!', $root)); | ||||
| } | } | ||||
| private function lintFile($file, ArcanistLinter $linter) { | private function lintFile($file, ArcanistLinter $linter, | ||||
| $tempFileSuffix = null) { | |||||
sectioneight: This might fit better in the $config section below, which is intended to be a flexible JSON… | |||||
| $linter = clone $linter; | $linter = clone $linter; | ||||
| $contents = Filesystem::readFile($file); | $contents = Filesystem::readFile($file); | ||||
| $contents = preg_split('/^~{4,}\n/m', $contents); | $contents = preg_split('/^~{4,}\n/m', $contents); | ||||
| if (count($contents) < 2) { | if (count($contents) < 2) { | ||||
| throw new Exception( | throw new Exception( | ||||
| pht( | pht( | ||||
| "Expected '%s' separating test case and results.", | "Expected '%s' separating test case and results.", | ||||
| Show All 14 Lines | private function lintFile($file, ArcanistLinter $linter, | ||||
| PhutilTypeSpec::checkMap( | PhutilTypeSpec::checkMap( | ||||
| $config, | $config, | ||||
| array( | array( | ||||
| 'hook' => 'optional bool', | 'hook' => 'optional bool', | ||||
| 'config' => 'optional map<string, wild>', | 'config' => 'optional map<string, wild>', | ||||
| 'path' => 'optional string', | 'path' => 'optional string', | ||||
| 'mode' => 'optional string', | 'mode' => 'optional string', | ||||
| 'stopped' => 'optional bool', | 'stopped' => 'optional bool', | ||||
| )); | )); | ||||
Not Done Inline ActionsWe don't want this change... the linter (go vet in this case) should lint whatever path is explicitly passed to it, regardless of the file extension. joshuaspence: We don't want this change... the linter (`go vet` in this case) should lint whatever path is… | |||||
Not Done Inline ActionsUnfortunately it does not work. Go vet expects the file to end with .go $ go tool vet src/lint/linter/__tests__/govet/fmt.lint-test vet: no files checked eMxyzptlk: Unfortunately it does not work. Go vet expects the file to end with `.go`
```
$ go tool vet… | |||||
Not Done Inline ActionsIf that's the case then I don't think that this linter should be upstreamed just yet. I don't like adding this functionality for only one subclass. Furthermore, I find this behavior to be counterintuitive. If my .arclint file says to lint *.txt files with ArcanistGoVetLinter, it would not be obvious why this wouldn't be working. I think that if we did want this functionality then we should add a getSupportedFileExtensions() method to ArcanistLinter. joshuaspence: If that's the case then I don't think that this linter should be upstreamed just yet. I don't… | |||||
Not Done Inline ActionsBlessed Reviewers thoughts on this? eMxyzptlk: #blessed_reviewers thoughts on this? | |||||
| $exception = null; | $exception = null; | ||||
| $after_lint = null; | $after_lint = null; | ||||
| $messages = null; | $messages = null; | ||||
| $exception_message = false; | $exception_message = false; | ||||
| $caught_exception = false; | $caught_exception = false; | ||||
| try { | try { | ||||
| $tmp = new TempFile($basename); | $tmp = new TempFile($basename); | ||||
| if ($tempFileSuffix !== null) { | |||||
| $tmp .= '.'.$tempFileSuffix; | |||||
| } | |||||
| Filesystem::writeFile($tmp, $data); | Filesystem::writeFile($tmp, $data); | ||||
| $full_path = (string)$tmp; | $full_path = (string)$tmp; | ||||
| $mode = idx($config, 'mode'); | $mode = idx($config, 'mode'); | ||||
| if ($mode) { | if ($mode) { | ||||
| Filesystem::changePermissions($tmp, octdec($mode)); | Filesystem::changePermissions($tmp, octdec($mode)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines | |||||
This might fit better in the $config section below, which is intended to be a flexible JSON hash already, and would allow other tests to opt-in on a per-file basis. I'll let the blessed reviewers decide though :)