diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 2a3cfcf8..00590037 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -87,6 +87,7 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index 00000000..aa07850e --- /dev/null +++ b/src/lint/renderer/__tests__/ArcanistConsoleLintRendererTestCase.php @@ -0,0 +1,89 @@ + 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 index 00000000..eba4522b --- /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 index 00000000..1907182f --- /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 index 00000000..43b9910f --- /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 index 00000000..de980441 --- /dev/null +++ b/src/lint/renderer/__tests__/data/simple.txt @@ -0,0 +1,3 @@ +a +b +c