From 99afe586b3a42adce580011079a83bbdaab675bd Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 24 Apr 2017 21:11:27 +0100 Subject: [PATCH] Simplify some code and format some tests better --- ale_linters/dockerfile/hadolint.vim | 1 - ale_linters/go/gobuild.vim | 4 - ale_linters/go/gometalinter.vim | 4 - autoload/ale/handlers.vim | 21 -- autoload/ale/handlers/rust.vim | 6 - test/handler/test_common_handlers.vader | 343 ++++++++++-------------- test/handler/test_ghc_handler.vader | 33 ++- test/handler/test_rust_handler.vader | 28 +- 8 files changed, 195 insertions(+), 245 deletions(-) diff --git a/ale_linters/dockerfile/hadolint.vim b/ale_linters/dockerfile/hadolint.vim index ab96d3c..1ac94ce 100644 --- a/ale_linters/dockerfile/hadolint.vim +++ b/ale_linters/dockerfile/hadolint.vim @@ -18,7 +18,6 @@ function! ale_linters#dockerfile#hadolint#Handle(buffer, lines) abort let l:text = l:match[3] call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:lnum, \ 'col': 0, \ 'type': l:type, diff --git a/ale_linters/go/gobuild.vim b/ale_linters/go/gobuild.vim index eee0bf8..419e67a 100644 --- a/ale_linters/go/gobuild.vim +++ b/ale_linters/go/gobuild.vim @@ -50,15 +50,11 @@ function! ale_linters#go#gobuild#HandleGoBuildErrors(buffer, full_filename, line continue endif - " vcol is Needed to indicate that the column is a character. call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:match[3], \ 'type': 'E', - \ 'nr': -1, \}) endfor diff --git a/ale_linters/go/gometalinter.vim b/ale_linters/go/gometalinter.vim index 71d60c5..b71747c 100644 --- a/ale_linters/go/gometalinter.vim +++ b/ale_linters/go/gometalinter.vim @@ -32,15 +32,11 @@ function! ale_linters#go#gometalinter#Handler(buffer, lines) abort continue endif - " vcol is Needed to indicate that the column is a character. call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:match[4], \ 'type': tolower(l:match[3]) ==# 'warning' ? 'W' : 'E', - \ 'nr': -1, \}) endfor diff --git a/autoload/ale/handlers.vim b/autoload/ale/handlers.vim index 75d881f..011817a 100644 --- a/autoload/ale/handlers.vim +++ b/autoload/ale/handlers.vim @@ -22,15 +22,11 @@ function! s:HandleUnixFormat(buffer, lines, type) abort continue endif - " vcol is Needed to indicate that the column is a character. call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:match[3], \ 'type': a:type, - \ 'nr': -1, \}) endfor @@ -60,13 +56,10 @@ function! ale#handlers#HandleCppCheckFormat(buffer, lines) abort endif call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': 0, \ 'text': l:match[3] . ' (' . l:match[2] . ')', \ 'type': l:match[2] ==# 'error' ? 'E' : 'W', - \ 'nr': -1, \}) endfor @@ -103,13 +96,10 @@ function! ale#handlers#HandlePEP8Format(buffer, lines) abort endif call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:code . ': ' . l:match[5], \ 'type': l:match[4] ==# 'E' ? 'E' : 'W', - \ 'nr': -1, \}) endfor @@ -142,15 +132,11 @@ function! ale#handlers#HandleCSSLintFormat(buffer, lines) abort " it is on small echo lines. let l:text = '(' . l:errorGroup . ') ' . l:text - " vcol is Needed to indicate that the column is a character. call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:text, \ 'type': l:type ==# 'Warning' ? 'W' : 'E', - \ 'nr': -1, \}) endfor @@ -176,15 +162,11 @@ function! ale#handlers#HandleStyleLintFormat(buffer, lines) abort let l:type = l:match[3] ==# '✖' ? 'E' : 'W' let l:text = l:match[4] . '[' . l:match[5] . ']' - " vcol is Needed to indicate that the column is a character. call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:text, \ 'type': l:type, - \ 'nr': -1, \}) endfor @@ -233,13 +215,10 @@ function! ale#handlers#HandleGhcFormat(buffer, lines) abort let l:type = l:type ==# '' ? 'E' : toupper(l:type[0]) call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:match[1] + 0, - \ 'vcol': 0, \ 'col': l:match[2] + 0, \ 'text': l:text, \ 'type': l:type, - \ 'nr': -1, \}) endfor diff --git a/autoload/ale/handlers/rust.vim b/autoload/ale/handlers/rust.vim index c00c227..4fa7f05 100644 --- a/autoload/ale/handlers/rust.vim +++ b/autoload/ale/handlers/rust.vim @@ -53,11 +53,8 @@ function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines \ && (l:span_filename ==# l:filename || l:span_filename ==# '') \) call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:span.line_start, - \ 'vcol': 0, \ 'col': l:span.byte_start, - \ 'nr': -1, \ 'text': l:error.message, \ 'type': toupper(l:error.level[0]), \}) @@ -68,11 +65,8 @@ function! ale#handlers#rust#HandleRustErrorsForFile(buffer, full_filename, lines if !empty(l:root_cause) call add(l:output, { - \ 'bufnr': a:buffer, \ 'lnum': l:root_cause[0], - \ 'vcol': 0, \ 'col': l:root_cause[1], - \ 'nr': -1, \ 'text': l:error.message, \ 'type': toupper(l:error.level[0]), \}) diff --git a/test/handler/test_common_handlers.vader b/test/handler/test_common_handlers.vader index f087fb5..b5e0c2d 100644 --- a/test/handler/test_common_handlers.vader +++ b/test/handler/test_common_handlers.vader @@ -1,202 +1,153 @@ -Execute (Run HandleCSSLintFormat): - let g:loclist = ale#handlers#HandleCSSLintFormat(42, [ - \ 'something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors)', - \ "something.css: line 2, col 5, Warning - Expected ... but found 'wat'. (known-properties)", - \]) +Execute(HandleCSSLintFormat should handle CSS errors): + AssertEqual + \ [ + \ { + \ 'lnum': 2, + \ 'col': 1, + \ 'type': 'E', + \ 'text': '(errors) Expected RBRACE at line 2, col 1.', + \ }, + \ { + \ 'lnum': 2, + \ 'col': 5, + \ 'type': 'W', + \ 'text': "(known-properties) Expected ... but found 'wat'.", + \ }, + \ ], + \ ale#handlers#HandleCSSLintFormat(42, [ + \ 'something.css: line 2, col 1, Error - Expected RBRACE at line 2, col 1. (errors)', + \ "something.css: line 2, col 5, Warning - Expected ... but found 'wat'. (known-properties)", + \ ]) -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 2, - \ 'col': 1, - \ 'type': 'E', - \ 'text': '(errors) Expected RBRACE at line 2, col 1.', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 2, - \ 'col': 5, - \ 'type': 'W', - \ 'text': "(known-properties) Expected ... but found 'wat'.", - \ }, - \], g:loclist +Execute (HandlePEP8Format should handle the correct lines of output): + AssertEqual + \ [ + \ { + \ 'lnum': 6, + \ 'col': 6, + \ 'type': 'E', + \ 'text': 'E111: indentation is not a multiple of four', + \ }, + \ { + \ 'lnum': 35, + \ 'col': 0, + \ 'type': 'E', + \ 'text': "EANSIBLE0002: Trailing whitespace", + \ }, + \ ], + \ ale#handlers#HandlePEP8Format(42, [ + \ "stdin:6:6: E111 indentation is not a multiple of four", + \ "test.yml:35: [EANSIBLE0002] Trailing whitespace", + \ ]) -Execute (Run HandlePEP8Format): - let g:loclist = ale#handlers#HandlePEP8Format(42, [ - \ "stdin:6:6: E111 indentation is not a multiple of four", - \ "test.yml:35: [EANSIBLE0002] Trailing whitespace", - \]) +Execute (HandleGCCFormat should handle the correct lines of output): + AssertEqual + \ [ + \ { + \ 'lnum': 8, + \ 'col': 5, + \ 'type': 'W', + \ 'text': 'conversion lacks type at end of format [-Wformat=]', + \ }, + \ { + \ 'lnum': 10, + \ 'col': 27, + \ 'type': 'E', + \ 'text': 'invalid operands to binary - (have ‘int’ and ‘char *’)', + \ }, + \ ], + \ ale#handlers#gcc#HandleGCCFormat(42, [ + \ ':8:5: warning: conversion lacks type at end of format [-Wformat=]', + \ ':10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’)', + \ ]) -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 6, - \ 'col': 6, - \ 'type': 'E', - \ 'text': 'E111: indentation is not a multiple of four', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 35, - \ 'col': 0, - \ 'type': 'E', - \ 'text': "EANSIBLE0002: Trailing whitespace", - \ }, - \], g:loclist +Execute (HandleUnixFormatAsError should handle some example lines of output): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 0, + \ 'type': 'E', + \ 'text': 'missing argument for Printf("%s"): format reads arg 2, have only 1 args', + \ }, + \ { + \ 'lnum': 53, + \ 'col': 10, + \ 'type': 'E', + \ 'text': 'if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', + \ }, + \ { + \ 'lnum': 1, + \ 'col': 1, + \ 'type': 'E', + \ 'text': '".b" is not a valid class name. Class names must begin with "-", "_" or a letter and can only contain "_", "-", a-z and 0-9.', + \ }, + \ ], + \ ale#handlers#HandleUnixFormatAsError(42, [ + \ 'file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args', + \ 'file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', + \ 'test.pug:1:1 ".b" is not a valid class name. Class names must begin with "-", "_" or a letter and can only contain "_", "-", a-z and 0-9.', + \ ]) -Execute (Run HandleGCCFormat): - let g:loclist = ale#handlers#gcc#HandleGCCFormat(42, [ - \ ':8:5: warning: conversion lacks type at end of format [-Wformat=]', - \ ':10:27: error: invalid operands to binary - (have ‘int’ and ‘char *’)', - \]) +Execute (HandleUnixFormatAsWarning should handle some example lines of output): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 0, + \ 'type': 'W', + \ 'text': 'missing argument for Printf("%s"): format reads arg 2, have only 1 args', + \ }, + \ { + \ 'lnum': 53, + \ 'col': 10, + \ 'type': 'W', + \ 'text': 'if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', + \ }, + \ ], + \ ale#handlers#HandleUnixFormatAsWarning(42, [ + \ 'file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args', + \ 'file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', + \ ]) -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'lnum': 8, - \ 'col': 5, - \ 'type': 'W', - \ 'text': 'conversion lacks type at end of format [-Wformat=]', - \ }, - \ { - \ 'lnum': 10, - \ 'col': 27, - \ 'type': 'E', - \ 'text': 'invalid operands to binary - (have ‘int’ and ‘char *’)', - \ }, - \], g:loclist +Execute (Unix format functions should handle Windows paths): + AssertEqual + \ [ + \ { + \ 'lnum': 27, + \ 'col': 0, + \ 'type': 'E', + \ 'text': 'foo', + \ }, + \ { + \ 'lnum': 53, + \ 'col': 10, + \ 'type': 'E', + \ 'text': 'foo', + \ }, + \ ], + \ ale#handlers#HandleUnixFormatAsError(42, [ + \ 'C:\Users\w0rp\AppData\Local\Temp\Xyz123.go:27: foo', + \ 'C:\Users\w0rp\AppData\Local\Temp\Xyz123.go:53:10: foo', + \ ]) -Execute (Run HandleUnixFormatAsError): - let g:loclist = ale#handlers#HandleUnixFormatAsError(42, [ - \ 'file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args', - \ 'file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', - \ 'test.pug:1:1 ".b" is not a valid class name. Class names must begin with "-", "_" or a letter and can only contain "_", "-", a-z and 0-9.', - \]) - -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 27, - \ 'col': 0, - \ 'type': 'E', - \ 'text': 'missing argument for Printf("%s"): format reads arg 2, have only 1 args', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 53, - \ 'col': 10, - \ 'type': 'E', - \ 'text': 'if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 1, - \ 'col': 1, - \ 'type': 'E', - \ 'text': '".b" is not a valid class name. Class names must begin with "-", "_" or a letter and can only contain "_", "-", a-z and 0-9.', - \ }, - \], g:loclist - -Execute (Run HandleUnixFormatAsWarning): - let g:loclist = ale#handlers#HandleUnixFormatAsWarning(42, [ - \ 'file.go:27: missing argument for Printf("%s"): format reads arg 2, have only 1 args', - \ 'file.go:53:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', - \]) - -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 27, - \ 'col': 0, - \ 'type': 'W', - \ 'text': 'missing argument for Printf("%s"): format reads arg 2, have only 1 args', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 53, - \ 'col': 10, - \ 'type': 'W', - \ 'text': 'if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)', - \ }, - \], g:loclist - -Execute (Run a Unix format function with a Windows path): - let g:loclist = ale#handlers#HandleUnixFormatAsError(42, [ - \ 'C:\Users\w0rp\AppData\Local\Temp\Xyz123.go:27: foo', - \ 'C:\Users\w0rp\AppData\Local\Temp\Xyz123.go:53:10: foo', - \]) - -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 27, - \ 'col': 0, - \ 'type': 'E', - \ 'text': 'foo', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 53, - \ 'col': 10, - \ 'type': 'E', - \ 'text': 'foo', - \ }, - \], g:loclist - -Execute (Run HandleCppCheckFormat): - let g:loclist = ale#handlers#HandleCppCheckFormat(42, [ - \ '[/tmp/test.c:5]: (style) Variable a is assigned a value that is never used.', - \ '[/tmp/test.c:12]: (error) Array a[10] accessed at index 10, which is out of bounds.' - \]) - -Then (The loclist should be correct): - AssertEqual [ - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 5, - \ 'col': 0, - \ 'type': 'W', - \ 'text': 'Variable a is assigned a value that is never used. (style)', - \ }, - \ { - \ 'bufnr': 42, - \ 'vcol': 0, - \ 'nr': -1, - \ 'lnum': 12, - \ 'col': 0, - \ 'type': 'E', - \ 'text': 'Array a[10] accessed at index 10, which is out of bounds. (error)', - \ }, - \], g:loclist - -After: - unlet g:loclist +Execute (HandleCppCheckFormat should handle some example lines of output): + AssertEqual + \ [ + \ { + \ 'lnum': 5, + \ 'col': 0, + \ 'type': 'W', + \ 'text': 'Variable a is assigned a value that is never used. (style)', + \ }, + \ { + \ 'lnum': 12, + \ 'col': 0, + \ 'type': 'E', + \ 'text': 'Array a[10] accessed at index 10, which is out of bounds. (error)', + \ }, + \ ], + \ ale#handlers#HandleCppCheckFormat(42, [ + \ '[/tmp/test.c:5]: (style) Variable a is assigned a value that is never used.', + \ '[/tmp/test.c:12]: (error) Array a[10] accessed at index 10, which is out of bounds.' + \ ]) diff --git a/test/handler/test_ghc_handler.vader b/test/handler/test_ghc_handler.vader index 2350d9e..b924974 100644 --- a/test/handler/test_ghc_handler.vader +++ b/test/handler/test_ghc_handler.vader @@ -1,8 +1,12 @@ Execute(The ghc handler should handle hdevtools output): - AssertEqual \ [ - \ {'lnum': 147, 'bufnr': 12, 'vcol': 0, 'nr': -1, 'type': 'W', 'col': 62, 'text': '• Couldnt match type ‘a -> T.Text’ with ‘T.Text’ Expected type: [T.Text]'}, + \ { + \ 'lnum': 147, + \ 'type': 'W', + \ 'col': 62, + \ 'text': '• Couldnt match type ‘a -> T.Text’ with ‘T.Text’ Expected type: [T.Text]', + \ }, \ ], \ ale#handlers#HandleGhcFormat(12, [ \ '/path/to/foo.hs:147:62: warning:', @@ -10,13 +14,21 @@ Execute(The ghc handler should handle hdevtools output): \ ' Expected type: [T.Text]', \ ]) - Execute(The ghc handler should handle ghc 8 output): - AssertEqual \ [ - \ {'lnum': 6, 'bufnr': 47, 'vcol': 0, 'nr': -1, 'type': 'E', 'col': 1, 'text': ' Failed to load interface for ‘GitHub.Data’ Use -v to see a list of the files searched for.'}, - \ {'lnum': 7, 'bufnr': 47, 'vcol': 0, 'nr': -1, 'type': 'W', 'col': 1, 'text': ' Failed to load interface for ‘GitHub.Endpoints.PullRequests’ Use -v to see a list of the files searched for.'}, + \ { + \ 'lnum': 6, + \ 'type': 'E', + \ 'col': 1, + \ 'text': ' Failed to load interface for ‘GitHub.Data’ Use -v to see a list of the files searched for.', + \ }, + \ { + \ 'lnum': 7, + \ 'type': 'W', + \ 'col': 1, + \ 'text': ' Failed to load interface for ‘GitHub.Endpoints.PullRequests’ Use -v to see a list of the files searched for.', + \ }, \ ], \ ale#handlers#HandleGhcFormat(47, [ \ '', @@ -29,12 +41,15 @@ Execute(The ghc handler should handle ghc 8 output): \ ' Use -v to see a list of the files searched for.', \ ]) - Execute(The ghc handler should handle ghc 7 output): - AssertEqual \ [ - \ {'lnum': 168, 'bufnr': 47, 'vcol': 0, 'nr': -1, 'type': 'E', 'col': 1, 'text': ' parse error (possibly incorrect indentation or mismatched brackets)'}, + \ { + \ 'lnum': 168, + \ 'type': 'E', + \ 'col': 1, + \ 'text': ' parse error (possibly incorrect indentation or mismatched brackets)', + \ }, \ ], \ ale#handlers#HandleGhcFormat(47, [ \ 'src/Main.hs:168:1:', diff --git a/test/handler/test_rust_handler.vader b/test/handler/test_rust_handler.vader index d4d54d3..3e0ed43 100644 --- a/test/handler/test_rust_handler.vader +++ b/test/handler/test_rust_handler.vader @@ -1,8 +1,18 @@ Execute(The Rust handler should handle rustc output): AssertEqual \ [ - \ {'lnum': 15, 'bufnr': 347, 'vcol': 0, 'nr': -1, 'type': 'E', 'col': 418, 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`'}, - \ {'lnum': 13, 'bufnr': 347, 'vcol': 0, 'nr': -1, 'type': 'E', 'col': 407, 'text': 'no method named `wat` found for type `std::string::String` in the current scope'}, + \ { + \ 'lnum': 15, + \ 'type': 'E', + \ 'col': 418, + \ 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`', + \ }, + \ { + \ 'lnum': 13, + \ 'type': 'E', + \ 'col': 407, + \ 'text': 'no method named `wat` found for type `std::string::String` in the current scope', + \ }, \ ], \ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/playpen.rs', [ \ '', @@ -16,8 +26,18 @@ Execute(The Rust handler should handle rustc output): Execute(The Rust handler should handle cargo output): AssertEqual \ [ - \ {'lnum': 15, 'bufnr': 347, 'vcol': 0, 'nr': -1, 'type': 'E', 'col': 11505, 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`'}, - \ {'lnum': 13, 'bufnr': 347, 'vcol': 0, 'nr': -1, 'type': 'E', 'col': 11494, 'text': 'no method named `wat` found for type `std::string::String` in the current scope'}, + \ { + \ 'lnum': 15, + \ 'type': 'E', + \ 'col': 11505, + \ 'text': 'expected one of `.`, `;`, `?`, `}`, or an operator, found `for`', + \ }, + \ { + \ 'lnum': 13, + \ 'type': 'E', + \ 'col': 11494, + \ 'text': 'no method named `wat` found for type `std::string::String` in the current scope', + \ }, \ ], \ ale#handlers#rust#HandleRustErrorsForFile(347, 'src/playpen.rs', [ \ '',