mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-25 16:22:42 +01:00
Write tests for ArcanistNoLintLinter
Summary: With a special guest appearance from `ArcanistGeneratedLinter`. Test Plan: `arc unit` Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11345
This commit is contained in:
parent
afc53ed322
commit
272f737110
9 changed files with 65 additions and 10 deletions
|
@ -81,6 +81,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistFlake8LinterTestCase' => 'lint/linter/__tests__/ArcanistFlake8LinterTestCase.php',
|
'ArcanistFlake8LinterTestCase' => 'lint/linter/__tests__/ArcanistFlake8LinterTestCase.php',
|
||||||
'ArcanistFutureLinter' => 'lint/linter/ArcanistFutureLinter.php',
|
'ArcanistFutureLinter' => 'lint/linter/ArcanistFutureLinter.php',
|
||||||
'ArcanistGeneratedLinter' => 'lint/linter/ArcanistGeneratedLinter.php',
|
'ArcanistGeneratedLinter' => 'lint/linter/ArcanistGeneratedLinter.php',
|
||||||
|
'ArcanistGeneratedLinterTestCase' => 'lint/linter/__tests__/ArcanistGeneratedLinterTestCase.php',
|
||||||
'ArcanistGetConfigWorkflow' => 'workflow/ArcanistGetConfigWorkflow.php',
|
'ArcanistGetConfigWorkflow' => 'workflow/ArcanistGetConfigWorkflow.php',
|
||||||
'ArcanistGitAPI' => 'repository/api/ArcanistGitAPI.php',
|
'ArcanistGitAPI' => 'repository/api/ArcanistGitAPI.php',
|
||||||
'ArcanistGitHookPreReceiveWorkflow' => 'workflow/ArcanistGitHookPreReceiveWorkflow.php',
|
'ArcanistGitHookPreReceiveWorkflow' => 'workflow/ArcanistGitHookPreReceiveWorkflow.php',
|
||||||
|
@ -131,7 +132,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php',
|
'ArcanistNoEffectException' => 'exception/usage/ArcanistNoEffectException.php',
|
||||||
'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php',
|
'ArcanistNoEngineException' => 'exception/usage/ArcanistNoEngineException.php',
|
||||||
'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php',
|
'ArcanistNoLintLinter' => 'lint/linter/ArcanistNoLintLinter.php',
|
||||||
'ArcanistNoLintTestCaseMisnamed' => 'lint/linter/__tests__/ArcanistNoLintTestCase.php',
|
'ArcanistNoLintLinterTestCase' => 'lint/linter/__tests__/ArcanistNoLintLinterTestCase.php',
|
||||||
'ArcanistNoneLintRenderer' => 'lint/renderer/ArcanistNoneLintRenderer.php',
|
'ArcanistNoneLintRenderer' => 'lint/renderer/ArcanistNoneLintRenderer.php',
|
||||||
'ArcanistPEP8Linter' => 'lint/linter/ArcanistPEP8Linter.php',
|
'ArcanistPEP8Linter' => 'lint/linter/ArcanistPEP8Linter.php',
|
||||||
'ArcanistPEP8LinterTestCase' => 'lint/linter/__tests__/ArcanistPEP8LinterTestCase.php',
|
'ArcanistPEP8LinterTestCase' => 'lint/linter/__tests__/ArcanistPEP8LinterTestCase.php',
|
||||||
|
@ -278,6 +279,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistFlake8LinterTestCase' => 'ArcanistExternalLinterTestCase',
|
'ArcanistFlake8LinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||||
'ArcanistFutureLinter' => 'ArcanistLinter',
|
'ArcanistFutureLinter' => 'ArcanistLinter',
|
||||||
'ArcanistGeneratedLinter' => 'ArcanistLinter',
|
'ArcanistGeneratedLinter' => 'ArcanistLinter',
|
||||||
|
'ArcanistGeneratedLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistGetConfigWorkflow' => 'ArcanistWorkflow',
|
'ArcanistGetConfigWorkflow' => 'ArcanistWorkflow',
|
||||||
'ArcanistGitAPI' => 'ArcanistRepositoryAPI',
|
'ArcanistGitAPI' => 'ArcanistRepositoryAPI',
|
||||||
'ArcanistGitHookPreReceiveWorkflow' => 'ArcanistWorkflow',
|
'ArcanistGitHookPreReceiveWorkflow' => 'ArcanistWorkflow',
|
||||||
|
@ -317,7 +319,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistNoEffectException' => 'ArcanistUsageException',
|
'ArcanistNoEffectException' => 'ArcanistUsageException',
|
||||||
'ArcanistNoEngineException' => 'ArcanistUsageException',
|
'ArcanistNoEngineException' => 'ArcanistUsageException',
|
||||||
'ArcanistNoLintLinter' => 'ArcanistLinter',
|
'ArcanistNoLintLinter' => 'ArcanistLinter',
|
||||||
'ArcanistNoLintTestCaseMisnamed' => 'ArcanistPhutilTestCase',
|
'ArcanistNoLintLinterTestCase' => 'ArcanistArcanistLinterTestCase',
|
||||||
'ArcanistNoneLintRenderer' => 'ArcanistLintRenderer',
|
'ArcanistNoneLintRenderer' => 'ArcanistLintRenderer',
|
||||||
'ArcanistPEP8Linter' => 'ArcanistExternalLinter',
|
'ArcanistPEP8Linter' => 'ArcanistExternalLinter',
|
||||||
'ArcanistPEP8LinterTestCase' => 'ArcanistExternalLinterTestCase',
|
'ArcanistPEP8LinterTestCase' => 'ArcanistExternalLinterTestCase',
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistGeneratedLinterTestCase
|
||||||
|
extends ArcanistArcanistLinterTestCase {
|
||||||
|
|
||||||
|
public function testLinter() {
|
||||||
|
return $this->executeTestsInDirectory(dirname(__FILE__).'/generated/');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -87,6 +87,7 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
|
||||||
'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',
|
||||||
));
|
));
|
||||||
|
|
||||||
$exception = null;
|
$exception = null;
|
||||||
|
@ -126,8 +127,8 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
|
||||||
$path_name = idx($config, 'path', $path);
|
$path_name = idx($config, 'path', $path);
|
||||||
$linter->addPath($path_name);
|
$linter->addPath($path_name);
|
||||||
$linter->addData($path_name, $data);
|
$linter->addData($path_name, $data);
|
||||||
$config = idx($config, 'config', array());
|
|
||||||
foreach ($config as $key => $value) {
|
foreach (idx($config, 'config', array()) as $key => $value) {
|
||||||
$linter->setLinterConfigurationValue($key, $value);
|
$linter->setLinterConfigurationValue($key, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +142,16 @@ abstract class ArcanistLinterTestCase extends ArcanistPhutilTestCase {
|
||||||
count($results),
|
count($results),
|
||||||
pht('Expect one result returned by linter.'));
|
pht('Expect one result returned by linter.'));
|
||||||
|
|
||||||
|
$assert_stopped = idx($config, 'stopped');
|
||||||
|
if ($assert_stopped !== null) {
|
||||||
|
$this->assertEqual(
|
||||||
|
$assert_stopped,
|
||||||
|
$linter->didStopAllLinters(),
|
||||||
|
$assert_stopped
|
||||||
|
? pht('Expect linter to be stopped.')
|
||||||
|
: pht('Expect linter to not be stopped.'));
|
||||||
|
}
|
||||||
|
|
||||||
$result = reset($results);
|
$result = reset($results);
|
||||||
$patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
|
$patcher = ArcanistLintPatcher::newFromArcanistLintResult($result);
|
||||||
$after_lint = $patcher->getModifiedFileContent();
|
$after_lint = $patcher->getModifiedFileContent();
|
||||||
|
|
10
src/lint/linter/__tests__/ArcanistNoLintLinterTestCase.php
Normal file
10
src/lint/linter/__tests__/ArcanistNoLintLinterTestCase.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistNoLintLinterTestCase
|
||||||
|
extends ArcanistArcanistLinterTestCase {
|
||||||
|
|
||||||
|
public function testLinter() {
|
||||||
|
return $this->executeTestsInDirectory(dirname(__FILE__).'/nolint/');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Not a real test... meant to fail lint if @nolint is not respected.
|
|
||||||
*/
|
|
||||||
final class ArcanistNoLintTestCaseMisnamed extends ArcanistPhutilTestCase {}
|
|
7
src/lint/linter/__tests__/generated/generated.lint-test
Normal file
7
src/lint/linter/__tests__/generated/generated.lint-test
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
@generated
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
{
|
||||||
|
"stopped": true
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
@not-generated
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
{
|
||||||
|
"stopped": false
|
||||||
|
}
|
7
src/lint/linter/__tests__/nolint/lint.lint-test
Normal file
7
src/lint/linter/__tests__/nolint/lint.lint-test
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
@lint
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
{
|
||||||
|
"stopped": false
|
||||||
|
}
|
7
src/lint/linter/__tests__/nolint/nolint.lint-test
Normal file
7
src/lint/linter/__tests__/nolint/nolint.lint-test
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
@nolint
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
~~~~~~~~~~
|
||||||
|
{
|
||||||
|
"stopped": true
|
||||||
|
}
|
Loading…
Reference in a new issue