aboutsummaryrefslogtreecommitdiff
path: root/test/old/testdir/test_compiler.vim
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-02-04 07:44:15 +0800
committerGitHub <noreply@github.com>2025-02-04 07:44:15 +0800
commitf618cdf9c41fd977df89f809e6adb040522f675b (patch)
tree7d4af0519b6b50a0cb176ac99a33b7897877bafb /test/old/testdir/test_compiler.vim
parenteacd662ccb755a8663a2e9e3658f8d600931b26e (diff)
parentca8694a69d2a91032337bc1141c954ba0df5002f (diff)
downloadrneovim-f618cdf9c41fd977df89f809e6adb040522f675b.tar.gz
rneovim-f618cdf9c41fd977df89f809e6adb040522f675b.tar.bz2
rneovim-f618cdf9c41fd977df89f809e6adb040522f675b.zip
Merge pull request #31604 from zeertzjq/vim-9.1.0935
vim-patch:9.1.{0935,0967,1073}
Diffstat (limited to 'test/old/testdir/test_compiler.vim')
-rw-r--r--test/old/testdir/test_compiler.vim469
1 files changed, 454 insertions, 15 deletions
diff --git a/test/old/testdir/test_compiler.vim b/test/old/testdir/test_compiler.vim
index 3ad6b365de..1310cbadfc 100644
--- a/test/old/testdir/test_compiler.vim
+++ b/test/old/testdir/test_compiler.vim
@@ -18,6 +18,8 @@ func Test_compiler()
endif
e Xfoo.pl
+ " Play nice with other tests.
+ defer setqflist([])
compiler perl
call assert_equal('perl', b:current_compiler)
call assert_fails('let g:current_compiler', 'E121:')
@@ -91,6 +93,7 @@ func s:SpotBugsParseFilterMakePrg(dirname, makeprg)
endif
let offset += 1 + strlen('-sourcepath')
let result.sourcepath = matchstr(strpart(a:makeprg, offset), '.\{-}\ze[ \t]')
+ let offset += 1 + strlen(result.sourcepath)
" Get the class file arguments, dropping the pathname prefix.
let offset = stridx(a:makeprg, a:dirname, offset)
@@ -140,7 +143,8 @@ func Test_compiler_spotbugs_makeprg()
" THE EXPECTED RESULTS.
let results = {}
let results['Xspotbugs/src/tests/𐌂1.java'] = {
- \ 'sourcepath': '%:p:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/𐌂1.java',
+ \ ':p:h:S')},
\ 'classfiles': sort([
\ 'Xspotbugs/tests/𐌂1$1.class',
\ 'Xspotbugs/tests/𐌂1$1𐌉𐌉1.class',
@@ -153,11 +157,12 @@ func Test_compiler_spotbugs_makeprg()
\ }
" No class file for an empty source file even with "-Xpkginfo:always".
let results['Xspotbugs/src/tests/package-info.java'] = {
- \ 'sourcepath': '',
+ \ 'Sourcepath': {-> ''},
\ 'classfiles': [],
\ }
let results['Xspotbugs/src/tests/α/𐌂1.java'] = {
- \ 'sourcepath': '%:p:h:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/𐌂1.java',
+ \ ':p:h:h:S')},
\ 'classfiles': sort([
\ 'Xspotbugs/tests/α/𐌂1$1.class',
\ 'Xspotbugs/tests/α/𐌂1$1𐌉𐌉1.class',
@@ -169,11 +174,13 @@ func Test_compiler_spotbugs_makeprg()
\ 'Xspotbugs/tests/α/𐌂2.class']),
\ }
let results['Xspotbugs/src/tests/α/package-info.java'] = {
- \ 'sourcepath': '%:p:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/package-info.java',
+ \ ':p:h:S')},
\ 'classfiles': ['Xspotbugs/tests/α/package-info.class'],
\ }
let results['Xspotbugs/src/tests/α/β/𐌂1.java'] = {
- \ 'sourcepath': '%:p:h:h:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/β/𐌂1.java',
+ \ ':p:h:h:h:S')},
\ 'classfiles': sort([
\ 'Xspotbugs/tests/α/β/𐌂1$1.class',
\ 'Xspotbugs/tests/α/β/𐌂1$1𐌉𐌉1.class',
@@ -185,11 +192,13 @@ func Test_compiler_spotbugs_makeprg()
\ 'Xspotbugs/tests/α/β/𐌂2.class']),
\ }
let results['Xspotbugs/src/tests/α/β/package-info.java'] = {
- \ 'sourcepath': '%:p:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/β/package-info.java',
+ \ ':p:h:S')},
\ 'classfiles': ['Xspotbugs/tests/α/β/package-info.class'],
\ }
let results['Xspotbugs/src/tests/α/β/γ/𐌂1.java'] = {
- \ 'sourcepath': '%:p:h:h:h:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/β/γ/𐌂1.java',
+ \ ':p:h:h:h:h:S')},
\ 'classfiles': sort([
\ 'Xspotbugs/tests/α/β/γ/𐌂1$1.class',
\ 'Xspotbugs/tests/α/β/γ/𐌂1$1𐌉𐌉1.class',
@@ -201,11 +210,13 @@ func Test_compiler_spotbugs_makeprg()
\ 'Xspotbugs/tests/α/β/γ/𐌂2.class']),
\ }
let results['Xspotbugs/src/tests/α/β/γ/package-info.java'] = {
- \ 'sourcepath': '%:p:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/β/γ/package-info.java',
+ \ ':p:h:S')},
\ 'classfiles': ['Xspotbugs/tests/α/β/γ/package-info.class'],
\ }
let results['Xspotbugs/src/tests/α/β/γ/δ/𐌂1.java'] = {
- \ 'sourcepath': '%:p:h:h:h:h:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/β/γ/δ/𐌂1.java',
+ \ ':p:h:h:h:h:h:S')},
\ 'classfiles': sort([
\ 'Xspotbugs/tests/α/β/γ/δ/𐌂1$1.class',
\ 'Xspotbugs/tests/α/β/γ/δ/𐌂1$1𐌉𐌉1.class',
@@ -217,14 +228,15 @@ func Test_compiler_spotbugs_makeprg()
\ 'Xspotbugs/tests/α/β/γ/δ/𐌂2.class']),
\ }
let results['Xspotbugs/src/tests/α/β/γ/δ/package-info.java'] = {
- \ 'sourcepath': '%:p:h:S',
+ \ 'Sourcepath': {-> fnamemodify('Xspotbugs/src/tests/α/β/γ/δ/package-info.java',
+ \ ':p:h:S')},
\ 'classfiles': ['Xspotbugs/tests/α/β/γ/δ/package-info.class'],
\ }
" MAKE CLASS FILES DISCOVERABLE!
let g:spotbugs_properties = {
- \ 'sourceDirPath': 'src/tests',
- \ 'classDirPath': 'tests',
+ \ 'sourceDirPath': ['src/tests'],
+ \ 'classDirPath': ['tests'],
\ }
call assert_true(has_key(s:SpotBugsParseFilterMakePrg('Xspotbugs', ''), 'sourcepath'))
@@ -249,20 +261,22 @@ func Test_compiler_spotbugs_makeprg()
let package_file = src_dir .. 'package-info.java'
call writefile([package], src_dir .. 'package-info.java')
- for s in ['on', 'off']
+ " Note that using "off" for the first _outer_ iteration is preferable
+ " because only then "hlexists()" may be 0 (see "compiler/spotbugs.vim").
+ for s in ['off', 'on']
execute 'syntax ' .. s
execute 'edit ' .. type_file
compiler spotbugs
let result = s:SpotBugsParseFilterMakePrg('Xspotbugs', &l:makeprg)
- call assert_equal(results[type_file].sourcepath, result.sourcepath)
+ call assert_equal(results[type_file].Sourcepath(), result.sourcepath)
call assert_equal(results[type_file].classfiles, result.classfiles)
bwipeout
execute 'edit ' .. package_file
compiler spotbugs
let result = s:SpotBugsParseFilterMakePrg('Xspotbugs', &l:makeprg)
- call assert_equal(results[package_file].sourcepath, result.sourcepath)
+ call assert_equal(results[package_file].Sourcepath(), result.sourcepath)
call assert_equal(results[package_file].classfiles, result.classfiles)
bwipeout
endfor
@@ -271,4 +285,429 @@ func Test_compiler_spotbugs_makeprg()
let &shellslash = save_shellslash
endfunc
+func s:SpotBugsBeforeFileTypeTryPluginAndClearCache(state)
+ " Ponder over "extend(spotbugs#DefaultProperties(), g:spotbugs_properties)"
+ " in "ftplugin/java.vim".
+ let g:spotbugs#state = a:state
+ runtime autoload/spotbugs.vim
+endfunc
+
+func Test_compiler_spotbugs_properties()
+ let save_shellslash = &shellslash
+ set shellslash
+ setlocal makeprg=
+ filetype plugin on
+
+ call assert_true(mkdir('Xspotbugs/src', 'pR'))
+ call assert_true(mkdir('Xspotbugs/tests', 'pR'))
+ let type_file = 'Xspotbugs/src/𐌄.java'
+ let test_file = 'Xspotbugs/tests/𐌄$.java'
+ call writefile(['enum 𐌄{}'], type_file)
+ call writefile(['class 𐌄${}'], test_file)
+
+ " TEST INTEGRATION WITH A BOGUS COMPILER PLUGIN.
+ if !filereadable($VIMRUNTIME .. '/compiler/foo.vim') && !executable('foo')
+ let g:spotbugs_properties = {'compiler': 'foo'}
+ " XXX: In case this "if" block is no longer first.
+ call s:SpotBugsBeforeFileTypeTryPluginAndClearCache({
+ \ 'compiler': g:spotbugs_properties.compiler,
+ \ })
+ execute 'edit ' .. type_file
+ call assert_equal('java', &l:filetype)
+ " This variable will indefinitely keep the compiler name.
+ call assert_equal('foo', g:spotbugs#state.compiler)
+ " The "compiler" entry should be gone after FileType and default entries
+ " should only appear for a supported compiler.
+ call assert_false(has_key(g:spotbugs_properties, 'compiler'))
+ call assert_true(empty(g:spotbugs_properties))
+ " Query default implementations.
+ call assert_true(exists('*spotbugs#DefaultProperties'))
+ call assert_true(exists('*spotbugs#DefaultPreCompilerAction'))
+ call assert_true(exists('*spotbugs#DefaultPreCompilerTestAction'))
+ call assert_true(empty(spotbugs#DefaultProperties()))
+ " Get a ":message".
+ redir => out
+ call spotbugs#DefaultPreCompilerAction()
+ redir END
+ call assert_equal('Not supported: "foo"', out[stridx(out, 'Not') :])
+ " Get a ":message".
+ redir => out
+ call spotbugs#DefaultPreCompilerTestAction()
+ redir END
+ call assert_equal('Not supported: "foo"', out[stridx(out, 'Not') :])
+ " No ":autocmd"s without one of "PreCompiler*Action", "PostCompilerAction".
+ call assert_false(exists('#java_spotbugs'))
+ bwipeout
+ endif
+
+ let s:spotbugs_results = {
+ \ 'preActionDone': 0,
+ \ 'preTestActionDone': 0,
+ \ 'preTestLocalActionDone': 0,
+ \ 'postActionDone': 0,
+ \ 'preCommandArguments': '',
+ \ 'preTestCommandArguments': '',
+ \ 'postCommandArguments': '',
+ \ }
+ defer execute('unlet s:spotbugs_results')
+
+ func! g:SpotBugsPreAction() abort
+ let s:spotbugs_results.preActionDone = 1
+ " XXX: Notify the spotbugs compiler about success or failure.
+ cc
+ endfunc
+ defer execute('delfunction g:SpotBugsPreAction')
+
+ func! g:SpotBugsPreTestAction() abort
+ let s:spotbugs_results.preTestActionDone = 1
+ " XXX: Let see compilation fail.
+ throw 'Oops'
+ endfunc
+ defer execute('delfunction g:SpotBugsPreTestAction')
+
+ func! g:SpotBugsPreTestLocalAction() abort
+ let s:spotbugs_results.preTestLocalActionDone = 1
+ " XXX: Notify the spotbugs compiler about success or failure.
+ cc
+ endfunc
+ defer execute('delfunction g:SpotBugsPreTestLocalAction')
+
+ func! g:SpotBugsPostAction() abort
+ let s:spotbugs_results.postActionDone = 1
+ endfunc
+ defer execute('delfunction g:SpotBugsPostAction')
+
+ func! g:SpotBugsPreCommand(arguments) abort
+ let s:spotbugs_results.preActionDone = 1
+ let s:spotbugs_results.preCommandArguments = a:arguments
+ " XXX: Notify the spotbugs compiler about success or failure.
+ cc
+ endfunc
+ defer execute('delfunction g:SpotBugsPreCommand')
+
+ func! g:SpotBugsPreTestCommand(arguments) abort
+ let s:spotbugs_results.preTestActionDone = 1
+ let s:spotbugs_results.preTestCommandArguments = a:arguments
+ " XXX: Notify the spotbugs compiler about success or failure.
+ cc
+ endfunc
+ defer execute('delfunction g:SpotBugsPreTestCommand')
+
+ func! g:SpotBugsPostCommand(arguments) abort
+ let s:spotbugs_results.postActionDone = 1
+ let s:spotbugs_results.postCommandArguments = a:arguments
+ endfunc
+ defer execute('delfunction g:SpotBugsPostCommand')
+
+ func! g:SpotBugsPostCompilerActionExecutor(action) abort
+ try
+ " XXX: Notify the spotbugs compiler about success or failure.
+ cc
+ catch /\<E42:/
+ execute a:action
+ endtry
+ endfunc
+ defer execute('delfunction g:SpotBugsPostCompilerActionExecutor')
+
+ " TEST INTEGRATION WITH A SUPPORTED COMPILER PLUGIN.
+ if filereadable($VIMRUNTIME .. '/compiler/maven.vim')
+ let save_PATH = $PATH
+ if !executable('mvn')
+ if has('win32')
+ let $PATH = 'Xspotbugs;' .. $PATH
+ " This is what ":help executable()" suggests.
+ call writefile([], 'Xspotbugs/mvn.cmd')
+ else
+ let $PATH = 'Xspotbugs:' .. $PATH
+ call writefile([], 'Xspotbugs/mvn')
+ call setfperm('Xspotbugs/mvn', 'rwx------')
+ endif
+ endif
+
+ let g:spotbugs_properties = {
+ \ 'compiler': 'maven',
+ \ 'PreCompilerAction': function('g:SpotBugsPreAction'),
+ \ 'PreCompilerTestAction': function('g:SpotBugsPreTestAction'),
+ \ 'PostCompilerAction': function('g:SpotBugsPostAction'),
+ \ }
+ " XXX: In case this is a runner-up ":edit".
+ call s:SpotBugsBeforeFileTypeTryPluginAndClearCache({
+ \ 'compiler': g:spotbugs_properties.compiler,
+ \ })
+ execute 'edit ' .. type_file
+ call assert_equal('java', &l:filetype)
+ call assert_equal('maven', g:spotbugs#state.compiler)
+ call assert_false(has_key(g:spotbugs_properties, 'compiler'))
+ call assert_false(empty(g:spotbugs_properties))
+ " Query default implementations.
+ call assert_true(exists('*spotbugs#DefaultProperties'))
+ call assert_equal(sort([
+ \ 'PreCompilerAction',
+ \ 'PreCompilerTestAction',
+ \ 'PostCompilerAction',
+ \ 'sourceDirPath',
+ \ 'classDirPath',
+ \ 'testSourceDirPath',
+ \ 'testClassDirPath',
+ \ ]),
+ \ sort(keys(spotbugs#DefaultProperties())))
+ " Some ":autocmd"s with one of "PreCompiler*Action", "PostCompilerAction".
+ call assert_true(exists('#java_spotbugs'))
+ call assert_true(exists('#java_spotbugs#Syntax'))
+ call assert_true(exists('#java_spotbugs#User'))
+ call assert_equal(2, exists(':SpotBugsDefineBufferAutocmd'))
+ " SpotBugsDefineBufferAutocmd SigUSR1 User SigUSR1 User SigUSR1 User
+ " call assert_true(exists('#java_spotbugs#SigUSR1'))
+ SpotBugsDefineBufferAutocmd Signal User Signal User Signal User
+ call assert_true(exists('#java_spotbugs#Signal'))
+ call assert_true(exists('#java_spotbugs#Syntax'))
+ call assert_true(exists('#java_spotbugs#User'))
+ call assert_equal(2, exists(':SpotBugsRemoveBufferAutocmd'))
+ " SpotBugsRemoveBufferAutocmd SigUSR1 User SigUSR1 User UserGettingBored
+ " call assert_false(exists('#java_spotbugs#SigUSR1'))
+ SpotBugsRemoveBufferAutocmd Signal User Signal User UserGettingBored
+ call assert_false(exists('#java_spotbugs#Signal'))
+ call assert_true(exists('#java_spotbugs#Syntax'))
+ call assert_true(exists('#java_spotbugs#User'))
+
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+
+ doautocmd java_spotbugs Syntax
+ call assert_false(exists('#java_spotbugs#Syntax'))
+
+ " No match: "type_file !~# 'src/main/java'".
+ call assert_false(s:spotbugs_results.preActionDone)
+ " No match: "type_file !~# 'src/test/java'".
+ call assert_false(s:spotbugs_results.preTestActionDone)
+ " No pre-match, no post-action.
+ call assert_false(s:spotbugs_results.postActionDone)
+ " Without a match, confirm that ":compiler spotbugs" has NOT run.
+ call assert_true(empty(&l:makeprg))
+
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+ " Update path entries. (Note that we cannot use just "src" because there
+ " is another "src" directory nearer the filesystem root directory, i.e.
+ " "vim/vim/src/testdir/Xspotbugs/src", and "s:DispatchAction()" (see
+ " "ftplugin/java.vim") will match "vim/vim/src/testdir/Xspotbugs/tests"
+ " against "src".)
+ let g:spotbugs_properties.sourceDirPath = ['Xspotbugs/src']
+ let g:spotbugs_properties.classDirPath = ['Xspotbugs/src']
+ let g:spotbugs_properties.testSourceDirPath = ['tests']
+ let g:spotbugs_properties.testClassDirPath = ['tests']
+
+ doautocmd java_spotbugs User
+ " No match: "type_file !~# 'src/main/java'" (with old "*DirPath" values
+ " cached).
+ call assert_false(s:spotbugs_results.preActionDone)
+ " No match: "type_file !~# 'src/test/java'" (with old "*DirPath" values
+ " cached).
+ call assert_false(s:spotbugs_results.preTestActionDone)
+ " No pre-match, no post-action.
+ call assert_false(s:spotbugs_results.postActionDone)
+ " Without a match, confirm that ":compiler spotbugs" has NOT run.
+ call assert_true(empty(&l:makeprg))
+
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+ " XXX: Re-build ":autocmd"s from scratch with new values applied.
+ doautocmd FileType
+
+ call assert_true(exists('b:spotbugs_syntax_once'))
+ doautocmd java_spotbugs User
+ " A match: "type_file =~# 'Xspotbugs/src'" (with new "*DirPath" values
+ " cached).
+ call assert_true(s:spotbugs_results.preActionDone)
+ " No match: "type_file !~# 'tests'" (with new "*DirPath" values cached).
+ call assert_false(s:spotbugs_results.preTestActionDone)
+ " For a pre-match, a post-action.
+ call assert_true(s:spotbugs_results.postActionDone)
+
+ " With a match, confirm that ":compiler spotbugs" has run.
+ if has('win32')
+ call assert_match('^spotbugs\.bat\s', &l:makeprg)
+ else
+ call assert_match('^spotbugs\s', &l:makeprg)
+ endif
+
+ bwipeout
+ setlocal makeprg=
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionDone = 0
+ let s:spotbugs_results.preTestLocalActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+
+ execute 'edit ' .. test_file
+ " Prepare a buffer-local, incomplete variant of properties, relying on
+ " "ftplugin/java.vim" to take care of merging in unique entries, if any,
+ " from "g:spotbugs_properties".
+ let b:spotbugs_properties = {
+ \ 'PreCompilerTestAction': function('g:SpotBugsPreTestLocalAction'),
+ \ }
+ call assert_equal('java', &l:filetype)
+ call assert_true(exists('#java_spotbugs'))
+ call assert_true(exists('#java_spotbugs#Syntax'))
+ call assert_true(exists('#java_spotbugs#User'))
+ call assert_fails('doautocmd java_spotbugs Syntax', 'Oops')
+ call assert_false(exists('#java_spotbugs#Syntax'))
+ " No match: "test_file !~# 'Xspotbugs/src'".
+ call assert_false(s:spotbugs_results.preActionDone)
+ " A match: "test_file =~# 'tests'".
+ call assert_true(s:spotbugs_results.preTestActionDone)
+ call assert_false(s:spotbugs_results.preTestLocalActionDone)
+ " No action after pre-failure (the thrown "Oops" doesn't qualify for ":cc").
+ call assert_false(s:spotbugs_results.postActionDone)
+ " No ":compiler spotbugs" will be run after pre-failure.
+ call assert_true(empty(&l:makeprg))
+
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionDone = 0
+ let s:spotbugs_results.preTestLocalActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+ " XXX: Re-build ":autocmd"s from scratch with buffer-local values applied.
+ doautocmd FileType
+
+ call assert_true(exists('b:spotbugs_syntax_once'))
+ doautocmd java_spotbugs User
+ " No match: "test_file !~# 'Xspotbugs/src'".
+ call assert_false(s:spotbugs_results.preActionDone)
+ " A match: "test_file =~# 'tests'".
+ call assert_true(s:spotbugs_results.preTestLocalActionDone)
+ call assert_false(s:spotbugs_results.preTestActionDone)
+ " For a pre-match, a post-action.
+ call assert_true(s:spotbugs_results.postActionDone)
+
+ " With a match, confirm that ":compiler spotbugs" has run.
+ if has('win32')
+ call assert_match('^spotbugs\.bat\s', &l:makeprg)
+ else
+ call assert_match('^spotbugs\s', &l:makeprg)
+ endif
+
+ setlocal makeprg=
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionDone = 0
+ let s:spotbugs_results.preTestLocalActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+ let s:spotbugs_results.preCommandArguments = ''
+ let s:spotbugs_results.preTestCommandArguments = ''
+ let s:spotbugs_results.postCommandArguments = ''
+ " XXX: Compose the assigned "*Command"s with the default Maven "*Action"s.
+ let b:spotbugs_properties = {
+ \ 'compiler': 'maven',
+ \ 'DefaultPreCompilerTestCommand': function('g:SpotBugsPreTestCommand'),
+ \ 'DefaultPreCompilerCommand': function('g:SpotBugsPreCommand'),
+ \ 'DefaultPostCompilerCommand': function('g:SpotBugsPostCommand'),
+ \ 'PostCompilerActionExecutor': function('g:SpotBugsPostCompilerActionExecutor'),
+ \ 'augroupForPostCompilerAction': 'java_spotbugs_test',
+ \ 'sourceDirPath': ['Xspotbugs/src'],
+ \ 'classDirPath': ['Xspotbugs/src'],
+ \ 'testSourceDirPath': ['tests'],
+ \ 'testClassDirPath': ['tests'],
+ \ }
+ unlet g:spotbugs_properties
+ " XXX: Re-build ":autocmd"s from scratch with buffer-local values applied.
+ call s:SpotBugsBeforeFileTypeTryPluginAndClearCache({
+ \ 'compiler': b:spotbugs_properties.compiler,
+ \ 'commands': {
+ \ 'DefaultPreCompilerTestCommand':
+ \ b:spotbugs_properties.DefaultPreCompilerTestCommand,
+ \ 'DefaultPreCompilerCommand':
+ \ b:spotbugs_properties.DefaultPreCompilerCommand,
+ \ 'DefaultPostCompilerCommand':
+ \ b:spotbugs_properties.DefaultPostCompilerCommand,
+ \ },
+ \ })
+ doautocmd FileType
+
+ call assert_equal('maven', g:spotbugs#state.compiler)
+ call assert_equal(sort([
+ \ 'DefaultPreCompilerTestCommand',
+ \ 'DefaultPreCompilerCommand',
+ \ 'DefaultPostCompilerCommand',
+ \ ]),
+ \ sort(keys(g:spotbugs#state.commands)))
+ call assert_true(exists('b:spotbugs_syntax_once'))
+ doautocmd java_spotbugs User
+ " No match: "test_file !~# 'Xspotbugs/src'".
+ call assert_false(s:spotbugs_results.preActionDone)
+ call assert_true(empty(s:spotbugs_results.preCommandArguments))
+ " A match: "test_file =~# 'tests'".
+ call assert_true(s:spotbugs_results.preTestActionDone)
+ call assert_equal('test-compile', s:spotbugs_results.preTestCommandArguments)
+ " For a pre-match, a post-action.
+ call assert_true(s:spotbugs_results.postActionDone)
+ call assert_equal('%:S', s:spotbugs_results.postCommandArguments)
+
+ " With a match, confirm that ":compiler spotbugs" has run.
+ if has('win32')
+ call assert_match('^spotbugs\.bat\s', &l:makeprg)
+ else
+ call assert_match('^spotbugs\s', &l:makeprg)
+ endif
+
+ setlocal makeprg=
+ let s:spotbugs_results.preActionDone = 0
+ let s:spotbugs_results.preTestActionOtherDone = 0
+ let s:spotbugs_results.preTestLocalActionDone = 0
+ let s:spotbugs_results.postActionDone = 0
+ let s:spotbugs_results.preCommandArguments = ''
+ let s:spotbugs_results.preTestCommandArguments = ''
+ let s:spotbugs_results.postCommandArguments = ''
+
+ " When "PostCompilerActionExecutor", "Pre*Action" and/or "Pre*TestAction",
+ " and "Post*Action" are available, "#java_spotbugs_post" must be defined.
+ call assert_true(exists('#java_spotbugs_post'))
+ call assert_true(exists('#java_spotbugs_post#User'))
+ call assert_false(exists('#java_spotbugs_post#ShellCmdPost'))
+ call assert_false(exists('#java_spotbugs_test#ShellCmdPost'))
+
+ " Re-link a Funcref on the fly.
+ func! g:SpotBugsPreTestCommand(arguments) abort
+ let s:spotbugs_results.preTestActionOtherDone = 1
+ let s:spotbugs_results.preTestCommandArguments = a:arguments
+ " Define a once-only ":autocmd" for "#java_spotbugs_test#ShellCmdPost".
+ doautocmd java_spotbugs_post User
+ " XXX: Do NOT use ":cc" to notify the spotbugs compiler about success or
+ " failure, and assume the transfer of control to a ShellCmdPost command.
+ endfunc
+
+ doautocmd java_spotbugs User
+ " No match: "test_file !~# 'Xspotbugs/src'".
+ call assert_false(s:spotbugs_results.preActionDone)
+ call assert_true(empty(s:spotbugs_results.preCommandArguments))
+ " A match: "test_file =~# 'tests'".
+ call assert_true(s:spotbugs_results.preTestActionOtherDone)
+ call assert_equal('test-compile', s:spotbugs_results.preTestCommandArguments)
+ " For a pre-match, no post-action (without ":cc") UNLESS a ShellCmdPost
+ " event is consumed whose command will invoke "PostCompilerActionExecutor"
+ " and the latter will accept a post-compiler action argument.
+ call assert_false(s:spotbugs_results.postActionDone)
+ call assert_true(exists('#java_spotbugs_test#ShellCmdPost'))
+ doautocmd ShellCmdPost
+ call assert_false(exists('#java_spotbugs_test#ShellCmdPost'))
+ call assert_true(s:spotbugs_results.postActionDone)
+ call assert_equal('%:S', s:spotbugs_results.postCommandArguments)
+
+ " With a match, confirm that ":compiler spotbugs" has run.
+ if has('win32')
+ call assert_match('^spotbugs\.bat\s', &l:makeprg)
+ else
+ call assert_match('^spotbugs\s', &l:makeprg)
+ endif
+
+ bwipeout
+ setlocal makeprg=
+ let $PATH = save_PATH
+ endif
+
+ filetype plugin off
+ setlocal makeprg=
+ let &shellslash = save_shellslash
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab