summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/command_callback/test_cargo_command_callbacks.vader48
-rw-r--r--test/command_callback/test_cpp_clangcheck_command_callbacks.vader9
-rw-r--r--test/command_callback/test_haskell_ghc_command_callbacks.vader23
-rw-r--r--test/command_callback/test_proto_command_callback.vader11
-rw-r--r--test/handler/test_mypy_handler.vader30
-rw-r--r--test/lsp/test_did_save_event.vader108
-rw-r--r--test/smoke_test.vader62
-rw-r--r--test/test_history_saving.vader4
-rw-r--r--test/test_prepare_command.vader4
-rw-r--r--test/test_wrap_comand.vader2
10 files changed, 290 insertions, 11 deletions
diff --git a/test/command_callback/test_cargo_command_callbacks.vader b/test/command_callback/test_cargo_command_callbacks.vader
index 65ea5a80..9c06f27d 100644
--- a/test/command_callback/test_cargo_command_callbacks.vader
+++ b/test/command_callback/test_cargo_command_callbacks.vader
@@ -1,9 +1,13 @@
Before:
Save g:ale_rust_cargo_use_check
Save g:ale_rust_cargo_check_all_targets
+ Save g:ale_rust_cargo_default_feature_behavior
+ Save g:ale_rust_cargo_include_features
unlet! g:ale_rust_cargo_use_check
unlet! g:ale_cargo_check_all_targets
+ unlet! g:ale_rust_cargo_default_feature_behavior
+ unlet! g:ale_rust_cargo_include_features
runtime ale_linters/rust/cargo.vim
call ale#test#SetDirectory('/testplugin/test/command_callback')
@@ -114,3 +118,47 @@ Execute(--all-targets should be used when g:ale_rust_cargo_check_all_targets is
\ ale_linters#rust#cargo#GetCommand(bufnr(''), [])
AssertEqual '', ale_linters#rust#cargo#VersionCheck(bufnr(''))
+
+Execute(--no-default-features should be used when g:ale_rust_cargo_default_feature_behavior is none):
+ let g:ale_rust_cargo_default_feature_behavior = 'none'
+
+ AssertEqual
+ \ 'cargo check' . g:suffix . ' --no-default-features',
+ \ ale_linters#rust#cargo#GetCommand(bufnr(''), [
+ \ 'cargo 0.22.0 (3423351a5 2017-10-06)',
+ \ ])
+
+Execute(g:ale_rust_cargo_include_features added when g:ale_rust_cargo_default_feature_behavior is none):
+ let g:ale_rust_cargo_default_feature_behavior = 'none'
+ let g:ale_rust_cargo_include_features = 'foo bar'
+
+ AssertEqual
+ \ 'cargo check' . g:suffix . ' --no-default-features --features ' .
+ \ (fnamemodify(&shell, ':t') is? 'cmd.exe' ? '"foo bar"' : "'foo bar'"),
+ \ ale_linters#rust#cargo#GetCommand(bufnr(''), [
+ \ 'cargo 0.22.0 (3423351a5 2017-10-06)',
+ \ ])
+
+Execute(g:ale_rust_cargo_include_features added and escaped):
+ let g:ale_rust_cargo_default_feature_behavior = 'default'
+ let g:ale_rust_cargo_include_features = "foo bar baz"
+
+ AssertEqual
+ \ 'cargo check' . g:suffix . ' --features ' .
+ \ (fnamemodify(&shell, ':t') is? 'cmd.exe' ? '"foo bar baz"' : "'foo bar baz'"),
+ \ ale_linters#rust#cargo#GetCommand(bufnr(''), [
+ \ 'cargo 0.22.0 (3423351a5 2017-10-06)',
+ \ ])
+
+Execute(--all-features should be used when g:ale_rust_cargo_default_feature_behavior is all):
+ let g:ale_rust_cargo_default_feature_behavior = 'all'
+
+ " When all features are enabled we should ignore extra features to add
+ " since it won't do anything
+ let g:ale_rust_cargo_include_features = 'foo bar'
+
+ AssertEqual
+ \ 'cargo check' . g:suffix . ' --all-features',
+ \ ale_linters#rust#cargo#GetCommand(bufnr(''), [
+ \ 'cargo 0.22.0 (3423351a5 2017-10-06)',
+ \ ])
diff --git a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader
index 34b87fc6..f708c52d 100644
--- a/test/command_callback/test_cpp_clangcheck_command_callbacks.vader
+++ b/test/command_callback/test_cpp_clangcheck_command_callbacks.vader
@@ -28,7 +28,7 @@ Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('clang-check')
\ . ' -analyze %s'
- \ . ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text',
+ \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text',
\ ale_linters#cpp#clangcheck#GetCommand(bufnr(''))
let b:ale_cpp_clangcheck_executable = 'foobar'
@@ -38,7 +38,7 @@ Execute(The executable should be used in the command):
AssertEqual
\ ale#Escape('foobar')
\ . ' -analyze %s'
- \ . ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text',
+ \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text',
\ ale_linters#cpp#clangcheck#GetCommand(bufnr(''))
Execute(The options should be configurable):
@@ -46,8 +46,9 @@ Execute(The options should be configurable):
AssertEqual
\ ale#Escape('clang-check')
- \ . ' -analyze %s --something'
- \ . ' -extra-arg -Xanalyzer -extra-arg -analyzer-output=text',
+ \ . ' -analyze %s'
+ \ . ' -extra-arg -Xclang -extra-arg -analyzer-output=text'
+ \ . ' --something',
\ ale_linters#cpp#clangcheck#GetCommand(bufnr(''))
Execute(The build directory should be used when set):
diff --git a/test/command_callback/test_haskell_ghc_command_callbacks.vader b/test/command_callback/test_haskell_ghc_command_callbacks.vader
new file mode 100644
index 00000000..edaf2b98
--- /dev/null
+++ b/test/command_callback/test_haskell_ghc_command_callbacks.vader
@@ -0,0 +1,23 @@
+Before:
+ Save g:ale_haskell_ghc_options
+
+ unlet! g:ale_haskell_ghc_options
+ unlet! b:ale_haskell_ghc_options
+
+ runtime ale_linters/haskell/ghc.vim
+
+After:
+ Restore
+ unlet! b:ale_haskell_ghc_options
+ call ale#linter#Reset()
+
+Execute(The options should be used in the command):
+ AssertEqual
+ \ 'ghc -fno-code -v0 %t',
+ \ ale_linters#haskell#ghc#GetCommand(bufnr(''))
+
+ let b:ale_haskell_ghc_options = 'foobar'
+
+ AssertEqual
+ \ 'ghc foobar %t',
+ \ ale_linters#haskell#ghc#GetCommand(bufnr(''))
diff --git a/test/command_callback/test_proto_command_callback.vader b/test/command_callback/test_proto_command_callback.vader
index 2fd7775e..76050c61 100644
--- a/test/command_callback/test_proto_command_callback.vader
+++ b/test/command_callback/test_proto_command_callback.vader
@@ -1,14 +1,21 @@
Before:
- call ale#test#SetDirectory('/testplugin/test/command_callback')
call ale#test#SetFilename('test.proto')
After:
Restore
- call ale#test#RestoreDirectory()
+ unlet! b:ale_proto_protoc_gen_lint_options
+
call ale#linter#Reset()
Execute(The default command should be correct):
AssertEqual
\ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --lint_out=. ' . '%s',
\ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr(''))
+
+Execute(The callback should include any additional options):
+ let b:ale_proto_protoc_gen_lint_options = '--some-option'
+
+ AssertEqual
+ \ 'protoc' . ' -I ' . ale#Escape(getcwd()) . ' --some-option --lint_out=. ' . '%s',
+ \ ale_linters#proto#protoc_gen_lint#GetCommand(bufnr(''))
diff --git a/test/handler/test_mypy_handler.vader b/test/handler/test_mypy_handler.vader
index abb8504a..f3d4cbf8 100644
--- a/test/handler/test_mypy_handler.vader
+++ b/test/handler/test_mypy_handler.vader
@@ -1,9 +1,15 @@
Before:
+ Save g:ale_python_mypy_ignore_invalid_syntax
+
+ unlet! g:ale_python_mypy_ignore_invalid_syntax
+
runtime ale_linters/python/mypy.vim
call ale#test#SetDirectory('/testplugin/test/handler')
After:
+ Restore
+
call ale#test#RestoreDirectory()
call ale#linter#Reset()
@@ -80,3 +86,27 @@ Execute(The mypy handler should handle Windows names with spaces):
\ ale_linters#python#mypy#Handle(bufnr(''), [
\ 'C:\something\with spaces.py:4: error: No library stub file for module ''django.db''',
\ ])
+
+Execute(The mypy syntax errors shouldn't be ignored by default):
+ AssertEqual
+ \ [
+ \ {
+ \ 'lnum': 4,
+ \ 'col': 0,
+ \ 'filename': ale#path#Simplify(g:dir . '/foo.py'),
+ \ 'type': 'E',
+ \ 'text': 'invalid syntax',
+ \ },
+ \ ],
+ \ ale_linters#python#mypy#Handle(bufnr(''), [
+ \ 'foo.py:4: error: invalid syntax',
+ \ ])
+
+Execute(The mypy syntax errors should be ignored when the option is on):
+ let g:ale_python_mypy_ignore_invalid_syntax = 1
+
+ AssertEqual
+ \ [],
+ \ ale_linters#python#mypy#Handle(bufnr(''), [
+ \ 'foo.py:4: error: invalid syntax',
+ \ ])
diff --git a/test/lsp/test_did_save_event.vader b/test/lsp/test_did_save_event.vader
new file mode 100644
index 00000000..042a3ce2
--- /dev/null
+++ b/test/lsp/test_did_save_event.vader
@@ -0,0 +1,108 @@
+Before:
+ Save g:ale_lint_on_save
+ Save g:ale_enabled
+ Save g:ale_linters
+ Save g:ale_run_synchronously
+
+ call ale#test#SetDirectory('/testplugin/test/completion')
+ call ale#test#SetFilename('dummy.txt')
+
+ runtime autoload/ale/lsp.vim
+
+ let g:ale_lint_on_save = 1
+ let b:ale_enabled = 1
+ let g:ale_lsp_next_message_id = 1
+ let g:ale_run_synchronously = 1
+ let g:message_list = []
+ let g:Callback = ''
+
+ function! LanguageCallback() abort
+ return 'foobar'
+ endfunction
+
+ function! ProjectRootCallback() abort
+ return expand('.')
+ endfunction
+
+ call ale#linter#Define('foobar', {
+ \ 'name': 'dummy_linter',
+ \ 'lsp': 'stdio',
+ \ 'command': 'cat - > /dev/null',
+ \ 'executable': has('win32') ? 'cmd' : 'echo',
+ \ 'language_callback': 'LanguageCallback',
+ \ 'project_root_callback': 'ProjectRootCallback',
+ \ })
+ let g:ale_linters = {'foobar': ['dummy_linter']}
+
+ function! ale#linter#StartLSP(buffer, linter, callback) abort
+ let g:Callback = a:callback
+
+ return {
+ \ 'connection_id': 347,
+ \ 'project_root': '/foo/bar',
+ \}
+ endfunction
+
+ " Replace the Send function for LSP, so we can monitor calls to it.
+ function! ale#lsp#Send(conn_id, message, ...) abort
+ call add(g:message_list, a:message)
+ endfunction
+
+After:
+ Restore
+
+ unlet! b:ale_enabled
+ unlet! b:ale_linters
+ unlet! g:Callback
+ unlet! g:message_list
+
+ delfunction LanguageCallback
+ delfunction ProjectRootCallback
+
+ call ale#test#RestoreDirectory()
+ call ale#linter#Reset()
+
+ " Stop any timers we left behind.
+ " This stops the tests from failing randomly.
+ call ale#completion#StopTimer()
+
+ runtime autoload/ale/completion.vim
+ runtime autoload/ale/lsp.vim
+
+Given foobar (Some imaginary filetype):
+ <contents>
+
+Execute(Server should be notified on save):
+ call ale#events#SaveEvent(bufnr(''))
+
+ 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"}],
+ \ }],
+ \ [1, 'textDocument/didSave', {
+ \ 'textDocument': {
+ \ 'uri': ale#path#ToURI(expand('%:p')),
+ \ },
+ \ }],
+ \ ],
+ \ g:message_list
+
+Execute(Server should be notified on change):
+ call ale#events#FileChangedEvent(bufnr(''))
+
+ 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"}],
+ \ }],
+ \ ],
+ \ g:message_list
diff --git a/test/smoke_test.vader b/test/smoke_test.vader
index 7635cbd9..f6d0be56 100644
--- a/test/smoke_test.vader
+++ b/test/smoke_test.vader
@@ -1,6 +1,7 @@
Before:
Save g:ale_set_lists_synchronously
Save g:ale_buffer_info
+ Save &shell
let g:ale_buffer_info = {}
let g:ale_set_lists_synchronously = 1
@@ -59,6 +60,67 @@ Execute(Linters should run with the default options):
\ 'valid': 1,
\ }], getloclist(0)
+Execute(Linters should run in PowerShell too):
+ if has('win32')
+ set shell=powershell
+
+ AssertEqual 'foobar', &filetype
+
+ " Replace the callback to handle two lines.
+ function! TestCallback(buffer, output)
+ " Windows adds extra spaces to the text from echo.
+ return [
+ \ {
+ \ 'lnum': 1,
+ \ 'col': 3,
+ \ 'text': substitute(a:output[0], ' *$', '', ''),
+ \ },
+ \ {
+ \ 'lnum': 2,
+ \ 'col': 3,
+ \ 'text': substitute(a:output[1], ' *$', '', ''),
+ \ },
+ \]
+ endfunction
+
+ " Recreate the command string to use &&, which PowerShell does not support.
+ call ale#linter#Reset()
+ call ale#linter#Define('foobar', {
+ \ 'name': 'testlinter',
+ \ 'callback': 'TestCallback',
+ \ 'executable': 'cmd',
+ \ 'command': 'echo foo && echo bar',
+ \})
+
+ call ale#Lint()
+ call ale#engine#WaitForJobs(2000)
+
+ AssertEqual [
+ \ {
+ \ 'bufnr': bufnr('%'),
+ \ 'lnum': 1,
+ \ 'vcol': 0,
+ \ 'col': 3,
+ \ 'text': 'foo',
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ 'pattern': '',
+ \ 'valid': 1,
+ \ },
+ \ {
+ \ 'bufnr': bufnr('%'),
+ \ 'lnum': 2,
+ \ 'vcol': 0,
+ \ 'col': 3,
+ \ 'text': 'bar',
+ \ 'type': 'E',
+ \ 'nr': -1,
+ \ 'pattern': '',
+ \ 'valid': 1,
+ \ },
+ \], getloclist(0)
+ endif
+
Execute(Previous errors should be removed when linters change):
call ale#Lint()
call ale#engine#WaitForJobs(2000)
diff --git a/test/test_history_saving.vader b/test/test_history_saving.vader
index 020ceb53..7dabcd9d 100644
--- a/test/test_history_saving.vader
+++ b/test/test_history_saving.vader
@@ -76,7 +76,7 @@ Execute(History should be set when commands are run):
AssertEqual sort(['status', 'exit_code', 'job_id', 'command']), sort(keys(g:history[0]))
if has('win32')
- AssertEqual 'cmd /c echo command history test', g:history[0].command
+ AssertEqual 'cmd /s/c "echo command history test"', g:history[0].command
else
AssertEqual ['/bin/sh', '-c', '/bin/sh -c ''echo command history test'''], g:history[0].command
endif
@@ -151,7 +151,7 @@ Execute(The history should be updated when fixers are run):
AssertEqual ['finished'], map(copy(b:ale_history), 'v:val.status')
if has('win32')
- AssertEqual 'cmd /c echo foo ', split(b:ale_history[0].command, '<')[0]
+ AssertEqual 'cmd /s/c "echo foo ', split(b:ale_history[0].command, '<')[0]
else
AssertEqual '/bin/sh -c echo foo ', split(join(b:ale_history[0].command), '<')[0]
endif
diff --git a/test/test_prepare_command.vader b/test/test_prepare_command.vader
index 16772e82..ed9272ab 100644
--- a/test/test_prepare_command.vader
+++ b/test/test_prepare_command.vader
@@ -30,10 +30,10 @@ Execute(Other shells should be used when set):
AssertEqual ['/bin/bash', '-c', 'foobar'], ale#job#PrepareCommand(bufnr(''), 'foobar')
endif
-Execute(cmd /c as a string should be used on Windows):
+Execute(cmd /s/c as a string should be used on Windows):
if has('win32')
let &shell = 'who cares'
let &shellcmdflag = 'whatever'
- AssertEqual 'cmd /c foobar', ale#job#PrepareCommand(bufnr(''), 'foobar')
+ AssertEqual 'cmd /s/c "foobar"', ale#job#PrepareCommand(bufnr(''), 'foobar')
endif
diff --git a/test/test_wrap_comand.vader b/test/test_wrap_comand.vader
index 8c1569b1..7ddb06a1 100644
--- a/test/test_wrap_comand.vader
+++ b/test/test_wrap_comand.vader
@@ -5,7 +5,7 @@ Before:
function! TestCommand(expected_part, input) abort
let l:expected = has('win32')
- \ ? 'cmd /c ' . a:expected_part
+ \ ? 'cmd /s/c "' . a:expected_part . '"'
\ : split(&shell) + split(&shellcmdflag) + [a:expected_part]
AssertEqual l:expected, ale#job#PrepareCommand(bufnr(''), a:input)