Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15440257
D18508.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Referenced Files
None
Subscribers
None
D18508.id.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -87,6 +87,7 @@
'ArcanistConfigurationDrivenUnitTestEngine' => 'unit/engine/ArcanistConfigurationDrivenUnitTestEngine.php',
'ArcanistConfigurationManager' => 'configuration/ArcanistConfigurationManager.php',
'ArcanistConsoleLintRenderer' => 'lint/renderer/ArcanistConsoleLintRenderer.php',
+ 'ArcanistConsoleLintRendererTestCase' => 'lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php',
'ArcanistConstructorParenthesesXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistConstructorParenthesesXHPASTLinterRule.php',
'ArcanistConstructorParenthesesXHPASTLinterRuleTestCase' => 'lint/linter/xhpast/rules/__tests__/ArcanistConstructorParenthesesXHPASTLinterRuleTestCase.php',
'ArcanistControlStatementSpacingXHPASTLinterRule' => 'lint/linter/xhpast/rules/ArcanistControlStatementSpacingXHPASTLinterRule.php',
@@ -502,6 +503,7 @@
'ArcanistConfigurationDrivenUnitTestEngine' => 'ArcanistUnitTestEngine',
'ArcanistConfigurationManager' => 'Phobject',
'ArcanistConsoleLintRenderer' => 'ArcanistLintRenderer',
+ 'ArcanistConsoleLintRendererTestCase' => 'PhutilTestCase',
'ArcanistConstructorParenthesesXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
'ArcanistConstructorParenthesesXHPASTLinterRuleTestCase' => 'ArcanistXHPASTLinterRuleTestCase',
'ArcanistControlStatementSpacingXHPASTLinterRule' => 'ArcanistXHPASTLinterRule',
diff --git a/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php b/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php
new file mode 100644
--- /dev/null
+++ b/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php
@@ -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);
+ }
+
+}
diff --git a/src/lint/renderer/__tests__/data/inline.expect b/src/lint/renderer/__tests__/data/inline.expect
new file mode 100644
--- /dev/null
+++ b/src/lint/renderer/__tests__/data/inline.expect
@@ -0,0 +1,8 @@
+>>> Lint for path/to/example.c:
+
+
+ Warning (WARN123) Lint Warning
+ Consider this.
+
+ >>> - 1 adjudicated
+ + adjudidoged
diff --git a/src/lint/renderer/__tests__/data/inline.txt b/src/lint/renderer/__tests__/data/inline.txt
new file mode 100644
--- /dev/null
+++ b/src/lint/renderer/__tests__/data/inline.txt
@@ -0,0 +1 @@
+adjudicated
diff --git a/src/lint/renderer/__tests__/data/simple.expect b/src/lint/renderer/__tests__/data/simple.expect
new file mode 100644
--- /dev/null
+++ b/src/lint/renderer/__tests__/data/simple.expect
@@ -0,0 +1,10 @@
+>>> Lint for path/to/example.c:
+
+
+ Warning (WARN123) Lint Warning
+ Consider this.
+
+ >>> - 1 a
+ + z
+ 2 b
+ 3 c
diff --git a/src/lint/renderer/__tests__/data/simple.txt b/src/lint/renderer/__tests__/data/simple.txt
new file mode 100644
--- /dev/null
+++ b/src/lint/renderer/__tests__/data/simple.txt
@@ -0,0 +1,3 @@
+a
+b
+c
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 27, 11:42 AM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7709460
Default Alt Text
D18508.id.diff (5 KB)
Attached To
Mode
D18508: Add basic test coverage for lint console rendering
Attached
Detach File
Event Timeline
Log In to Comment