robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
0df53062df
master
1" Test the :compiler command 2 3source check.vim 4source shared.vim 5 6func Test_compiler () 7CheckExecutable perl 8CheckFeature quickfix 9 10let save_LC_ALL = $ LC_ALL 11let $ LC_ALL = "C" 12 13let save_shellslash = & shellslash 14" Nvim doesn't allow setting value of a hidden option to non-default value 15if exists ( '+shellslash' ) 16" %:S does not work properly with 'shellslash' set 17set noshellslash 18endif 19 20e Xfoo.pl 21" Play nice with other tests. 22defer setqflist([]) 23 24compiler perl 25call assert_equal ( 'perl' , b: current_compiler ) 26call assert_fails ( 'let g:current_compiler' , 'E121:' ) 27let verbose_efm = execute ( 'verbose set efm' ) 28call assert_match ( 'Last set from .*[/\\]compiler[/\\]perl.vim ' , verbose_efm ) 29" Not using the global value 30call assert_notequal ( '' , & l: efm ) 31 32call setline ( 1 , [ '#!/usr/bin/perl -w' , 'use strict;' , 'my $foo=1' ]) 33w ! 34call feedkeys ( ":make\<CR>\<CR>" , 'tx' ) 35call assert_fails ( 'clist' , 'E42:' ) 36 37call setline ( 1 , [ '#!/usr/bin/perl -w' , 'use strict;' , '$foo=1' ]) 38w ! 39call feedkeys ( ":make\<CR>\<CR>" , 'tx' ) 40let a = execute ( 'clist' ) 41call assert_match ( '\d\+ Xfoo.pl:3: Global symbol "$foo" ' 42 \. 'requires explicit package name' , a ) 43 44compiler make 45call assert_fails ( 'let b:current_compiler' , 'E121:' ) 46call assert_fails ( 'let g:current_compiler' , 'E121:' ) 47let verbose_efm = execute ( 'verbose set efm' ) 48call assert_match ( 'Last set from .*[/\\]compiler[/\\]make.vim ' , verbose_efm ) 49 50compiler ! perl 51call assert_equal ( 'perl' , b: current_compiler ) 52call assert_equal ( 'perl' , g: current_compiler ) 53let verbose_efm = execute ( 'verbose set efm' ) 54call assert_match ( 'Last set from .*[/\\]compiler[/\\]perl.vim ' , verbose_efm ) 55call assert_equal ( verbose_efm , execute ( 'verbose setglobal efm' )) 56" Using the global value 57call assert_equal ( '' , & l: efm ) 58 59compiler ! make 60call assert_fails ( 'let b:current_compiler' , 'E121:' ) 61call assert_fails ( 'let g:current_compiler' , 'E121:' ) 62let verbose_efm = execute ( 'verbose set efm' ) 63call assert_match ( 'Last set from .*[/\\]compiler[/\\]make.vim ' , verbose_efm ) 64call assert_equal ( verbose_efm , execute ( 'verbose setglobal efm' )) 65" Using the global value 66call assert_equal ( '' , & l: efm ) 67 68let & shellslash = save_shellslash 69call delete ( 'Xfoo.pl' ) 70bw ! 71let $ LC_ALL = save_LC_ALL 72endfunc 73 74func GetCompilerNames () 75return glob ( '$VIMRUNTIME/compiler/*.vim' , 0 , 1 ) 76 \ ->map ({ i , v ->substitute ( v , '.*[\\/]\([a-zA-Z0-9_\-]*\).vim' , '\1' , '' )}) 77 \ ->sort () 78endfunc 79 80func Test_compiler_without_arg () 81let runtime = substitute ( $ VIMRUNTIME , '\\' , '/' , 'g' ) 82let a = split ( execute ( 'compiler' )) 83let exp = GetCompilerNames () 84call assert_match ( runtime .. '/compiler/' .. exp [ 0 ] .. '.vim$' , a [ 0 ]) 85call assert_match ( runtime .. '/compiler/' .. exp [ 1 ] .. '.vim$' , a [ 1 ]) 86call assert_match ( runtime .. '/compiler/' .. exp [ -1 ] .. '.vim$' , a [ -1 ]) 87endfunc 88 89" Test executing :compiler from the command line, not from a script 90func Test_compiler_commandline () 91call system ( GetVimCommandClean () .. ' -c "compiler gcc" -c "call writefile([b:current_compiler], ''XcompilerOut'')" -c "quit"' ) 92call assert_equal ( 0 , v: shell_error ) 93call assert_equal ([ "gcc" ], readfile ( 'XcompilerOut' )) 94 95call delete ( 'XcompilerOut' ) 96endfunc 97 98func Test_compiler_completion () 99let clist = GetCompilerNames () ->join ( ' ' ) 100call feedkeys ( ":compiler \<C-A>\<C-B>\"\<CR>" , 'tx' ) 101call assert_match ( '^"compiler ' .. clist .. '$' , @:) 102 103call feedkeys ( ":compiler p\<C-A>\<C-B>\"\<CR>" , 'tx' ) 104call assert_match ( '"compiler pandoc pbx perl\( p[a-z_]\+\)\+ pyunit' , @:) 105 106call feedkeys ( ":compiler! p\<C-A>\<C-B>\"\<CR>" , 'tx' ) 107call assert_match ( '"compiler! pandoc pbx perl\( p[a-z_]\+\)\+ pyunit' , @:) 108endfunc 109 110func Test_compiler_error () 111let g: current_compiler = 'abc' 112call assert_fails ( 'compiler doesnotexist' , 'E666:' ) 113call assert_equal ( 'abc' , g: current_compiler ) 114call assert_fails ( 'compiler! doesnotexist' , 'E666:' ) 115unlet ! g: current_compiler 116endfunc 117 118func s: SpotBugsParseFilterMakePrg ( dirname , makeprg ) 119let result = {} 120let result . sourcepath = '' 121let result . classfiles = [] 122 123" Get the argument after the rightmost occurrence of "-sourcepath". 124let offset = strridx ( a: makeprg , '-sourcepath' ) 125if offset < 0 126return result 127endif 128let offset += 1 + strlen ( '-sourcepath' ) 129let result . sourcepath = matchstr ( strpart ( a: makeprg , offset ), '.\{-}\ze[ \t]' ) 130let offset += 1 + strlen ( result . sourcepath ) 131 132" Get the class file arguments, dropping the pathname prefix. 133let offset = stridx ( a: makeprg , a: dirname , offset ) 134if offset < 0 135return result 136endif 137 138while offset > -1 139let candidate = matchstr ( a: makeprg , '[^ \t]\{-}\.class\>' , offset ) 140if empty ( candidate ) 141break 142endif 143call add ( result . classfiles , candidate ) 144let offset = stridx ( a: makeprg , a: dirname , ( 1 + strlen ( candidate ) + offset )) 145endwhile 146 147call sort ( result . classfiles ) 148return result 149endfunc 150 151func Test_compiler_spotbugs_makeprg () 152let save_shellslash = & shellslash 153set shellslash 154 155call assert_true ( mkdir ( 'Xspotbugs/src/tests/α/β/γ/δ' , 'pR' )) 156call assert_true ( mkdir ( 'Xspotbugs/tests/α/β/γ/δ' , 'pR' )) 157 158let lines =<< trim END 159// EOL comment. /* 160abstract class 161𐌂1 /* Multiline comment. */ { 162/* Multiline comment. */ // EOL comment. /* 163static final String COMMENT_A_LIKE = "/*"; 164{ new Object() {/* Try globbing. */}; } 165static { interface 𐌉𐌉1 {} } 166static class 𐌂11 { interface 𐌉𐌉2 {} } 167} 168/* Multiline comment. */ // EOL comment. /* 169final class 𐌂2 { 170public static void main(String... aa) { 171record 𐌓() {} 172enum 𐌄 {} 173} 174} // class 175END 176 177" THE EXPECTED RESULTS. 178let results = {} 179let results [ 'Xspotbugs/src/tests/𐌂1.java' ] = { 180 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/𐌂1.java' , 181 \':p:h:S' )}, 182 \'classfiles' : sort ([ 183 \'Xspotbugs/tests/𐌂1$1.class' , 184 \'Xspotbugs/tests/𐌂1$1𐌉𐌉1.class' , 185 \'Xspotbugs/tests/𐌂1$𐌂11$𐌉𐌉2.class' , 186 \'Xspotbugs/tests/𐌂1$𐌂11.class' , 187 \'Xspotbugs/tests/𐌂1.class' , 188 \'Xspotbugs/tests/𐌂2$1𐌄.class' , 189 \'Xspotbugs/tests/𐌂2$1𐌓.class' , 190 \'Xspotbugs/tests/𐌂2.class' ]), 191 \} 192" No class file for an empty source file even with "-Xpkginfo:always". 193let results [ 'Xspotbugs/src/tests/package-info.java' ] = { 194 \'Sourcepath' : { ->'' }, 195 \'classfiles' : [], 196 \} 197let results [ 'Xspotbugs/src/tests/α/𐌂1.java' ] = { 198 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/𐌂1.java' , 199 \':p:h:h:S' )}, 200 \'classfiles' : sort ([ 201 \'Xspotbugs/tests/α/𐌂1$1.class' , 202 \'Xspotbugs/tests/α/𐌂1$1𐌉𐌉1.class' , 203 \'Xspotbugs/tests/α/𐌂1$𐌂11$𐌉𐌉2.class' , 204 \'Xspotbugs/tests/α/𐌂1$𐌂11.class' , 205 \'Xspotbugs/tests/α/𐌂1.class' , 206 \'Xspotbugs/tests/α/𐌂2$1𐌄.class' , 207 \'Xspotbugs/tests/α/𐌂2$1𐌓.class' , 208 \'Xspotbugs/tests/α/𐌂2.class' ]), 209 \} 210let results [ 'Xspotbugs/src/tests/α/package-info.java' ] = { 211 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/package-info.java' , 212 \':p:h:S' )}, 213 \'classfiles' : [ 'Xspotbugs/tests/α/package-info.class' ], 214 \} 215let results [ 'Xspotbugs/src/tests/α/β/𐌂1.java' ] = { 216 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/β/𐌂1.java' , 217 \':p:h:h:h:S' )}, 218 \'classfiles' : sort ([ 219 \'Xspotbugs/tests/α/β/𐌂1$1.class' , 220 \'Xspotbugs/tests/α/β/𐌂1$1𐌉𐌉1.class' , 221 \'Xspotbugs/tests/α/β/𐌂1$𐌂11$𐌉𐌉2.class' , 222 \'Xspotbugs/tests/α/β/𐌂1$𐌂11.class' , 223 \'Xspotbugs/tests/α/β/𐌂1.class' , 224 \'Xspotbugs/tests/α/β/𐌂2$1𐌄.class' , 225 \'Xspotbugs/tests/α/β/𐌂2$1𐌓.class' , 226 \'Xspotbugs/tests/α/β/𐌂2.class' ]), 227 \} 228let results [ 'Xspotbugs/src/tests/α/β/package-info.java' ] = { 229 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/β/package-info.java' , 230 \':p:h:S' )}, 231 \'classfiles' : [ 'Xspotbugs/tests/α/β/package-info.class' ], 232 \} 233let results [ 'Xspotbugs/src/tests/α/β/γ/𐌂1.java' ] = { 234 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/β/γ/𐌂1.java' , 235 \':p:h:h:h:h:S' )}, 236 \'classfiles' : sort ([ 237 \'Xspotbugs/tests/α/β/γ/𐌂1$1.class' , 238 \'Xspotbugs/tests/α/β/γ/𐌂1$1𐌉𐌉1.class' , 239 \'Xspotbugs/tests/α/β/γ/𐌂1$𐌂11$𐌉𐌉2.class' , 240 \'Xspotbugs/tests/α/β/γ/𐌂1$𐌂11.class' , 241 \'Xspotbugs/tests/α/β/γ/𐌂1.class' , 242 \'Xspotbugs/tests/α/β/γ/𐌂2$1𐌄.class' , 243 \'Xspotbugs/tests/α/β/γ/𐌂2$1𐌓.class' , 244 \'Xspotbugs/tests/α/β/γ/𐌂2.class' ]), 245 \} 246let results [ 'Xspotbugs/src/tests/α/β/γ/package-info.java' ] = { 247 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/β/γ/package-info.java' , 248 \':p:h:S' )}, 249 \'classfiles' : [ 'Xspotbugs/tests/α/β/γ/package-info.class' ], 250 \} 251let results [ 'Xspotbugs/src/tests/α/β/γ/δ/𐌂1.java' ] = { 252 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/β/γ/δ/𐌂1.java' , 253 \':p:h:h:h:h:h:S' )}, 254 \'classfiles' : sort ([ 255 \'Xspotbugs/tests/α/β/γ/δ/𐌂1$1.class' , 256 \'Xspotbugs/tests/α/β/γ/δ/𐌂1$1𐌉𐌉1.class' , 257 \'Xspotbugs/tests/α/β/γ/δ/𐌂1$𐌂11$𐌉𐌉2.class' , 258 \'Xspotbugs/tests/α/β/γ/δ/𐌂1$𐌂11.class' , 259 \'Xspotbugs/tests/α/β/γ/δ/𐌂1.class' , 260 \'Xspotbugs/tests/α/β/γ/δ/𐌂2$1𐌄.class' , 261 \'Xspotbugs/tests/α/β/γ/δ/𐌂2$1𐌓.class' , 262 \'Xspotbugs/tests/α/β/γ/δ/𐌂2.class' ]), 263 \} 264let results [ 'Xspotbugs/src/tests/α/β/γ/δ/package-info.java' ] = { 265 \'Sourcepath' : { ->fnamemodify ( 'Xspotbugs/src/tests/α/β/γ/δ/package-info.java' , 266 \':p:h:S' )}, 267 \'classfiles' : [ 'Xspotbugs/tests/α/β/γ/δ/package-info.class' ], 268 \} 269 270" MAKE CLASS FILES DISCOVERABLE! 271let g: spotbugs_properties = { 272 \'sourceDirPath' : [ 'src/tests' ], 273 \'classDirPath' : [ 'tests' ], 274 \} 275 276call assert_true ( has_key ( s: SpotBugsParseFilterMakePrg ( 'Xspotbugs' , '' ), 'sourcepath' )) 277call assert_true ( has_key ( s: SpotBugsParseFilterMakePrg ( 'Xspotbugs' , '' ), 'classfiles' )) 278 279" Write 45 mock-up class files for 10 source files. 280for [ class_dir , src_dir , package ] in [ 281 \[ 'Xspotbugs/tests/' , 'Xspotbugs/src/tests/' , '' ], 282 \[ 'Xspotbugs/tests/α/' , 'Xspotbugs/src/tests/α/' , 'package α;' ], 283 \[ 'Xspotbugs/tests/α/β/' , 'Xspotbugs/src/tests/α/β/' , 'package α.β;' ], 284 \[ 'Xspotbugs/tests/α/β/γ/' , 'Xspotbugs/src/tests/α/β/γ/' , 'package α.β.γ;' ], 285 \[ 'Xspotbugs/tests/α/β/γ/δ/' , 'Xspotbugs/src/tests/α/β/γ/δ/' , 'package α.β.γ.δ;' ]] 286for class_file in [ '𐌂1$1.class' , '𐌂1$1𐌉𐌉1.class' , '𐌂1$𐌂11$𐌉𐌉2.class' , 287 \'𐌂1$𐌂11.class' , '𐌂1.class' , '𐌂2$1𐌄.class' , '𐌂2$1𐌓.class' , '𐌂2.class' ] 288call writefile ( 0 zcafe.babe.0000.0041, class_dir .. class_file) 289endfor 290call writefile ( 0 zcafe.babe.0000.0041, class_dir .. 'package-info.class') 291 292" Write Java source files. 293let type_file = src_dir .. '𐌂1.java' 294call writefile ( insert ( copy ( lines ), package ), type_file ) 295let package_file = src_dir .. 'package-info.java' 296call writefile ([ package ], src_dir .. 'package-info.java' ) 297 298" Note that using "off" for the first _outer_ iteration is preferable 299" because only then "hlexists()" may be 0 (see "compiler/spotbugs.vim"). 300for s in [ 'off' , 'on' ] 301execute 'syntax ' .. s 302 303execute 'edit ' .. type_file 304compiler spotbugs 305let result = s: SpotBugsParseFilterMakePrg ( 'Xspotbugs' , & l: makeprg ) 306call assert_equal ( results [ type_file ]. Sourcepath (), result . sourcepath ) 307call assert_equal ( results [ type_file ]. classfiles , result . classfiles ) 308bwipeout 309 310execute 'edit ' .. package_file 311compiler spotbugs 312let result = s: SpotBugsParseFilterMakePrg ( 'Xspotbugs' , & l: makeprg ) 313call assert_equal ( results [ package_file ]. Sourcepath (), result . sourcepath ) 314call assert_equal ( results [ package_file ]. classfiles , result . classfiles ) 315bwipeout 316endfor 317endfor 318 319let & shellslash = save_shellslash 320endfunc 321 322func s: SpotBugsBeforeFileTypeTryPluginAndClearCache ( state ) 323" Ponder over "extend(spotbugs#DefaultProperties(), g:spotbugs_properties)" 324" in "ftplugin/java.vim". 325let g: spotbugs#state = a: state 326runtime autoload/spotbugs.vim 327endfunc 328 329func Test_compiler_spotbugs_properties () 330let save_shellslash = & shellslash 331set shellslash 332setlocal makeprg = 333filetype plugin on 334 335call assert_true ( mkdir ( 'Xspotbugs/src' , 'pR' )) 336call assert_true ( mkdir ( 'Xspotbugs/tests' , 'pR' )) 337let type_file = 'Xspotbugs/src/𐌄.java' 338let test_file = 'Xspotbugs/tests/𐌄$.java' 339call writefile ([ 'enum 𐌄{}' ], type_file ) 340call writefile ([ 'class 𐌄${}' ], test_file ) 341 342" TEST INTEGRATION WITH A BOGUS COMPILER PLUGIN. 343if ! filereadable ( $ VIMRUNTIME .. '/compiler/foo.vim' ) && ! executable ( 'foo' ) 344let g: spotbugs_properties = { 'compiler' : 'foo' } 345" XXX: In case this "if" block is no longer first. 346call s: SpotBugsBeforeFileTypeTryPluginAndClearCache ({ 347 \'compiler' : g: spotbugs_properties . compiler , 348 \}) 349execute 'edit ' .. type_file 350call assert_equal ( 'java' , & l: filetype ) 351" This variable will indefinitely keep the compiler name. 352call assert_equal ( 'foo' , g: spotbugs#state . compiler ) 353" The "compiler" entry should be gone after FileType and default entries 354" should only appear for a supported compiler. 355call assert_false ( has_key ( g: spotbugs_properties , 'compiler' )) 356call assert_true ( empty ( g: spotbugs_properties )) 357" Query default implementations. 358call assert_true ( exists ( '*spotbugs#DefaultProperties' )) 359call assert_true ( exists ( '*spotbugs#DefaultPreCompilerAction' )) 360call assert_true ( exists ( '*spotbugs#DefaultPreCompilerTestAction' )) 361call assert_true ( empty ( spotbugs#DefaultProperties ())) 362" Get a ":message". 363redir => out 364call spotbugs#DefaultPreCompilerAction () 365redir END 366call assert_equal ( 'Not supported: "foo"' , out [ stridx ( out , 'Not' ) :]) 367" Get a ":message". 368redir => out 369call spotbugs#DefaultPreCompilerTestAction () 370redir END 371call assert_equal ( 'Not supported: "foo"' , out [ stridx ( out , 'Not' ) :]) 372" No ":autocmd"s without one of "PreCompiler*Action", "PostCompilerAction". 373call assert_false ( exists ( '#java_spotbugs' )) 374bwipeout 375endif 376 377let s: spotbugs_results = { 378 \'preActionDone' : 0 , 379 \'preTestActionDone' : 0 , 380 \'preTestLocalActionDone' : 0 , 381 \'postActionDone' : 0 , 382 \'preCommandArguments' : '' , 383 \'preTestCommandArguments' : '' , 384 \'postCommandArguments' : '' , 385 \} 386defer execute('unlet s:spotbugs_results') 387 388func ! g: SpotBugsPreAction () abort 389let s: spotbugs_results . preActionDone = 1 390" XXX: Notify the spotbugs compiler about success or failure. 391cc 392endfunc 393defer execute('delfunction g:SpotBugsPreAction') 394 395func ! g: SpotBugsPreTestAction () abort 396let s: spotbugs_results . preTestActionDone = 1 397" XXX: Let see compilation fail. 398throw 'Oops' 399endfunc 400defer execute('delfunction g:SpotBugsPreTestAction') 401 402func ! g: SpotBugsPreTestLocalAction () abort 403let s: spotbugs_results . preTestLocalActionDone = 1 404" XXX: Notify the spotbugs compiler about success or failure. 405cc 406endfunc 407defer execute('delfunction g:SpotBugsPreTestLocalAction') 408 409func ! g: SpotBugsPostAction () abort 410let s: spotbugs_results . postActionDone = 1 411endfunc 412defer execute('delfunction g:SpotBugsPostAction') 413 414func ! g: SpotBugsPreCommand ( arguments ) abort 415let s: spotbugs_results . preActionDone = 1 416let s: spotbugs_results . preCommandArguments = a: arguments 417" XXX: Notify the spotbugs compiler about success or failure. 418cc 419endfunc 420defer execute('delfunction g:SpotBugsPreCommand') 421 422func ! g: SpotBugsPreTestCommand ( arguments ) abort 423let s: spotbugs_results . preTestActionDone = 1 424let s: spotbugs_results . preTestCommandArguments = a: arguments 425" XXX: Notify the spotbugs compiler about success or failure. 426cc 427endfunc 428defer execute('delfunction g:SpotBugsPreTestCommand') 429 430func ! g: SpotBugsPostCommand ( arguments ) abort 431let s: spotbugs_results . postActionDone = 1 432let s: spotbugs_results . postCommandArguments = a: arguments 433endfunc 434defer execute('delfunction g:SpotBugsPostCommand') 435 436func ! g: SpotBugsPostCompilerActionExecutor ( action ) abort 437try 438" XXX: Notify the spotbugs compiler about success or failure. 439cc 440catch /\<E42:/ 441execute a: action 442endtry 443endfunc 444defer execute('delfunction g:SpotBugsPostCompilerActionExecutor') 445 446" TEST INTEGRATION WITH A SUPPORTED COMPILER PLUGIN. 447if filereadable ( $ VIMRUNTIME .. '/compiler/maven.vim' ) 448let save_PATH = $ PATH 449if ! executable ( 'mvn' ) 450if has ( 'win32' ) 451let $ PATH = 'Xspotbugs;' .. $ PATH 452" This is what ":help executable()" suggests. 453call writefile ([], 'Xspotbugs/mvn.cmd' ) 454else 455let $ PATH = 'Xspotbugs:' .. $ PATH 456call writefile ([], 'Xspotbugs/mvn' ) 457call setfperm ( 'Xspotbugs/mvn' , 'rwx------' ) 458endif 459endif 460 461let g: spotbugs_properties = { 462 \'compiler' : 'maven' , 463 \'PreCompilerAction' : function ( 'g:SpotBugsPreAction' ), 464 \'PreCompilerTestAction' : function ( 'g:SpotBugsPreTestAction' ), 465 \'PostCompilerAction' : function ( 'g:SpotBugsPostAction' ), 466 \} 467" XXX: In case this is a runner-up ":edit". 468call s: SpotBugsBeforeFileTypeTryPluginAndClearCache ({ 469 \'compiler' : g: spotbugs_properties . compiler , 470 \}) 471execute 'edit ' .. type_file 472call assert_equal ( 'java' , & l: filetype ) 473call assert_equal ( 'maven' , g: spotbugs#state . compiler ) 474call assert_false ( has_key ( g: spotbugs_properties , 'compiler' )) 475call assert_false ( empty ( g: spotbugs_properties )) 476" Query default implementations. 477call assert_true ( exists ( '*spotbugs#DefaultProperties' )) 478call assert_equal ( sort ([ 479 \'PreCompilerAction' , 480 \'PreCompilerTestAction' , 481 \'PostCompilerAction' , 482 \'sourceDirPath' , 483 \'classDirPath' , 484 \'testSourceDirPath' , 485 \'testClassDirPath' , 486 \]), 487 \sort ( keys ( spotbugs#DefaultProperties ()))) 488" Some ":autocmd"s with one of "PreCompiler*Action", "PostCompilerAction". 489call assert_true ( exists ( '#java_spotbugs' )) 490call assert_true ( exists ( '#java_spotbugs#Syntax' )) 491call assert_true ( exists ( '#java_spotbugs#User' )) 492call assert_equal ( 2 , exists ( ':SpotBugsDefineBufferAutocmd' )) 493" SpotBugsDefineBufferAutocmd SigUSR1 User SigUSR1 User SigUSR1 User 494" call assert_true(exists('#java_spotbugs#SigUSR1')) 495SpotBugsDefineBufferAutocmd Signal User Signal User Signal User 496call assert_true ( exists ( '#java_spotbugs#Signal' )) 497call assert_true ( exists ( '#java_spotbugs#Syntax' )) 498call assert_true ( exists ( '#java_spotbugs#User' )) 499call assert_equal ( 2 , exists ( ':SpotBugsRemoveBufferAutocmd' )) 500" SpotBugsRemoveBufferAutocmd SigUSR1 User SigUSR1 User UserGettingBored 501" call assert_false(exists('#java_spotbugs#SigUSR1')) 502SpotBugsRemoveBufferAutocmd Signal User Signal User UserGettingBored 503call assert_false ( exists ( '#java_spotbugs#Signal' )) 504call assert_true ( exists ( '#java_spotbugs#Syntax' )) 505call assert_true ( exists ( '#java_spotbugs#User' )) 506 507let s: spotbugs_results . preActionDone = 0 508let s: spotbugs_results . preTestActionDone = 0 509let s: spotbugs_results . postActionDone = 0 510 511doautocmd java_spotbugs Syntax 512call assert_false ( exists ( '#java_spotbugs#Syntax' )) 513 514" No match: "type_file !~# 'src/main/java'". 515call assert_false ( s: spotbugs_results . preActionDone ) 516" No match: "type_file !~# 'src/test/java'". 517call assert_false ( s: spotbugs_results . preTestActionDone ) 518" No pre-match, no post-action. 519call assert_false ( s: spotbugs_results . postActionDone ) 520" Without a match, confirm that ":compiler spotbugs" has NOT run. 521call assert_true ( empty ( & l: makeprg )) 522 523let s: spotbugs_results . preActionDone = 0 524let s: spotbugs_results . preTestActionDone = 0 525let s: spotbugs_results . postActionDone = 0 526" Update path entries. (Note that we cannot use just "src" because there 527" is another "src" directory nearer the filesystem root directory, i.e. 528" "vim/vim/src/testdir/Xspotbugs/src", and "s:DispatchAction()" (see 529" "ftplugin/java.vim") will match "vim/vim/src/testdir/Xspotbugs/tests" 530" against "src".) 531let g: spotbugs_properties . sourceDirPath = [ 'Xspotbugs/src' ] 532let g: spotbugs_properties . classDirPath = [ 'Xspotbugs/src' ] 533let g: spotbugs_properties . testSourceDirPath = [ 'tests' ] 534let g: spotbugs_properties . testClassDirPath = [ 'tests' ] 535 536doautocmd java_spotbugs User 537" No match: "type_file !~# 'src/main/java'" (with old "*DirPath" values 538" cached). 539call assert_false ( s: spotbugs_results . preActionDone ) 540" No match: "type_file !~# 'src/test/java'" (with old "*DirPath" values 541" cached). 542call assert_false ( s: spotbugs_results . preTestActionDone ) 543" No pre-match, no post-action. 544call assert_false ( s: spotbugs_results . postActionDone ) 545" Without a match, confirm that ":compiler spotbugs" has NOT run. 546call assert_true ( empty ( & l: makeprg )) 547 548let s: spotbugs_results . preActionDone = 0 549let s: spotbugs_results . preTestActionDone = 0 550let s: spotbugs_results . postActionDone = 0 551" XXX: Re-build ":autocmd"s from scratch with new values applied. 552doautocmd FileType 553 554call assert_true ( exists ( 'b:spotbugs_syntax_once' )) 555doautocmd java_spotbugs User 556" A match: "type_file =~# 'Xspotbugs/src'" (with new "*DirPath" values 557" cached). 558call assert_true ( s: spotbugs_results . preActionDone ) 559" No match: "type_file !~# 'tests'" (with new "*DirPath" values cached). 560call assert_false ( s: spotbugs_results . preTestActionDone ) 561" For a pre-match, a post-action. 562call assert_true ( s: spotbugs_results . postActionDone ) 563 564" With a match, confirm that ":compiler spotbugs" has run. 565if has ( 'win32' ) 566call assert_match ( '^spotbugs\.bat\s' , & l: makeprg ) 567else 568call assert_match ( '^spotbugs\s' , & l: makeprg ) 569endif 570 571bwipeout 572setlocal makeprg = 573let s: spotbugs_results . preActionDone = 0 574let s: spotbugs_results . preTestActionDone = 0 575let s: spotbugs_results . preTestLocalActionDone = 0 576let s: spotbugs_results . postActionDone = 0 577 578execute 'edit ' .. test_file 579" Prepare a buffer-local, incomplete variant of properties, relying on 580" "ftplugin/java.vim" to take care of merging in unique entries, if any, 581" from "g:spotbugs_properties". 582let b: spotbugs_properties = { 583 \'PreCompilerTestAction' : function ( 'g:SpotBugsPreTestLocalAction' ), 584 \} 585call assert_equal ( 'java' , & l: filetype ) 586call assert_true ( exists ( '#java_spotbugs' )) 587call assert_true ( exists ( '#java_spotbugs#Syntax' )) 588call assert_true ( exists ( '#java_spotbugs#User' )) 589call assert_fails ( 'doautocmd java_spotbugs Syntax' , 'Oops' ) 590call assert_false ( exists ( '#java_spotbugs#Syntax' )) 591" No match: "test_file !~# 'Xspotbugs/src'". 592call assert_false ( s: spotbugs_results . preActionDone ) 593" A match: "test_file =~# 'tests'". 594call assert_true ( s: spotbugs_results . preTestActionDone ) 595call assert_false ( s: spotbugs_results . preTestLocalActionDone ) 596" No action after pre-failure (the thrown "Oops" doesn't qualify for ":cc"). 597call assert_false ( s: spotbugs_results . postActionDone ) 598" No ":compiler spotbugs" will be run after pre-failure. 599call assert_true ( empty ( & l: makeprg )) 600 601let s: spotbugs_results . preActionDone = 0 602let s: spotbugs_results . preTestActionDone = 0 603let s: spotbugs_results . preTestLocalActionDone = 0 604let s: spotbugs_results . postActionDone = 0 605" XXX: Re-build ":autocmd"s from scratch with buffer-local values applied. 606doautocmd FileType 607 608call assert_true ( exists ( 'b:spotbugs_syntax_once' )) 609doautocmd java_spotbugs User 610" No match: "test_file !~# 'Xspotbugs/src'". 611call assert_false ( s: spotbugs_results . preActionDone ) 612" A match: "test_file =~# 'tests'". 613call assert_true ( s: spotbugs_results . preTestLocalActionDone ) 614call assert_false ( s: spotbugs_results . preTestActionDone ) 615" For a pre-match, a post-action. 616call assert_true ( s: spotbugs_results . postActionDone ) 617 618" With a match, confirm that ":compiler spotbugs" has run. 619if has ( 'win32' ) 620call assert_match ( '^spotbugs\.bat\s' , & l: makeprg ) 621else 622call assert_match ( '^spotbugs\s' , & l: makeprg ) 623endif 624 625setlocal makeprg = 626let s: spotbugs_results . preActionDone = 0 627let s: spotbugs_results . preTestActionDone = 0 628let s: spotbugs_results . preTestLocalActionDone = 0 629let s: spotbugs_results . postActionDone = 0 630let s: spotbugs_results . preCommandArguments = '' 631let s: spotbugs_results . preTestCommandArguments = '' 632let s: spotbugs_results . postCommandArguments = '' 633" XXX: Compose the assigned "*Command"s with the default Maven "*Action"s. 634let b: spotbugs_properties = { 635 \'compiler' : 'maven' , 636 \'DefaultPreCompilerTestCommand' : function ( 'g:SpotBugsPreTestCommand' ), 637 \'DefaultPreCompilerCommand' : function ( 'g:SpotBugsPreCommand' ), 638 \'DefaultPostCompilerCommand' : function ( 'g:SpotBugsPostCommand' ), 639 \'PostCompilerActionExecutor' : function ( 'g:SpotBugsPostCompilerActionExecutor' ), 640 \'augroupForPostCompilerAction' : 'java_spotbugs_test' , 641 \'sourceDirPath' : [ 'Xspotbugs/src' ], 642 \'classDirPath' : [ 'Xspotbugs/src' ], 643 \'testSourceDirPath' : [ 'tests' ], 644 \'testClassDirPath' : [ 'tests' ], 645 \} 646unlet g: spotbugs_properties 647" XXX: Re-build ":autocmd"s from scratch with buffer-local values applied. 648call s: SpotBugsBeforeFileTypeTryPluginAndClearCache ({ 649 \'compiler' : b: spotbugs_properties . compiler , 650 \'commands' : { 651 \'DefaultPreCompilerTestCommand' : 652 \b: spotbugs_properties . DefaultPreCompilerTestCommand , 653 \'DefaultPreCompilerCommand' : 654 \b: spotbugs_properties . DefaultPreCompilerCommand , 655 \'DefaultPostCompilerCommand' : 656 \b: spotbugs_properties . DefaultPostCompilerCommand , 657 \}, 658 \}) 659doautocmd FileType 660 661call assert_equal ( 'maven' , g: spotbugs#state . compiler ) 662call assert_equal ( sort ([ 663 \'DefaultPreCompilerTestCommand' , 664 \'DefaultPreCompilerCommand' , 665 \'DefaultPostCompilerCommand' , 666 \]), 667 \sort ( keys ( g: spotbugs#state . commands ))) 668call assert_true ( exists ( 'b:spotbugs_syntax_once' )) 669doautocmd java_spotbugs User 670" No match: "test_file !~# 'Xspotbugs/src'". 671call assert_false ( s: spotbugs_results . preActionDone ) 672call assert_true ( empty ( s: spotbugs_results . preCommandArguments )) 673" A match: "test_file =~# 'tests'". 674call assert_true ( s: spotbugs_results . preTestActionDone ) 675call assert_equal ( 'test-compile' , s: spotbugs_results . preTestCommandArguments ) 676" For a pre-match, a post-action. 677call assert_true ( s: spotbugs_results . postActionDone ) 678call assert_equal ( '%:S' , s: spotbugs_results . postCommandArguments ) 679 680" With a match, confirm that ":compiler spotbugs" has run. 681if has ( 'win32' ) 682call assert_match ( '^spotbugs\.bat\s' , & l: makeprg ) 683else 684call assert_match ( '^spotbugs\s' , & l: makeprg ) 685endif 686 687setlocal makeprg = 688let s: spotbugs_results . preActionDone = 0 689let s: spotbugs_results . preTestActionOtherDone = 0 690let s: spotbugs_results . preTestLocalActionDone = 0 691let s: spotbugs_results . postActionDone = 0 692let s: spotbugs_results . preCommandArguments = '' 693let s: spotbugs_results . preTestCommandArguments = '' 694let s: spotbugs_results . postCommandArguments = '' 695 696" When "PostCompilerActionExecutor", "Pre*Action" and/or "Pre*TestAction", 697" and "Post*Action" are available, "#java_spotbugs_post" must be defined. 698call assert_true ( exists ( '#java_spotbugs_post' )) 699call assert_true ( exists ( '#java_spotbugs_post#User' )) 700call assert_false ( exists ( '#java_spotbugs_post#ShellCmdPost' )) 701call assert_false ( exists ( '#java_spotbugs_test#ShellCmdPost' )) 702 703" Re-link a Funcref on the fly. 704func ! g: SpotBugsPreTestCommand ( arguments ) abort 705let s: spotbugs_results . preTestActionOtherDone = 1 706let s: spotbugs_results . preTestCommandArguments = a: arguments 707" Define a once-only ":autocmd" for "#java_spotbugs_test#ShellCmdPost". 708doautocmd java_spotbugs_post User 709" XXX: Do NOT use ":cc" to notify the spotbugs compiler about success or 710" failure, and assume the transfer of control to a ShellCmdPost command. 711endfunc 712 713doautocmd java_spotbugs User 714" No match: "test_file !~# 'Xspotbugs/src'". 715call assert_false ( s: spotbugs_results . preActionDone ) 716call assert_true ( empty ( s: spotbugs_results . preCommandArguments )) 717" A match: "test_file =~# 'tests'". 718call assert_true ( s: spotbugs_results . preTestActionOtherDone ) 719call assert_equal ( 'test-compile' , s: spotbugs_results . preTestCommandArguments ) 720" For a pre-match, no post-action (without ":cc") UNLESS a ShellCmdPost 721" event is consumed whose command will invoke "PostCompilerActionExecutor" 722" and the latter will accept a post-compiler action argument. 723call assert_false ( s: spotbugs_results . postActionDone ) 724call assert_true ( exists ( '#java_spotbugs_test#ShellCmdPost' )) 725doautocmd ShellCmdPost 726call assert_false ( exists ( '#java_spotbugs_test#ShellCmdPost' )) 727call assert_true ( s: spotbugs_results . postActionDone ) 728call assert_equal ( '%:S' , s: spotbugs_results . postCommandArguments ) 729 730" With a match, confirm that ":compiler spotbugs" has run. 731if has ( 'win32' ) 732call assert_match ( '^spotbugs\.bat\s' , & l: makeprg ) 733else 734call assert_match ( '^spotbugs\s' , & l: makeprg ) 735endif 736 737bwipeout 738setlocal makeprg = 739let $ PATH = save_PATH 740endif 741 742filetype plugin off 743setlocal makeprg = 744let & shellslash = save_shellslash 745endfunc 746 747func Test_compiler_just () 748CheckFeature quickfix 749 750compiler just 751call assert_equal ( 'just' , b: current_compiler ) 752call assert_equal ( 'just' , & makeprg ) 753let verbose_efm = execute ( 'verbose set efm' ) 754call assert_match ( 'Last set from .*[/\\]compiler[/\\]just.vim ' , verbose_efm ) 755 756" Test that the errorformat can parse just error output 757let lines =<< trim END 758error: Variable `name` not defined 759——▶ justfile:2:15 760│ 7612 │ echo {{name}} 762│ ^^^^ 763END 764call writefile ( lines , 'Xjusterr.txt' ) 765cgetfile Xjusterr.txt 766let l = getqflist () 767call assert_equal ( 1 , len ( l )) 768call assert_equal ( 'E' , l [ 0 ]. type ) 769call assert_equal ( 'Variable `name` not defined' , l [ 0 ]. text ) 770call assert_equal ( 2 , l [ 0 ]. lnum ) 771call assert_equal ( 15 , l [ 0 ]. col ) 772 773call setqflist ([]) 774call delete ( 'Xjusterr.txt' ) 775compiler make 776endfunc 777 778" vim: shiftwidth=2 sts=2 expandtab