summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2019-01-26 19:33:52 +0000
committerw0rp <devw0rp@gmail.com>2019-01-26 19:33:52 +0000
commitcf14d0aa53e9b51f4987dbfd3913183901bb2805 (patch)
tree8b4cbeeee01c2c40cdc725ddddcfa31cec85ccd1 /test
parentf12d312aa4aa49c4698056933030cd5adb60b489 (diff)
downloadale-cf14d0aa53e9b51f4987dbfd3913183901bb2805.zip
#2132 Unify temporary file management in command.vim
Diffstat (limited to 'test')
-rw-r--r--test/test_format_command.vader42
-rw-r--r--test/test_sandbox_execution.vader2
-rw-r--r--test/test_temporary_file_management.vader44
3 files changed, 54 insertions, 34 deletions
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_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()