diff options
Diffstat (limited to 'test')
37 files changed, 863 insertions, 145 deletions
diff --git a/test/command_callback/test_bandit_command_callback.vader b/test/command_callback/test_bandit_command_callback.vader new file mode 100644 index 00000000..5d1e6fd3 --- /dev/null +++ b/test/command_callback/test_bandit_command_callback.vader @@ -0,0 +1,49 @@ +Before: + call ale#assert#SetUpLinterTest('python', 'bandit') + let b:bandit_flags = ' --format custom ' + \ . '--msg-template "{line}:{test_id}:{severity}:{msg}" ' + +After: + call ale#assert#TearDownLinterTest() + unlet! b:bandit_flags + +Execute(The bandit command callback should return default string): + AssertLinter 'bandit', + \ ale#Escape('bandit') + \ . b:bandit_flags + \ . ' -' + +Execute(The bandit command callback should allow options): + let g:ale_python_bandit_options = '--configfile bandit.yaml' + + AssertLinter 'bandit', + \ ale#Escape('bandit') + \ . b:bandit_flags + \ . ' --configfile bandit.yaml -' + +Execute(The bandit executable should be configurable): + let g:ale_python_bandit_executable = '~/.local/bin/bandit' + + AssertLinter '~/.local/bin/bandit', + \ ale#Escape('~/.local/bin/bandit') + \ . b:bandit_flags + \ . ' -' + +Execute(Setting executable to 'pipenv' appends 'run bandit'): + let g:ale_python_bandit_executable = 'path/to/pipenv' + + AssertLinter 'path/to/pipenv', + \ ale#Escape('path/to/pipenv') + \ . ' run bandit' + \ . b:bandit_flags + \ . ' -' + +Execute(Pipenv is detected when python_bandit_auto_pipenv is set): + let g:ale_python_bandit_auto_pipenv = 1 + call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py') + + AssertLinter 'pipenv', + \ ale#Escape('pipenv') + \ . ' run bandit' + \ . b:bandit_flags + \ . ' -' diff --git a/test/command_callback/test_ghdl_command_callbacks.vader b/test/command_callback/test_ghdl_command_callbacks.vader new file mode 100644 index 00000000..f254e11f --- /dev/null +++ b/test/command_callback/test_ghdl_command_callbacks.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('vhdl', 'ghdl') + +After: + unlet! b:command_tail + + call ale#assert#TearDownLinterTest() + +Execute(The executable should be configurable): + AssertLinter 'ghdl', ale#Escape('ghdl') . ' -s --std=08 %t' + + let b:ale_vhdl_ghdl_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' -s --std=08 %t' + +Execute(The options should be configurable): + let b:ale_vhdl_ghdl_options = '--something' + + AssertLinter 'ghdl', ale#Escape('ghdl') . ' -s --something %t' diff --git a/test/command_callback/test_haskell_stack_ghc_command_callback.vader b/test/command_callback/test_haskell_stack_ghc_command_callback.vader index 4adab583..f58f8b5f 100644 --- a/test/command_callback/test_haskell_stack_ghc_command_callback.vader +++ b/test/command_callback/test_haskell_stack_ghc_command_callback.vader @@ -12,3 +12,6 @@ Execute(The linter should be executed when there is a stack.yaml file): AssertLinter 'stack', 'stack ghc -- -fno-code -v0 %t' + let b:ale_haskell_stack_ghc_options = 'foobar' + + AssertLinter 'stack', 'stack ghc -- foobar %t' diff --git a/test/command_callback/test_pyls_command_callback.vader b/test/command_callback/test_pyls_command_callback.vader index 531b5b3b..aff2fcd7 100644 --- a/test/command_callback/test_pyls_command_callback.vader +++ b/test/command_callback/test_pyls_command_callback.vader @@ -45,3 +45,8 @@ Execute(Pipenv is detected when python_pyls_auto_pipenv is set): AssertLinter 'pipenv', \ ale#Escape('pipenv') . ' run pyls' + +Execute(Should accept configuration settings): + AssertLSPConfig {} + let b:ale_python_pyls_config = {'pyls': {'plugins': {'preload': {'enabled': v:false}}}} + AssertLSPConfig {'pyls': {'plugins': {'preload': {'enabled': v:false}}}} diff --git a/test/command_callback/test_sugarss_stylelint_command_callback.vader b/test/command_callback/test_sugarss_stylelint_command_callback.vader new file mode 100644 index 00000000..448436fb --- /dev/null +++ b/test/command_callback/test_sugarss_stylelint_command_callback.vader @@ -0,0 +1,31 @@ +Before: + call ale#assert#SetUpLinterTest('sugarss', 'stylelint') + unlet! b:executable + +After: + unlet! b:executable + call ale#assert#TearDownLinterTest() + +Execute(node_modules directories should be discovered): + call ale#test#SetFilename('stylelint_paths/nested/testfile.sss') + + let b:executable = ale#path#Simplify( + \ g:dir + \ . '/stylelint_paths/node_modules/.bin/stylelint' + \) + + AssertLinter b:executable, ale#Escape(b:executable) . ' --syntax=sugarss --stdin-filename %s' + +Execute(The global override should work): + let b:ale_sugarss_stylelint_executable = 'foobar' + let b:ale_sugarss_stylelint_use_global = 1 + + call ale#test#SetFilename('stylelint_paths/nested/testfile.sss') + + AssertLinter 'foobar', ale#Escape('foobar') . ' --syntax=sugarss --stdin-filename %s' + +Execute(Extra options should be configurable): + let b:ale_sugarss_stylelint_options = '--configFile ''/absolute/path/to/file''' + + AssertLinter 'stylelint', + \ ale#Escape('stylelint') . ' --configFile ''/absolute/path/to/file'' --syntax=sugarss --stdin-filename %s' diff --git a/test/command_callback/test_tex_textlint_command_callbacks.vader b/test/command_callback/test_tex_textlint_command_callbacks.vader new file mode 100644 index 00000000..d1e2ab91 --- /dev/null +++ b/test/command_callback/test_tex_textlint_command_callbacks.vader @@ -0,0 +1,65 @@ +" Author: januswel, w0rp + +Before: + " This is just one language for the linter. + call ale#assert#SetUpLinterTest('tex', 'textlint') + + " The configuration is shared between many languages. + Save g:ale_textlint_executable + Save g:ale_textlint_use_global + Save g:ale_textlint_options + + let g:ale_textlint_executable = 'textlint' + let g:ale_textlint_use_global = 0 + let g:ale_textlint_options = '' + + unlet! b:ale_textlint_executable + unlet! b:ale_textlint_use_global + unlet! b:ale_textlint_options + +After: + unlet! b:command_tail + unlet! b:ale_textlint_executable + unlet! b:ale_textlint_use_global + unlet! b:ale_textlint_options + + call ale#assert#TearDownLinterTest() + +Execute(The default command should be correct): + AssertLinter 'textlint', + \ ale#Escape('textlint') . ' -f json --stdin --stdin-filename %s' + +Execute(The executable should be configurable): + let b:ale_textlint_executable = 'foobar' + + AssertLinter 'foobar', + \ ale#Escape('foobar') . ' -f json --stdin --stdin-filename %s' + +Execute(The options should be configurable): + let b:ale_textlint_options = '--something' + + AssertLinter 'textlint', + \ ale#Escape('textlint') . ' --something -f json --stdin --stdin-filename %s' + +Execute(The local executable from .bin should be used if available): + call ale#test#SetFilename('textlint_paths/with_bin_path/foo.txt') + + AssertLinter + \ ale#path#Simplify(g:dir . '/textlint_paths/with_bin_path/node_modules/.bin/textlint'), + \ ale#Escape(ale#path#Simplify(g:dir . '/textlint_paths/with_bin_path/node_modules/.bin/textlint')) + \ . ' -f json --stdin --stdin-filename %s' + +Execute(The local executable from textlint/bin should be used if available): + call ale#test#SetFilename('textlint_paths/with_textlint_bin_path/foo.txt') + + if has('win32') + AssertLinter + \ ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js'), + \ ale#Escape('node.exe') . ' ' . ale#Escape(ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js')) + \ . ' -f json --stdin --stdin-filename %s' + else + AssertLinter + \ ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js'), + \ ale#Escape(ale#path#Simplify(g:dir . '/textlint_paths/with_textlint_bin_path/node_modules/textlint/bin/textlint.js')) + \ . ' -f json --stdin --stdin-filename %s' + endif diff --git a/test/command_callback/test_vcom_command_callbacks.vader b/test/command_callback/test_vcom_command_callbacks.vader new file mode 100644 index 00000000..77218f74 --- /dev/null +++ b/test/command_callback/test_vcom_command_callbacks.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('vhdl', 'vcom') + +After: + unlet! b:command_tail + + call ale#assert#TearDownLinterTest() + +Execute(The executable should be configurable): + AssertLinter 'vcom', ale#Escape('vcom') . ' -2008 -quiet -lint %t' + + let b:ale_vhdl_vcom_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' -2008 -quiet -lint %t' + +Execute(The options should be configurable): + let b:ale_vhdl_vcom_options = '--something' + + AssertLinter 'vcom', ale#Escape('vcom') . ' --something %t' diff --git a/test/command_callback/test_vlog_command_callbacks.vader b/test/command_callback/test_vlog_command_callbacks.vader new file mode 100644 index 00000000..a07944f7 --- /dev/null +++ b/test/command_callback/test_vlog_command_callbacks.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('verilog', 'vlog') + +After: + unlet! b:command_tail + + call ale#assert#TearDownLinterTest() + +Execute(The executable should be configurable): + AssertLinter 'vlog', ale#Escape('vlog') . ' -quiet -lint %t' + + let b:ale_verilog_vlog_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' -quiet -lint %t' + +Execute(The options should be configurable): + let b:ale_verilog_vlog_options = '--something' + + AssertLinter 'vlog', ale#Escape('vlog') . ' --something %t' diff --git a/test/command_callback/test_xvhdl_command_callbacks.vader b/test/command_callback/test_xvhdl_command_callbacks.vader new file mode 100644 index 00000000..86f9a32d --- /dev/null +++ b/test/command_callback/test_xvhdl_command_callbacks.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('vhdl', 'xvhdl') + +After: + unlet! b:command_tail + + call ale#assert#TearDownLinterTest() + +Execute(The executable should be configurable): + AssertLinter 'xvhdl', ale#Escape('xvhdl') . ' --2008 %t' + + let b:ale_vhdl_xvhdl_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' --2008 %t' + +Execute(The options should be configurable): + let b:ale_vhdl_xvhdl_options = '--something' + + AssertLinter 'xvhdl', ale#Escape('xvhdl') . ' --something %t' diff --git a/test/command_callback/test_xvlog_command_callbacks.vader b/test/command_callback/test_xvlog_command_callbacks.vader new file mode 100644 index 00000000..564ac979 --- /dev/null +++ b/test/command_callback/test_xvlog_command_callbacks.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('verilog', 'xvlog') + +After: + unlet! b:command_tail + + call ale#assert#TearDownLinterTest() + +Execute(The executable should be configurable): + AssertLinter 'xvlog', ale#Escape('xvlog') . ' %t' + + let b:ale_verilog_xvlog_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' %t' + +Execute(The options should be configurable): + let b:ale_verilog_xvlog_options = '--something' + + AssertLinter 'xvlog', ale#Escape('xvlog') . ' --something %t' diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader index 130f31b9..f670e186 100644 --- a/test/completion/test_lsp_completion_messages.vader +++ b/test/completion/test_lsp_completion_messages.vader @@ -215,7 +215,7 @@ Execute(The right message should be sent for the initial LSP request): \ }], \ [0, 'textDocument/completion', { \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, - \ 'position': {'line': 0, 'character': 3}, + \ 'position': {'line': 0, 'character': 2}, \ }], \ ], \ g:message_list @@ -274,7 +274,7 @@ Execute(Two completion requests shouldn't be sent in a row): \ }], \ [0, 'textDocument/completion', { \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, - \ 'position': {'line': 0, 'character': 3}, + \ 'position': {'line': 0, 'character': 2}, \ }], \ ], \ g:message_list diff --git a/test/fixers/test_cmakeformat_fixer_callback.vader b/test/fixers/test_cmakeformat_fixer_callback.vader new file mode 100644 index 00000000..9263d6fa --- /dev/null +++ b/test/fixers/test_cmakeformat_fixer_callback.vader @@ -0,0 +1,40 @@ +Before: + Save g:ale_cmake_cmakeformat_executable + Save g:ale_cmake_cmakeformat_options + + " Use an invalid global executable, so we don't match it. + let g:ale_cmake_cmakeformat_executable = 'xxxinvalid' + let g:ale_cmake_cmakeformat_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The cmakeformat callback should return the correct default values): + call ale#test#SetFilename('../cmake_files/CMakeList.txt') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' -i ' + \ . ' %t', + \ }, + \ ale#fixers#cmakeformat#Fix(bufnr('')) + +Execute(The cmakeformat callback should include custom cmakeformat options): + let g:ale_cmake_cmakeformat_options = "-r '(a) -> a'" + call ale#test#SetFilename('../cmake_files/CMakeList.txt') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape('xxxinvalid') + \ . ' -i ' + \ . ' ' . g:ale_cmake_cmakeformat_options + \ . ' %t', + \ }, + \ ale#fixers#cmakeformat#Fix(bufnr('')) diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader index 7f25471b..05ed421e 100644 --- a/test/fixers/test_prettier_fixer_callback.vader +++ b/test/fixers/test_prettier_fixer_callback.vader @@ -96,6 +96,34 @@ Execute(The version number should be cached): \ }, \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), []) +Execute(Should set --parser to `babylon` by default, < 1.16.0): + call ale#test#SetFilename('../prettier-test-files/testfile') + + set filetype=javascript + + AssertEqual + \ { + \ 'command': ale#path#CdString(expand('%:p:h')) + \ . ale#Escape(g:ale_javascript_prettier_executable) + \ . ' --parser babylon' + \ . ' --stdin-filepath %s --stdin', + \ }, + \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + +Execute(Should set --parser to `babel` by default, >= 1.16.0): + call ale#test#SetFilename('../prettier-test-files/testfile') + + set filetype=javascript + + AssertEqual + \ { + \ 'command': ale#path#CdString(expand('%:p:h')) + \ . ale#Escape(g:ale_javascript_prettier_executable) + \ . ' --parser babel' + \ . ' --stdin-filepath %s --stdin', + \ }, + \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.16.0']) + Execute(Should set --parser based on filetype, TypeScript): call ale#test#SetFilename('../prettier-test-files/testfile') diff --git a/test/handler/test_bandit_handler.vader b/test/handler/test_bandit_handler.vader new file mode 100644 index 00000000..a2793a46 --- /dev/null +++ b/test/handler/test_bandit_handler.vader @@ -0,0 +1,42 @@ +Before: + runtime ale_linters/python/bandit.vim + +After: + call ale#linter#Reset() + +Execute(The bandit handler for Python should parse input correctly): + AssertEqual + \ [ + \ { + \ 'bufnr': 0, + \ 'lnum': 2, + \ 'code': 'B404', + \ 'type': 'I', + \ 'text': 'Consider possible security implications associated with subprocess module.', + \ }, + \ { + \ 'bufnr': 0, + \ 'lnum': 4, + \ 'code': 'B305', + \ 'type': 'W', + \ 'text': 'Use of insecure cipher mode cryptography.hazmat.primitives.ciphers.modes.ECB.', + \ }, + \ { + \ 'bufnr': 0, + \ 'lnum': 6, + \ 'code': 'B609', + \ 'type': 'E', + \ 'text': 'Possible wildcard injection in call: subprocess.Popen', + \ }, + \ ], + \ ale_linters#python#bandit#Handle(0, [ + \ '[main] INFO profile include tests: None', + \ '[main] INFO profile exclude tests: None', + \ '[main] INFO cli include tests: None', + \ '[main] INFO cli exclude tests: None', + \ '[main] INFO running on Python 3.7.2', + \ '[node_visitor] INFO Unable to find qualified name for module: <stdin>', + \ '2:B404:LOW:Consider possible security implications associated with subprocess module.', + \ '4:B305:MEDIUM:Use of insecure cipher mode cryptography.hazmat.primitives.ciphers.modes.ECB.', + \ '6:B609:HIGH:Possible wildcard injection in call: subprocess.Popen', + \ ]) diff --git a/test/handler/test_eslint_handler.vader b/test/handler/test_eslint_handler.vader index 4a57927b..1bb438a6 100644 --- a/test/handler/test_eslint_handler.vader +++ b/test/handler/test_eslint_handler.vader @@ -342,6 +342,17 @@ Execute(eslint should warn about ignored files by default): \ '/path/to/some/ignored.js:0:0: File ignored because of a matching ignore pattern. Use "--no-ignore" to override. [Warning]', \ ]) + AssertEqual + \ [{ + \ 'lnum': 0, + \ 'col': 0, + \ 'type': 'W', + \ 'text': 'File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override.', + \ }], + \ ale#handlers#eslint#Handle(bufnr(''), [ + \ '/path/to/some/ignored.js:0:0: File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override. [Warning]', + \ ]) + Execute(eslint should not warn about ignored files when explicitly disabled): let g:ale_javascript_eslint_suppress_eslintignore = 1 @@ -351,6 +362,12 @@ Execute(eslint should not warn about ignored files when explicitly disabled): \ '/path/to/some/ignored.js:0:0: File ignored because of a matching ignore pattern. Use "--no-ignore" to override. [Warning]', \ ]) + AssertEqual + \ [], + \ ale#handlers#eslint#Handle(bufnr(''), [ + \ '/path/to/some/ignored.js:0:0: File ignored by default. Use "--ignore-pattern ''!node_modules/*''" to override. [Warning]', + \ ]) + Execute(eslint should handle react errors correctly): AssertEqual \ [ diff --git a/test/handler/test_flake8_handler.vader b/test/handler/test_flake8_handler.vader index cdf20bc0..fe42211a 100644 --- a/test/handler/test_flake8_handler.vader +++ b/test/handler/test_flake8_handler.vader @@ -258,3 +258,19 @@ Execute(E112 should be a syntax error): \ ale_linters#python#flake8#Handle(bufnr(''), [ \ 'foo.py:6:1: E112 expected an indented block', \ ]) + +Execute(Compatibility with hacking which uses older style flake8): + AssertEqual + \ [ + \ { + \ 'lnum': 6, + \ 'col': 1, + \ 'vcol': 1, + \ 'code': 'H306', + \ 'type': 'W', + \ 'text': 'imports not in alphabetical order (smtplib, io)', + \ }, + \ ], + \ ale_linters#python#flake8#Handle(bufnr(''), [ + \ 'foo.py:6:1: H306: imports not in alphabetical order (smtplib, io)', + \ ]) diff --git a/test/handler/test_ghdl_handler.vader b/test/handler/test_ghdl_handler.vader new file mode 100644 index 00000000..a0f5edac --- /dev/null +++ b/test/handler/test_ghdl_handler.vader @@ -0,0 +1,26 @@ +Before: + runtime ale_linters/vhdl/ghdl.vim + +After: + call ale#linter#Reset() + +Execute(The ghdl handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 41, + \ 'col' : 5, + \ 'type': 'E', + \ 'text': "error: 'begin' is expected instead of 'if'" + \ }, + \ { + \ 'lnum': 12, + \ 'col' : 8, + \ 'type': 'E', + \ 'text': ' no declaration for "i0"' + \ }, + \ ], + \ ale_linters#vhdl#ghdl#Handle(bufnr(''), [ + \ "dff_en.vhd:41:5:error: 'begin' is expected instead of 'if'", + \ '/path/to/file.vhdl:12:8: no declaration for "i0"', + \ ]) diff --git a/test/handler/test_pydocstyle_handler.vader b/test/handler/test_pydocstyle_handler.vader index d155dc9a..cfb75307 100644 --- a/test/handler/test_pydocstyle_handler.vader +++ b/test/handler/test_pydocstyle_handler.vader @@ -66,7 +66,7 @@ Execute(Basic pydocstyle warnings should be handled): \ ], \ ale_linters#python#pydocstyle#Handle(bufnr(''), [ \ 'Checking file ' . fnamemodify(bufname(bufnr('')), ':p') . '.', - \ ale#Escape(fnamemodify(bufname(bufnr('')), ':t')) . ':1 at module level:', + \ './mydir/myfile.py:1 at module level:', \ ' D100: Missing docstring in public module', \ '', \ ' All modules should normally have docstrings. [...] all functions and', @@ -80,7 +80,7 @@ Execute(Basic pydocstyle warnings should be handled): \ ' 1: # 2: 3: s 4: a 5: m 6: p 7: l ...', \ '', \ '', - \ ale#Escape(fnamemodify(bufname(bufnr('')), ':t')) . ':4 in public function `main`:', + \ 'C:\mydir\myfile.py:4 in public function `main`:', \ ' D205: 1 blank line required between summary line and description (found 0)', \ '', \ ' Multi-line docstrings consist of a summary line just like a one-line', @@ -92,7 +92,7 @@ Execute(Basic pydocstyle warnings should be handled): \ ' 3: d 4: e 5: f 6: 7: m 8: a 9: i ...', \ '', \ '', - \ ale#Escape(fnamemodify(bufname(bufnr('')), ':t')) . ':4 in public function `main`:', + \ 'myfile.py:4 in public function `main`:', \ ' D400: First line should end with a period (not ''e'')', \ '', \ ' The [first line of a] docstring is a phrase ending in a period.', diff --git a/test/handler/test_vcom_handler.vader b/test/handler/test_vcom_handler.vader new file mode 100644 index 00000000..943b525a --- /dev/null +++ b/test/handler/test_vcom_handler.vader @@ -0,0 +1,36 @@ +Before: + runtime ale_linters/vhdl/vcom.vim + +After: + call ale#linter#Reset() + +Execute(The vcom handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 218, + \ 'type': 'W', + \ 'text': '(vcom-1236) Shared variables must be of a protected type.' + \ }, + \ { + \ 'lnum': 73, + \ 'type': 'E', + \ 'text': '(vcom-1136) Unknown identifier "aresetn".' + \ }, + \ { + \ 'lnum': 73, + \ 'type': 'E', + \ 'text': 'Bad resolution function (STD_LOGIC) for type (error).' + \ }, + \ { + \ 'lnum': 73, + \ 'type': 'E', + \ 'text': 'near ":": (vcom-1576) expecting ";" or ")".' + \ }, + \ ], + \ ale_linters#vhdl#vcom#Handle(bufnr(''), [ + \ '** Warning: ../path/to/file.vhd(218): (vcom-1236) Shared variables must be of a protected type.', + \ '** Error: tb_file.vhd(73): (vcom-1136) Unknown identifier "aresetn".', + \ '** Error: tb_file.vhd(73): Bad resolution function (STD_LOGIC) for type (error).', + \ '** Error: tb_file.vhd(73): near ":": (vcom-1576) expecting ";" or ")".', + \ ]) diff --git a/test/handler/test_vlog_handler.vader b/test/handler/test_vlog_handler.vader new file mode 100644 index 00000000..a70665db --- /dev/null +++ b/test/handler/test_vlog_handler.vader @@ -0,0 +1,24 @@ +Before: + runtime ale_linters/verilog/vlog.vim + +After: + call ale#linter#Reset() + +Execute(The vlog handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 7, + \ 'type': 'W', + \ 'text': '(vlog-2623) Undefined variable: C.' + \ }, + \ { + \ 'lnum': 1, + \ 'type': 'E', + \ 'text': '(vlog-13294) Identifier must be declared with a port mode: C.' + \ }, + \ ], + \ ale_linters#verilog#vlog#Handle(bufnr(''), [ + \ '** Warning: add.v(7): (vlog-2623) Undefined variable: C.', + \ '** Error: file.v(1): (vlog-13294) Identifier must be declared with a port mode: C.', + \ ]) diff --git a/test/handler/test_xvhdl_handler.vader b/test/handler/test_xvhdl_handler.vader new file mode 100644 index 00000000..b90539b8 --- /dev/null +++ b/test/handler/test_xvhdl_handler.vader @@ -0,0 +1,24 @@ +Before: + runtime ale_linters/vhdl/xvhdl.vim + +After: + call ale#linter#Reset() + +Execute(The xvhdl handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 17, + \ 'type': 'E', + \ 'text': '[VRFC 10-91] aresetn is not declared ' + \ }, + \ { + \ 'lnum': 128, + \ 'type': 'E', + \ 'text': '[VRFC 10-91] m_axis_tx_tdata is not declared ' + \ }, + \ ], + \ ale_linters#vhdl#xvhdl#Handle(bufnr(''), [ + \ 'ERROR: [VRFC 10-91] aresetn is not declared [/path/to/file.vhd:17]', + \ 'ERROR: [VRFC 10-91] m_axis_tx_tdata is not declared [/home/user/tx_data.vhd:128]', + \ ]) diff --git a/test/handler/test_xvlog_handler.vader b/test/handler/test_xvlog_handler.vader new file mode 100644 index 00000000..2e1f83fc --- /dev/null +++ b/test/handler/test_xvlog_handler.vader @@ -0,0 +1,18 @@ +Before: + runtime ale_linters/verilog/xvlog.vim + +After: + call ale#linter#Reset() + +Execute(The xvlog handler should parse lines correctly): + AssertEqual + \ [ + \ { + \ 'lnum': 5, + \ 'type': 'E', + \ 'text': '[VRFC 10-1412] syntax error near output ' + \ }, + \ ], + \ ale_linters#verilog#xvlog#Handle(bufnr(''), [ + \ 'ERROR: [VRFC 10-1412] syntax error near output [/path/to/file.v:5]', + \ ]) diff --git a/test/lsp/test_lsp_client_messages.vader b/test/lsp/test_lsp_client_messages.vader index 71768ce5..bdede460 100644 --- a/test/lsp/test_lsp_client_messages.vader +++ b/test/lsp/test_lsp_client_messages.vader @@ -112,7 +112,7 @@ Execute(ale#lsp#message#Completion() should return correct messages): \ 'textDocument': { \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'), \ }, - \ 'position': {'line': 11, 'character': 34}, + \ 'position': {'line': 11, 'character': 33}, \ } \ ], \ ale#lsp#message#Completion(bufnr(''), 12, 34, '') @@ -126,7 +126,7 @@ Execute(ale#lsp#message#Completion() should return correct messages with a trigg \ 'textDocument': { \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'), \ }, - \ 'position': {'line': 11, 'character': 34}, + \ 'position': {'line': 11, 'character': 33}, \ 'context': {'triggerKind': 2, 'triggerCharacter': '.'}, \ } \ ], @@ -141,11 +141,25 @@ Execute(ale#lsp#message#Definition() should return correct messages): \ 'textDocument': { \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'), \ }, - \ 'position': {'line': 11, 'character': 34}, + \ 'position': {'line': 11, 'character': 33}, \ } \ ], \ ale#lsp#message#Definition(bufnr(''), 12, 34) +Execute(ale#lsp#message#TypeDefinition() should return correct messages): + AssertEqual + \ [ + \ 0, + \ 'textDocument/typeDefinition', + \ { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'), + \ }, + \ 'position': {'line': 11, 'character': 33}, + \ } + \ ], + \ ale#lsp#message#TypeDefinition(bufnr(''), 12, 34) + Execute(ale#lsp#message#References() should return correct messages): AssertEqual \ [ @@ -155,7 +169,7 @@ Execute(ale#lsp#message#References() should return correct messages): \ 'textDocument': { \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'), \ }, - \ 'position': {'line': 11, 'character': 34}, + \ 'position': {'line': 11, 'character': 33}, \ 'context': {'includeDeclaration': v:false}, \ } \ ], @@ -181,7 +195,7 @@ Execute(ale#lsp#message#Hover() should return correct messages): \ 'textDocument': { \ 'uri': ale#path#ToURI(g:dir . '/foo/bar.ts'), \ }, - \ 'position': {'line': 11, 'character': 34}, + \ 'position': {'line': 11, 'character': 33}, \ } \ ], \ ale#lsp#message#Hover(bufnr(''), 12, 34) diff --git a/test/lsp/test_lsp_command_formatting.vader b/test/lsp/test_lsp_command_formatting.vader index 9721f37f..fcd4f78c 100644 --- a/test/lsp/test_lsp_command_formatting.vader +++ b/test/lsp/test_lsp_command_formatting.vader @@ -17,6 +17,7 @@ Execute(Command formatting should be applied correctly for LSP linters): call ale#lsp_linter#StartLSP( \ bufnr(''), \ { + \ 'name': 'linter', \ 'language_callback': {-> 'x'}, \ 'project_root_callback': {-> '/foo/bar'}, \ 'lsp': 'stdio', diff --git a/test/lsp/test_lsp_root_detection.vader b/test/lsp/test_lsp_root_detection.vader new file mode 100644 index 00000000..2575a62c --- /dev/null +++ b/test/lsp/test_lsp_root_detection.vader @@ -0,0 +1,63 @@ +Before: + call ale#assert#SetUpLinterTest('c', 'clangd') + + function! Hook1(buffer) + return 'abc123' + endfunction + +After: + let g:ale_lsp_root = {} + unlet! b:ale_lsp_root + delfunction Hook1 + + call ale#assert#TearDownLinterTest() + +Execute(The buffer-specific variable can be a string): + let b:ale_lsp_root = '/some/path' + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The buffer-specific variable can be a dictionary): + let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The buffer-specific variable can have funcrefs): + let b:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull 'abc123' + +Execute(The global variable can be a dictionary): + let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The global variable can have funcrefs): + let g:ale_lsp_root = {'clangd': function('Hook1'), 'golangserver': '/path'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull 'abc123' + +Execute(The buffer-specific variable overrides the global variable): + let b:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/other/path'} + let g:ale_lsp_root = {'clangd': '/not/this/path', 'golangserver': '/elsewhere'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + +Execute(The global variable is queried if the buffer-specific has no value): + let b:ale_lsp_root = {'golangserver': '/other/path'} + let g:ale_lsp_root = {'clangd': '/some/path', 'golangserver': '/elsewhere'} + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '/some/path' + + +Execute(The default hook value is acceptable): + call ale#test#SetFilename('other-file.c') + + AssertLSPProjectFull '' diff --git a/test/lsp/test_read_lsp_diagnostics.vader b/test/lsp/test_read_lsp_diagnostics.vader index a5c5ded3..c197e0c6 100644 --- a/test/lsp/test_read_lsp_diagnostics.vader +++ b/test/lsp/test_read_lsp_diagnostics.vader @@ -17,7 +17,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle errors): \ 'lnum': 3, \ 'col': 11, \ 'end_lnum': 5, - \ 'end_col': 16, + \ 'end_col': 15, \ 'code': 'some-error', \ } \ ], @@ -38,7 +38,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle warnings): \ 'lnum': 2, \ 'col': 4, \ 'end_lnum': 2, - \ 'end_col': 4, + \ 'end_col': 3, \ 'code': 'some-warning', \ } \ ], @@ -59,7 +59,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing se \ 'lnum': 3, \ 'col': 11, \ 'end_lnum': 5, - \ 'end_col': 16, + \ 'end_col': 15, \ 'code': 'some-error', \ } \ ], @@ -79,7 +79,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes) \ 'lnum': 3, \ 'col': 11, \ 'end_lnum': 5, - \ 'end_col': 16, + \ 'end_col': 15, \ } \ ], \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ @@ -98,7 +98,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should include sources in detail): \ 'lnum': 10, \ 'col': 15, \ 'end_lnum': 12, - \ 'end_col': 23, + \ 'end_col': 22, \ } \ ], \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ @@ -117,7 +117,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should consider -1 to be a meaningles \ 'lnum': 3, \ 'col': 11, \ 'end_lnum': 5, - \ 'end_col': 16, + \ 'end_col': 15, \ } \ ], \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ @@ -136,7 +136,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages): \ 'lnum': 1, \ 'col': 3, \ 'end_lnum': 1, - \ 'end_col': 3, + \ 'end_col': 2, \ }, \ { \ 'type': 'W', @@ -144,7 +144,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages): \ 'lnum': 2, \ 'col': 5, \ 'end_lnum': 2, - \ 'end_col': 5, + \ 'end_col': 4, \ }, \ ], \ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [ @@ -167,7 +167,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det \ 'lnum': 1, \ 'col': 3, \ 'end_lnum': 1, - \ 'end_col': 3, + \ 'end_col': 2, \ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:43:80:\n\tmight be this" \ } \ ], diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index 325c2aa8..29c19b8e 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -97,6 +97,7 @@ Before: \ 'let g:ale_list_vertical = 0', \ 'let g:ale_list_window_size = 10', \ 'let g:ale_loclist_msg_format = ''%code: %%s''', + \ 'let g:ale_lsp_root = {}', \ 'let g:ale_max_buffer_history_size = 20', \ 'let g:ale_max_signs = -1', \ 'let g:ale_maximum_file_size = 0', diff --git a/test/test_c_flag_parsing.vader b/test/test_c_flag_parsing.vader index dbaf6b73..340f3ccf 100644 --- a/test/test_c_flag_parsing.vader +++ b/test/test_c_flag_parsing.vader @@ -14,14 +14,25 @@ Execute(The CFlags parser should be able to parse include directives): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')), + \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'), \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c']) + AssertEqual + \ '-isystem ' . '/usr/include/dir', + \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -isystem /usr/include/dir -c file.c']) + +Execute(ParseCFlags should ignore -c and -o): + call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') + + AssertEqual + \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'), + \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c -o a.out']) + Execute(The CFlags parser should be able to parse macro directives): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') \ . ' -DTEST=1', \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=1 -c file.c']) @@ -29,7 +40,7 @@ Execute(The CFlags parser should be able to parse macro directives with spaces): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') \ . ' -DTEST=$(( 2 * 4 ))', \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=$(( 2 * 4 )) -c file.c']) @@ -37,14 +48,14 @@ Execute(The CFlags parser should be able to parse shell directives with spaces): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=`date +%s` -c file.c']) Execute(ParseCFlags should be able to parse flags with relative paths): AssertEqual - \ ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), @@ -56,8 +67,8 @@ Execute(ParseCFlags should be able to parse flags with relative paths): Execute(ParseCFlags should be able to parse -Dgoal): AssertEqual \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), @@ -66,29 +77,16 @@ Execute(ParseCFlags should be able to parse -Dgoal): \ . ' -DTEST=`date +%s` -c file.c' \ ) -Execute(ParseCFlags should ignore -T and other arguments): - AssertEqual - \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) - \ . ' -DTEST=`date +%s`', - \ ale#c#ParseCFlags( - \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir --sysroot=subdir ' - \ . '-I'. ale#path#Simplify('kernel/include') - \ . ' -DTEST=`date +%s` -c file.c' - \ ) - Execute(ParseCFlags should handle paths with spaces in double quotes): AssertEqual \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/"dir with spaces"') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ 'gcc -Dgoal=9 -Isubdir ' \ . '-I"dir with spaces"' . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) @@ -96,29 +94,28 @@ Execute(ParseCFlags should handle paths with spaces in double quotes): Execute(ParseCFlags should handle paths with spaces in single quotes): AssertEqual \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. "/test_c_projects/makefile_project/'dir with spaces'") + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' - \ . '-I''dir with spaces''' . ' -I'. ale#path#Simplify('kernel/include') + \ 'gcc -Dgoal=9 -Isubdir ' + \ . "-I'dir with spaces'" . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) Execute(ParseCFlags should handle paths with minuses): AssertEqual \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' - \ . '-I''dir with spaces''' . ' -Idir-with-dash' + \ 'gcc -Dgoal=9 -Isubdir ' + \ . ' -Idir-with-dash' \ . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) @@ -126,17 +123,14 @@ Execute(ParseCFlags should handle paths with minuses): Execute(ParseCFlags should handle -D with minuses): AssertEqual \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') \ . ' -Dmacro-with-dash' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ 'gcc -Dgoal=9 -Isubdir ' \ . '-Dmacro-with-dash ' - \ . '-I''dir with spaces''' . ' -Idir-with-dash' \ . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) @@ -144,16 +138,11 @@ Execute(ParseCFlags should handle -D with minuses): Execute(ParseCFlags should handle flags at the end of the line): AssertEqual \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' -Dmacro-with-dash' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')), + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'), \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' - \ . '-Dmacro-with-dash ' - \ . '-I''dir with spaces''' . ' -Idir-with-dash' + \ 'gcc -Dgoal=9 -Isubdir ' \ . ' -I'. ale#path#Simplify('kernel/include') \ ) @@ -167,14 +156,26 @@ Execute(ParseCompileCommandsFlags should parse some basic flags): noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) AssertEqual - \ '-I' . ale#path#Simplify('/usr/include/xmms2'), + \ '-I' . '/usr/include/xmms2', \ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [ \ { - \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), - \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') + \ 'directory': '/foo/bar/xmms2-mpris', + \ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2' \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' - \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), - \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', + \ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', + \ }, + \ ] }, {}) + +Execute(ParseCompileCommandsFlags should tolerate items without commands): + noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) + + AssertEqual + \ '', + \ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [ + \ { + \ 'directory': '/foo/bar/xmms2-mpris', + \ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', \ }, \ ] }, {}) @@ -182,40 +183,23 @@ Execute(ParseCompileCommandsFlags should fall back to files in the same director noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) AssertEqual - \ '-I' . ale#path#Simplify('/usr/include/xmms2'), + \ '-I' . '/usr/include/xmms2', \ ale#c#ParseCompileCommandsFlags(bufnr(''), {}, { "src": [ \ { - \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), - \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') + \ 'directory': '/foo/bar/xmms2-mpris', + \ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2' \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' - \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), - \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), + \ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', + \ 'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c', \ }, \ ] }) -Execute(ParseCFlags should not merge flags): - AssertEqual - \ '-Dgoal=9' - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) - \ . ' ' . ale#Escape('-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')), - \ ale#c#ParseCFlags( - \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' - \ . 'subdir/somedep1.o ' . 'subdir/somedep2.o ' - \ . '-I''dir with spaces''' . ' -Idir-with-dash ' - \ . 'subdir/somedep3.o ' . 'subdir/somedep4.o ' - \ . ' -I'. ale#path#Simplify('kernel/include') . ' ' - \ . 'subdir/somedep5.o ' . 'subdir/somedep6.o ' - \ ) - Execute(ParseCFlags should handle parenthesis and quotes): AssertEqual - \ '-Dgoal=9 -Dtest1="('' '')" -Dtest2=''(` `)'' -Dtest3=`(" ")`', + \ '-Dgoal=9 -Dtest1="('' '')" file1.o -Dtest2=''(` `)'' file2.o -Dtest3=`(" ")` file3.o', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla ' + \ 'gcc -Dgoal=9 ' \ . '-Dtest1="('' '')" file1.o ' \ . '-Dtest2=''(` `)'' file2.o ' \ . '-Dtest3=`(" ")` file3.o ' diff --git a/test/test_filetype_linter_defaults.vader b/test/test_filetype_linter_defaults.vader index 4f190226..af028041 100644 --- a/test/test_filetype_linter_defaults.vader +++ b/test/test_filetype_linter_defaults.vader @@ -61,7 +61,7 @@ Execute(The defaults for the zsh filetype should be correct): Execute(The defaults for the verilog filetype should be correct): " This filetype isn't configured with default, so we can test loading all " available linters with this. - AssertEqual ['iverilog', 'verilator'], GetLinterNames('verilog') + AssertEqual ['iverilog', 'verilator', 'vlog', 'xvlog'], GetLinterNames('verilog') let g:ale_linters_explicit = 1 diff --git a/test/test_find_references.vader b/test/test_find_references.vader index 14b5e37b..d31424ef 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -8,6 +8,7 @@ Before: let g:message_list = [] let g:preview_called = 0 let g:item_list = [] + let g:options = {} let g:capability_checked = '' let g:conn_id = v:null let g:WaitCallback = v:null @@ -48,9 +49,10 @@ Before: call add(g:expr_list, a:expr) endfunction - function! ale#preview#ShowSelection(item_list) abort + function! ale#preview#ShowSelection(item_list, options) abort let g:preview_called = 1 let g:item_list = a:item_list + let g:options = a:options endfunction After: @@ -70,6 +72,7 @@ After: unlet! g:message_list unlet! g:expr_list unlet! b:ale_linters + unlet! g:options unlet! g:item_list unlet! g:preview_called @@ -180,7 +183,17 @@ Execute(tsserver reference requests should be sent): AssertEqual \ [[0, 'ts@references', {'file': expand('%:p'), 'line': 2, 'offset': 5}]], \ g:message_list - AssertEqual {'42': {}}, ale#references#GetMap() + AssertEqual {'42': {'use_relative_paths': 0}}, ale#references#GetMap() + +Execute('-relative' argument should enable 'use_relative_paths' in HandleTSServerResponse): + runtime ale_linters/typescript/tsserver.vim + call setpos('.', [bufnr(''), 2, 5, 0]) + + ALEFindReferences -relative + + call call(g:WaitCallback, [g:conn_id, '/foo/bar']) + + AssertEqual {'42': {'use_relative_paths': 1}}, ale#references#GetMap() Given python(Some Python file): foo @@ -270,10 +283,21 @@ Execute(LSP reference requests should be sent): \ }], \ [0, 'textDocument/references', { \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, - \ 'position': {'line': 0, 'character': 3}, + \ 'position': {'line': 0, 'character': 2}, \ 'context': {'includeDeclaration': v:false}, \ }], \ ], \ g:message_list - AssertEqual {'42': {}}, ale#references#GetMap() + AssertEqual {'42': {'use_relative_paths': 0}}, ale#references#GetMap() + +Execute('-relative' argument should enable 'use_relative_paths' in HandleLSPResponse): + runtime ale_linters/python/pyls.vim + let b:ale_linters = ['pyls'] + call setpos('.', [bufnr(''), 1, 5, 0]) + + ALEFindReferences -relative + + call call(g:WaitCallback, [g:conn_id, '/foo/bar']) + + AssertEqual {'42': {'use_relative_paths': 1}}, ale#references#GetMap() diff --git a/test/test_format_command.vader b/test/test_format_command.vader index 119c7138..15435326 100644 --- a/test/test_format_command.vader +++ b/test/test_format_command.vader @@ -8,7 +8,9 @@ Before: AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t') endfunction - function! TestCreateFunc(buffer, temporary_file) abort + runtime autoload/ale/command.vim + + function! ale#command#CreateTempFile(buffer, temporary_file, input) abort return !empty(a:temporary_file) endfunction @@ -17,17 +19,18 @@ After: unlet! g:match delfunction CheckTempFile - delfunction TestCreateFunc + + runtime autoload/ale/command.vim Execute(FormatCommand should do nothing to basic command strings): AssertEqual \ ['', 'awesome-linter do something', 0], - \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, v:null) Execute(FormatCommand should handle %%, and ignore other percents): AssertEqual \ ['', '% %%d %%f %x %', 0], - \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, v:null) Execute(FormatCommand should convert %s to the current filename): AssertEqual @@ -36,10 +39,10 @@ Execute(FormatCommand should convert %s to the current filename): \ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')), \ 0, \ ], - \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, v:null) Execute(FormatCommand should convert %t to a new temporary filename): - let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, function('TestCreateFunc')) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:null) call CheckTempFile(g:result[0]) @@ -52,17 +55,22 @@ Execute(FormatCommand should convert %t to a new temporary filename): " The two temporary filenames formatted in should be the same. AssertEqual g:match[1], g:match[2] +Execute(FormatCommand should not convert %t to a new temporary filename when the input is given as v:false): + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, v:false) + + AssertEqual ['', 'foo %t bar %t', 0], g:result + Execute(FormatCommand should signal that files are created when temporary files are needed): AssertEqual \ 1, - \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, function('TestCreateFunc'))[2] + \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, v:null)[2] AssertEqual \ 0, - \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, function('TestCreateFunc'))[2] + \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, v:null)[2] Execute(FormatCommand should let you combine %s and %t): - let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, function('TestCreateFunc')) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, v:null) call CheckTempFile(g:result[0]) @@ -79,30 +87,30 @@ Execute(FormatCommand should replace %e with the escaped executable): if has('win32') AssertEqual \ ['', 'foo foo', 0], - \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null) AssertEqual \ ['', '"foo bar"', 0], - \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null) AssertEqual \ ['', '%e %e', 0], - \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null) else AssertEqual \ ['', '''foo'' ''foo''', 0], - \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, v:null) AssertEqual \ ['', '''foo bar''', 0], - \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, v:null) AssertEqual \ ['', '%e %e', 0], - \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc')) + \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, v:null) endif Execute(EscapeCommandPart should escape all percent signs): AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%') Execute(EscapeCommandPart should pipe in temporary files appropriately): - let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, function('TestCreateFunc')) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, v:null) call CheckTempFile(g:result[0]) @@ -110,7 +118,7 @@ Execute(EscapeCommandPart should pipe in temporary files appropriately): Assert !empty(g:match), 'No match found! Result was: ' . g:result[1] AssertEqual ale#Escape(g:result[0]), g:match[1] - let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, function('TestCreateFunc')) + let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, v:null) call CheckTempFile(g:result[0]) diff --git a/test/test_go_to_definition.vader b/test/test_go_to_definition.vader index 4e4e2552..3cc2a58c 100644 --- a/test/test_go_to_definition.vader +++ b/test/test_go_to_definition.vader @@ -196,7 +196,7 @@ Execute(Other files should be jumped to for definition responses in vsplits too) AssertEqual [3, 7], getpos('.')[1:2] AssertEqual {}, ale#definition#GetMap() -Execute(tsserver completion requests should be sent): +Execute(tsserver definition requests should be sent): runtime ale_linters/typescript/tsserver.vim call setpos('.', [bufnr(''), 2, 5, 0]) @@ -217,7 +217,7 @@ Execute(tsserver completion requests should be sent): \ g:message_list AssertEqual {'42': {'open_in': 'current-buffer'}}, ale#definition#GetMap() -Execute(tsserver tab completion requests should be sent): +Execute(tsserver tab definition requests should be sent): runtime ale_linters/typescript/tsserver.vim call setpos('.', [bufnr(''), 2, 5, 0]) @@ -348,7 +348,7 @@ Execute(Definition responses with null response should be handled): AssertEqual [], g:expr_list -Execute(LSP completion requests should be sent): +Execute(LSP definition requests should be sent): runtime ale_linters/python/pyls.vim let b:ale_linters = ['pyls'] call setpos('.', [bufnr(''), 1, 5, 0]) @@ -377,14 +377,50 @@ Execute(LSP completion requests should be sent): \ }], \ [0, 'textDocument/definition', { \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, - \ 'position': {'line': 0, 'character': 3}, + \ 'position': {'line': 0, 'character': 2}, \ }], \ ], \ g:message_list AssertEqual {'42': {'open_in': 'current-buffer'}}, ale#definition#GetMap() -Execute(LSP tab completion requests should be sent): +Execute(LSP type definition requests should be sent): + runtime ale_linters/python/pyls.vim + let b:ale_linters = ['pyls'] + call setpos('.', [bufnr(''), 1, 5, 0]) + + ALEGoToTypeDefinition + + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'typeDefinition', g:capability_checked + call call(g:WaitCallback, [g:conn_id, '/foo/bar']) + + AssertEqual + \ 'function(''ale#definition#HandleLSPResponse'')', + \ string(g:Callback) + + AssertEqual + \ [ + \ [1, 'textDocument/didChange', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'version': g:ale_lsp_next_version_id - 1, + \ }, + \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}] + \ }], + \ [0, 'textDocument/typeDefinition', { + \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, + \ 'position': {'line': 0, 'character': 2}, + \ }], + \ ], + \ g:message_list + + AssertEqual {'42': {'open_in': 'current-buffer'}}, ale#definition#GetMap() + +Execute(LSP tab definition requests should be sent): runtime ale_linters/python/pyls.vim let b:ale_linters = ['pyls'] call setpos('.', [bufnr(''), 1, 5, 0]) @@ -413,7 +449,43 @@ Execute(LSP tab completion requests should be sent): \ }], \ [0, 'textDocument/definition', { \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, - \ 'position': {'line': 0, 'character': 3}, + \ 'position': {'line': 0, 'character': 2}, + \ }], + \ ], + \ g:message_list + + AssertEqual {'42': {'open_in': 'tab'}}, ale#definition#GetMap() + +Execute(LSP tab type definition requests should be sent): + runtime ale_linters/python/pyls.vim + let b:ale_linters = ['pyls'] + call setpos('.', [bufnr(''), 1, 5, 0]) + + ALEGoToTypeDefinitionInTab + + " We shouldn't register the callback yet. + AssertEqual '''''', string(g:Callback) + + AssertEqual type(function('type')), type(g:WaitCallback) + AssertEqual 'typeDefinition', g:capability_checked + call call(g:WaitCallback, [g:conn_id, '/foo/bar']) + + AssertEqual + \ 'function(''ale#definition#HandleLSPResponse'')', + \ string(g:Callback) + + AssertEqual + \ [ + \ [1, 'textDocument/didChange', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('%:p')), + \ 'version': g:ale_lsp_next_version_id - 1, + \ }, + \ 'contentChanges': [{'text': join(getline(1, '$'), "\n") . "\n"}] + \ }], + \ [0, 'textDocument/typeDefinition', { + \ 'textDocument': {'uri': ale#path#ToURI(expand('%:p'))}, + \ 'position': {'line': 0, 'character': 2}, \ }], \ ], \ g:message_list diff --git a/test/test_ignoring_linters.vader b/test/test_ignoring_linters.vader index 866f9e0d..32eae954 100644 --- a/test/test_ignoring_linters.vader +++ b/test/test_ignoring_linters.vader @@ -242,7 +242,7 @@ Execute(Buffer ignore lists should be applied for LSP linters): \ 'lnum': 1, \ 'col': 10, \ 'type': 'E', - \ 'end_col': 10, + \ 'end_col': 9, \ 'end_lnum': 1, \ 'text': 'x', \ } diff --git a/test/test_sandbox_execution.vader b/test/test_sandbox_execution.vader index 5a4974ba..cf994ce8 100644 --- a/test/test_sandbox_execution.vader +++ b/test/test_sandbox_execution.vader @@ -59,7 +59,7 @@ Execute(ALE shouldn't blow up if file cleanup happens in a sandbox): \ 'temporary_file_list': ['/tmp/foo'], \ 'temporary_directory_list': ['/tmp/bar'], \} - sandbox call ale#engine#RemoveManagedFiles(3) + sandbox call ale#command#RemoveManagedFiles(3) AssertEqual ['/tmp/foo'], g:ale_buffer_info[3].temporary_file_list AssertEqual ['/tmp/bar'], g:ale_buffer_info[3].temporary_directory_list diff --git a/test/test_semver_utils.vader b/test/test_semver_utils.vader index 30e9e818..cd0381dd 100644 --- a/test/test_semver_utils.vader +++ b/test/test_semver_utils.vader @@ -17,6 +17,10 @@ Execute(GetVersion should cache the version): AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', ['Version 3.4.7']) AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', []) +Execute(GetVersion should tolerate missing patch numbers): + " This goes against the semver spec, but we handle it anyway. + AssertEqual [3, 4, 0], ale#semver#GetVersion('dummy', ['Version 3.4']) + Execute(HasVersion should return 1 when the version has been cached): call ale#semver#GetVersion('dummy', []) AssertEqual 0, ale#semver#HasVersion('dummy') diff --git a/test/test_shell_detection.vader b/test/test_shell_detection.vader index adb8d70d..88ee462d 100644 --- a/test/test_shell_detection.vader +++ b/test/test_shell_detection.vader @@ -52,11 +52,27 @@ Execute(zsh should be detected appropriately): Given(A file with a csh hash bang and arguments): #!/usr/bin/env csh -eu --foobar -Execute(zsh should be detected appropriately): +Execute(csh should be detected appropriately): AssertEqual 'csh', ale#handlers#sh#GetShellType(bufnr('')) AssertEqual 'csh', ale_linters#sh#shell#GetExecutable(bufnr('')) AssertEqual 'csh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr('')) +Given(A file with a ksh hashbang): + #!/bin/ksh + +Execute(/bin/ksh should be detected appropriately): + AssertEqual 'ksh', ale#handlers#sh#GetShellType(bufnr('')) + AssertEqual 'ksh', ale_linters#sh#shell#GetExecutable(bufnr('')) + AssertEqual 'ksh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr('')) + +Given(A file with a ksh as an argument to env): + #!/usr/bin/env ksh + +Execute(ksh should be detected appropriately): + AssertEqual 'ksh', ale#handlers#sh#GetShellType(bufnr('')) + AssertEqual 'ksh', ale_linters#sh#shell#GetExecutable(bufnr('')) + AssertEqual 'ksh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr('')) + Given(A file with a sh hash bang and arguments): #!/usr/bin/env sh -eu --foobar diff --git a/test/test_temporary_file_management.vader b/test/test_temporary_file_management.vader index 4847706a..b25da7ac 100644 --- a/test/test_temporary_file_management.vader +++ b/test/test_temporary_file_management.vader @@ -13,21 +13,21 @@ Before: " We are registering a temporary file, so we should delete it. let g:filename = tempname() call writefile(['foo'], g:filename) - call ale#engine#ManageFile(a:buffer, g:filename) + call ale#command#ManageFile(a:buffer, g:filename) " We are registering this directory appropriately, so we should delete " the whole thing. let g:directory = tempname() call mkdir(g:directory) call writefile(['foo'], g:directory . '/bar') - call ale#engine#ManageDirectory(a:buffer, g:directory) + call ale#command#ManageDirectory(a:buffer, g:directory) " We are registering this directory as temporary file, so we " shouldn't delete it. let g:preserved_directory = tempname() call mkdir(g:preserved_directory) call writefile(['foo'], g:preserved_directory . '/bar') - call ale#engine#ManageFile(a:buffer, g:preserved_directory) + call ale#command#ManageFile(a:buffer, g:preserved_directory) return g:command endfunction @@ -42,6 +42,7 @@ Before: \ 'callback': 'TestCallback', \ 'command_callback': 'TestCommandCallback', \}) + call ale#command#ClearData() After: Restore @@ -58,6 +59,7 @@ After: delfunction TestCommandCallback delfunction TestCallback call ale#linter#Reset() + call ale#command#ClearData() Given foobar (Some imaginary filetype): foo @@ -95,11 +97,11 @@ Execute(ALE should delete managed files when the buffer is removed): Assert !isdirectory(g:directory), 'The temporary directory was not deleted' Assert isdirectory(g:preserved_directory), 'The tempoary directory was not kept' -Execute(ALE should create and delete directories for ale#engine#CreateDirectory()): +Execute(ALE should create and delete directories for ale#command#CreateDirectory()): call ale#engine#InitBufferInfo(bufnr('%')) - let b:dir = ale#engine#CreateDirectory(bufnr('%')) - let b:dir2 = ale#engine#CreateDirectory(bufnr('%')) + let b:dir = ale#command#CreateDirectory(bufnr('%')) + let b:dir2 = ale#command#CreateDirectory(bufnr('%')) Assert isdirectory(b:dir), 'The directory was not created' @@ -117,16 +119,26 @@ Execute(ALE should create and delete directories for ale#engine#CreateDirectory( Assert !isdirectory(b:dir), 'The directory was not deleted' Assert !isdirectory(b:dir2), 'The second directory was not deleted' -Execute(ale#engine#ManageFile should add the file even if the buffer info hasn't be set yet): - let g:ale_buffer_info = {} - call ale#engine#ManageFile(bufnr(''), '/foo/bar') +Execute(ale#command#ManageFile should add the file even if the buffer info hasn't be set yet): + call ale#command#ManageFile(bufnr(''), '/foo/bar') + AssertEqual - \ ['/foo/bar'], - \ g:ale_buffer_info[bufnr('')].temporary_file_list + \ { + \ bufnr(''): { + \ 'file_list': ['/foo/bar'], + \ 'directory_list': [], + \ }, + \ }, + \ ale#command#GetData() + +Execute(ale#command#ManageDirectory should add the directory even if the buffer info hasn't be set yet): + call ale#command#ManageDirectory(bufnr(''), '/foo/bar') -Execute(ale#engine#ManageDirectory should add the directory even if the buffer info hasn't be set yet): - let g:ale_buffer_info = {} - call ale#engine#ManageDirectory(bufnr(''), '/foo/bar') AssertEqual - \ ['/foo/bar'], - \ g:ale_buffer_info[bufnr('')].temporary_directory_list + \ { + \ bufnr(''): { + \ 'file_list': [], + \ 'directory_list': ['/foo/bar'], + \ }, + \ }, + \ ale#command#GetData() |