2017-03-31 15:14:53 -04:00
|
|
|
Before:
|
2017-10-08 18:26:50 -04:00
|
|
|
call ale#test#SetDirectory('/testplugin/test/command_callback')
|
|
|
|
|
2018-04-08 15:35:06 -04:00
|
|
|
Save g:ale_java_javac_executable
|
2017-10-08 18:26:50 -04:00
|
|
|
Save g:ale_java_javac_options
|
|
|
|
Save g:ale_java_javac_classpath
|
|
|
|
|
2018-04-08 15:35:06 -04:00
|
|
|
unlet! g:ale_java_javac_executable
|
2017-10-08 18:26:50 -04:00
|
|
|
unlet! g:ale_java_javac_options
|
|
|
|
unlet! g:ale_java_javac_classpath
|
|
|
|
|
|
|
|
let g:cp_sep = has('unix') ? ':' : ';'
|
|
|
|
|
|
|
|
function! GetCommand(previous_output) abort
|
|
|
|
let l:command = ale_linters#java#javac#GetCommand(
|
|
|
|
\ bufnr(''),
|
|
|
|
\ a:previous_output
|
|
|
|
\)
|
|
|
|
|
|
|
|
let l:split_command = split(l:command)
|
|
|
|
let l:index = index(l:split_command, '-d')
|
|
|
|
|
|
|
|
let l:split_command[l:index + 1] = 'TEMP'
|
|
|
|
|
|
|
|
return join(l:split_command)
|
|
|
|
endfunction
|
|
|
|
|
2017-03-31 15:14:53 -04:00
|
|
|
runtime ale_linters/java/javac.vim
|
|
|
|
call ale#engine#InitBufferInfo(bufnr(''))
|
|
|
|
|
2017-10-08 18:26:50 -04:00
|
|
|
call ale#test#SetFilename('dummy.java')
|
2017-04-25 17:32:48 -04:00
|
|
|
|
2018-04-08 15:35:06 -04:00
|
|
|
let g:prefix = 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
|
|
|
\ . ale#Escape('javac') . ' -Xlint'
|
2017-11-05 10:33:31 -05:00
|
|
|
|
2017-03-31 15:14:53 -04:00
|
|
|
After:
|
2017-10-08 18:26:50 -04:00
|
|
|
call ale#test#RestoreDirectory()
|
|
|
|
|
|
|
|
Restore
|
|
|
|
|
|
|
|
unlet! g:cp_sep
|
2017-11-05 10:33:31 -05:00
|
|
|
unlet! g:prefix
|
2017-10-08 18:26:50 -04:00
|
|
|
|
|
|
|
delfunction GetCommand
|
|
|
|
|
2017-03-31 15:14:53 -04:00
|
|
|
call ale#linter#Reset()
|
|
|
|
" We need to clean up the buffer to remove the temporary directories created
|
|
|
|
" for the command.
|
2017-07-07 18:47:41 -04:00
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
2017-03-31 15:14:53 -04:00
|
|
|
|
|
|
|
Execute(The javac callback should return the correct default value):
|
2017-11-05 10:33:31 -05:00
|
|
|
AssertEqual g:prefix . ' -d TEMP %t', GetCommand([])
|
2017-03-31 15:14:53 -04:00
|
|
|
|
|
|
|
Execute(The javac callback should use g:ale_java_javac_classpath correctly):
|
|
|
|
let g:ale_java_javac_classpath = 'foo.jar'
|
|
|
|
|
2017-10-08 18:26:50 -04:00
|
|
|
AssertEqual
|
2017-11-05 10:33:31 -05:00
|
|
|
\ g:prefix
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ' -cp ' . ale#Escape('foo.jar')
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([])
|
2017-04-25 17:32:48 -04:00
|
|
|
|
2018-04-08 15:35:06 -04:00
|
|
|
Execute(The executable should be configurable):
|
|
|
|
let g:ale_java_javac_executable = 'foobar'
|
|
|
|
|
|
|
|
AssertEqual 'foobar', ale_linters#java#javac#GetExecutable(bufnr(''))
|
|
|
|
|
|
|
|
AssertEqual
|
|
|
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
|
|
|
|
\ . ale#Escape('foobar') . ' -Xlint'
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([])
|
|
|
|
|
2017-04-25 17:32:48 -04:00
|
|
|
Execute(The javac callback should include discovered classpaths):
|
2017-10-08 18:26:50 -04:00
|
|
|
AssertEqual
|
2017-11-05 10:33:31 -05:00
|
|
|
\ g:prefix
|
|
|
|
\ . ' -cp '
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([
|
|
|
|
\ '[DEBUG] Ignore this.',
|
|
|
|
\ '[INFO] Something we should ignore.',
|
|
|
|
\ '/foo/bar.jar',
|
|
|
|
\ '/xyz/abc.jar',
|
|
|
|
\ ])
|
2017-04-25 17:32:48 -04:00
|
|
|
|
|
|
|
Execute(The javac callback should combine discovered classpaths and manual ones):
|
|
|
|
let g:ale_java_javac_classpath = 'configured.jar'
|
|
|
|
|
2017-10-08 18:26:50 -04:00
|
|
|
AssertEqual
|
2017-11-05 10:33:31 -05:00
|
|
|
\ g:prefix
|
|
|
|
\ . ' -cp '
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ale#Escape(join(
|
|
|
|
\ [
|
|
|
|
\ '/foo/bar.jar',
|
|
|
|
\ '/xyz/abc.jar',
|
|
|
|
\ 'configured.jar',
|
|
|
|
\ ],
|
|
|
|
\ g:cp_sep
|
|
|
|
\ ))
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([
|
|
|
|
\ '[DEBUG] Ignore this.',
|
|
|
|
\ '[INFO] Something we should ignore.',
|
|
|
|
\ '/foo/bar.jar',
|
|
|
|
\ '/xyz/abc.jar',
|
|
|
|
\ ])
|
|
|
|
|
|
|
|
let g:ale_java_javac_classpath = 'configured.jar' . g:cp_sep . 'configured2.jar'
|
|
|
|
|
|
|
|
AssertEqual
|
2017-11-05 10:33:31 -05:00
|
|
|
\ g:prefix
|
|
|
|
\ . ' -cp '
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ale#Escape(join(
|
|
|
|
\ [
|
|
|
|
\ '/foo/bar.jar',
|
|
|
|
\ '/xyz/abc.jar',
|
|
|
|
\ 'configured.jar',
|
|
|
|
\ 'configured2.jar',
|
|
|
|
\ ],
|
|
|
|
\ g:cp_sep
|
|
|
|
\ ))
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([
|
|
|
|
\ '[DEBUG] Ignore this.',
|
|
|
|
\ '[INFO] Something we should ignore.',
|
|
|
|
\ '/foo/bar.jar',
|
|
|
|
\ '/xyz/abc.jar',
|
|
|
|
\ ])
|
2017-04-25 17:32:48 -04:00
|
|
|
|
|
|
|
Execute(The javac callback should detect source directories):
|
2017-07-07 18:47:41 -04:00
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
2017-11-20 11:42:43 -05:00
|
|
|
noautocmd e! java_paths/src/main/java/com/something/dummy
|
2017-04-25 17:32:48 -04:00
|
|
|
call ale#engine#InitBufferInfo(bufnr(''))
|
|
|
|
|
2017-10-08 18:26:50 -04:00
|
|
|
AssertEqual
|
2018-04-08 15:35:06 -04:00
|
|
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ' -sourcepath ' . ale#Escape(
|
2017-12-19 13:23:09 -05:00
|
|
|
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/')
|
2017-10-08 18:26:50 -04:00
|
|
|
\ )
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([])
|
2017-04-25 17:32:48 -04:00
|
|
|
|
|
|
|
Execute(The javac callback should combine detected source directories and classpaths):
|
2017-07-07 18:47:41 -04:00
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
2017-10-08 18:26:50 -04:00
|
|
|
call ale#test#SetFilename('java_paths/src/main/java/com/something/dummy.java')
|
2017-04-25 17:32:48 -04:00
|
|
|
call ale#engine#InitBufferInfo(bufnr(''))
|
|
|
|
|
2017-10-08 18:26:50 -04:00
|
|
|
AssertEqual
|
2018-04-08 15:35:06 -04:00
|
|
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ' -cp ' . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
|
|
|
|
\ . ' -sourcepath ' . ale#Escape(
|
2017-12-19 13:23:09 -05:00
|
|
|
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/')
|
2017-10-08 18:26:50 -04:00
|
|
|
\ )
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([
|
|
|
|
\ '[DEBUG] Ignore this.',
|
|
|
|
\ '[INFO] Something we should ignore.',
|
|
|
|
\ '/foo/bar.jar',
|
|
|
|
\ '/xyz/abc.jar',
|
|
|
|
\ ])
|
2017-03-31 15:14:53 -04:00
|
|
|
|
|
|
|
Execute(The javac callback should use g:ale_java_javac_options correctly):
|
|
|
|
let g:ale_java_javac_options = '--anything --else'
|
|
|
|
|
2017-04-25 17:32:48 -04:00
|
|
|
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [])
|
2017-03-31 15:14:53 -04:00
|
|
|
|
2017-10-08 18:26:50 -04:00
|
|
|
AssertEqual
|
2017-11-05 10:33:31 -05:00
|
|
|
\ g:prefix
|
2017-10-08 18:26:50 -04:00
|
|
|
\ . ' -d TEMP --anything --else %t',
|
|
|
|
\ GetCommand([])
|
2017-11-20 11:42:43 -05:00
|
|
|
|
|
|
|
Execute(The javac callback should include src/test/java for test paths):
|
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
|
|
|
" The test path is only included for test files.
|
|
|
|
" Regular Java files shouldn't import from tests.
|
|
|
|
noautocmd e! java_paths/src/test/java/com/something/dummy
|
|
|
|
call ale#engine#InitBufferInfo(bufnr(''))
|
|
|
|
|
|
|
|
AssertEqual
|
2018-04-08 15:35:06 -04:00
|
|
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
|
2017-11-20 11:42:43 -05:00
|
|
|
\ . ' -sourcepath ' . ale#Escape(join([
|
2017-12-19 13:23:09 -05:00
|
|
|
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/'),
|
|
|
|
\ ale#path#Simplify(g:dir . '/java_paths/src/test/java/'),
|
2017-11-20 11:42:43 -05:00
|
|
|
\ ], g:cp_sep))
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([])
|
|
|
|
|
|
|
|
Execute(The javac callback should include src/main/jaxb when available):
|
|
|
|
call ale#engine#Cleanup(bufnr(''))
|
|
|
|
noautocmd e! java_paths_with_jaxb/src/main/java/com/something/dummy
|
|
|
|
call ale#engine#InitBufferInfo(bufnr(''))
|
|
|
|
|
|
|
|
AssertEqual
|
2018-04-08 15:35:06 -04:00
|
|
|
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
|
2017-11-20 11:42:43 -05:00
|
|
|
\ . ' -sourcepath ' . ale#Escape(join([
|
2017-12-19 13:23:09 -05:00
|
|
|
\ ale#path#Simplify(g:dir . '/java_paths_with_jaxb/src/main/java/'),
|
|
|
|
\ ale#path#Simplify(g:dir . '/java_paths_with_jaxb/src/main/jaxb/'),
|
2017-11-20 11:42:43 -05:00
|
|
|
\ ], g:cp_sep))
|
|
|
|
\ . ' -d TEMP %t',
|
|
|
|
\ GetCommand([])
|