summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/command_callback/test_bandit_command_callback.vader49
-rw-r--r--test/handler/test_bandit_handler.vader42
-rw-r--r--test/lsp/test_lsp_command_formatting.vader1
-rw-r--r--test/lsp/test_lsp_root_detection.vader63
-rw-r--r--test/test_ale_info.vader1
-rw-r--r--test/test_format_command.vader42
-rw-r--r--test/test_sandbox_execution.vader2
-rw-r--r--test/test_shell_detection.vader18
-rw-r--r--test/test_temporary_file_management.vader44
9 files changed, 227 insertions, 35 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/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/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/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_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_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_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()