mirror of
https://we.phorge.it/source/arcanist.git
synced 2025-01-25 14:08:18 +01:00
Add basic test coverage for lint console rendering
Summary: Ref T9846. The algorithm here is fairly invovled, so lay down some test coverage before breaking it. Test Plan: Ran tests. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9846 Differential Revision: https://secure.phabricator.com/D18508
This commit is contained in:
parent
5eda40337b
commit
ab0d81bca2
6 changed files with 113 additions and 0 deletions
|
@ -87,6 +87,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistConfigurationDrivenUnitTestEngine' => 'unit/engine/ArcanistConfigurationDrivenUnitTestEngine.php',
|
'ArcanistConfigurationDrivenUnitTestEngine' => 'unit/engine/ArcanistConfigurationDrivenUnitTestEngine.php',
|
||||||
'ArcanistConfigurationManager' => 'configuration/ArcanistConfigurationManager.php',
|
'ArcanistConfigurationManager' => 'configuration/ArcanistConfigurationManager.php',
|
||||||
'ArcanistConsoleLintRenderer' => 'lint/renderer/ArcanistConsoleLintRenderer.php',
|
'ArcanistConsoleLintRenderer' => 'lint/renderer/ArcanistConsoleLintRenderer.php',
|
||||||
|
'ArcanistConsoleLintRendererTestCase' => 'lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php',
|
||||||
'ArcanistConstructorParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php',
|
'ArcanistConstructorParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php',
|
||||||
'ArcanistConstructorParenthesesXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistConstructorParenthesesXHPASTLinterRuleTestCase.php',
|
'ArcanistConstructorParenthesesXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistConstructorParenthesesXHPASTLinterRuleTestCase.php',
|
||||||
'ArcanistControlStatementSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistControlStatementSpacingXHPASTLinterRule.php',
|
'ArcanistControlStatementSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistControlStatementSpacingXHPASTLinterRule.php',
|
||||||
|
@ -502,6 +503,7 @@ phutil_register_library_map(array(
|
||||||
'ArcanistConfigurationDrivenUnitTestEngine' => 'ArcanistUnitTestEngine',
|
'ArcanistConfigurationDrivenUnitTestEngine' => 'ArcanistUnitTestEngine',
|
||||||
'ArcanistConfigurationManager' => 'Phobject',
|
'ArcanistConfigurationManager' => 'Phobject',
|
||||||
'ArcanistConsoleLintRenderer' => 'ArcanistLintRenderer',
|
'ArcanistConsoleLintRenderer' => 'ArcanistLintRenderer',
|
||||||
|
'ArcanistConsoleLintRendererTestCase' => 'PhutilTestCase',
|
||||||
'ArcanistConstructorParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistConstructorParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
'ArcanistConstructorParenthesesXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
'ArcanistConstructorParenthesesXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
|
||||||
'ArcanistControlStatementSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
'ArcanistControlStatementSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class ArcanistConsoleLintRendererTestCase
|
||||||
|
extends PhutilTestCase {
|
||||||
|
|
||||||
|
public function testRendering() {
|
||||||
|
$map = array(
|
||||||
|
'simple' => array(
|
||||||
|
'line' => 1,
|
||||||
|
'char' => 1,
|
||||||
|
'original' => 'a',
|
||||||
|
'replacement' => 'z',
|
||||||
|
),
|
||||||
|
'inline' => array(
|
||||||
|
'line' => 1,
|
||||||
|
'char' => 7,
|
||||||
|
'original' => 'cat',
|
||||||
|
'replacement' => 'dog',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
$defaults = array(
|
||||||
|
'severity' => ArcanistLintSeverity::SEVERITY_WARNING,
|
||||||
|
'name' => 'Lint Warning',
|
||||||
|
'path' => 'path/to/example.c',
|
||||||
|
'description' => 'Consider this.',
|
||||||
|
'code' => 'WARN123',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($map as $key => $test_case) {
|
||||||
|
$data = $this->readTestData("{$key}.txt");
|
||||||
|
$expect = $this->readTestData("{$key}.expect");
|
||||||
|
|
||||||
|
$test_case = $test_case + $defaults;
|
||||||
|
|
||||||
|
$path = $test_case['path'];
|
||||||
|
$severity = $test_case['severity'];
|
||||||
|
$name = $test_case['name'];
|
||||||
|
$description = $test_case['description'];
|
||||||
|
$code = $test_case['code'];
|
||||||
|
|
||||||
|
$line = $test_case['line'];
|
||||||
|
$char = $test_case['char'];
|
||||||
|
|
||||||
|
$original = idx($test_case, 'original');
|
||||||
|
$replacement = idx($test_case, 'replacement');
|
||||||
|
|
||||||
|
$message = id(new ArcanistLintMessage())
|
||||||
|
->setPath($path)
|
||||||
|
->setSeverity($severity)
|
||||||
|
->setName($name)
|
||||||
|
->setDescription($description)
|
||||||
|
->setCode($code)
|
||||||
|
->setLine($line)
|
||||||
|
->setChar($char)
|
||||||
|
->setOriginalText($original)
|
||||||
|
->setReplacementText($replacement);
|
||||||
|
|
||||||
|
$result = id(new ArcanistLintResult())
|
||||||
|
->setPath($path)
|
||||||
|
->setData($data)
|
||||||
|
->addMessage($message);
|
||||||
|
|
||||||
|
$renderer = new ArcanistConsoleLintRenderer();
|
||||||
|
|
||||||
|
try {
|
||||||
|
PhutilConsoleFormatter::disableANSI(true);
|
||||||
|
$actual = $renderer->renderLintResult($result);
|
||||||
|
PhutilConsoleFormatter::disableANSI(false);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
PhutilConsoleFormatter::disableANSI(false);
|
||||||
|
throw $ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEqual(
|
||||||
|
$expect,
|
||||||
|
$actual,
|
||||||
|
pht(
|
||||||
|
'Lint rendering for "%s".',
|
||||||
|
$key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function readTestData($filename) {
|
||||||
|
$path = dirname(__FILE__).'/data/'.$filename;
|
||||||
|
return Filesystem::readFile($path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
8
src/lint/renderer/__tests__/data/inline.expect
Normal file
8
src/lint/renderer/__tests__/data/inline.expect
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
>>> Lint for path/to/example.c:
|
||||||
|
|
||||||
|
|
||||||
|
Warning (WARN123) Lint Warning
|
||||||
|
Consider this.
|
||||||
|
|
||||||
|
>>> - 1 adjudicated
|
||||||
|
+ adjudidoged
|
1
src/lint/renderer/__tests__/data/inline.txt
Normal file
1
src/lint/renderer/__tests__/data/inline.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
adjudicated
|
10
src/lint/renderer/__tests__/data/simple.expect
Normal file
10
src/lint/renderer/__tests__/data/simple.expect
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
>>> Lint for path/to/example.c:
|
||||||
|
|
||||||
|
|
||||||
|
Warning (WARN123) Lint Warning
|
||||||
|
Consider this.
|
||||||
|
|
||||||
|
>>> - 1 a
|
||||||
|
+ z
|
||||||
|
2 b
|
||||||
|
3 c
|
3
src/lint/renderer/__tests__/data/simple.txt
Normal file
3
src/lint/renderer/__tests__/data/simple.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
a
|
||||||
|
b
|
||||||
|
c
|
Loading…
Add table
Reference in a new issue