robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local curbuf_contents =n . curbuf_contents 8local command =n . command 9local eq , matches =t . eq , t . matches 10local getcompletion =n . fn . getcompletion 11local insert =n . insert 12local exec_lua =n . exec_lua 13local source =n . source 14local assert_alive =n . assert_alive 15local fn =n . fn 16local api =n . api 17local retry =t . retry 18 19describe ( ':checkhealth' , function () 20it ( 'detects invalid $VIMRUNTIME' , function () 21clear ( { 22env ={ VIMRUNTIME ='bogus' } , 23} ) 24local status , err =pcall ( command , 'checkhealth' ) 25eq ( false , status ) 26eq ( 'Invalid $VIMRUNTIME: bogus' , string . match ( err , 'Invalid.*' )) 27end ) 28 29it ( "detects invalid 'runtimepath'" , function () 30clear () 31command ( 'set runtimepath=bogus' ) 32local status , err =pcall ( command , 'checkhealth' ) 33eq ( false , status ) 34eq ( "Invalid 'runtimepath'" , string . match ( err , 'Invalid.*' )) 35end ) 36 37it ( 'detects invalid $VIM' , function () 38clear () 39-- Do this after startup, otherwise it just breaks $VIMRUNTIME. 40command ( "let $VIM='zub'" ) 41command ( 'checkhealth vim.health' ) 42retry ( nil , 10000 , function () 43matches ( 'ERROR $VIM .* zub' , curbuf_contents ()) 44end ) 45end ) 46 47it ( 'getcompletion()' , function () 48clear { args ={ '-u' , 'NORC' , '+set runtimepath+=test/functional/fixtures' } } 49 50eq ( 'nvim.zip' , getcompletion ( 'vim' , 'checkhealth' )[ 1 ]) 51eq ( 'vim.provider' , getcompletion ( 'vim.prov' , 'checkhealth' )[ 1 ]) 52eq ( 'vim.lsp' , getcompletion ( 'vim.ls' , 'checkhealth' )[ 1 ]) 53 54-- "test_plug/health/init.lua" should complete as "test_plug", not "test_plug.health". #30342 55eq ( { 56'test_plug' , 57'test_plug.full_render' , 58'test_plug.submodule' , 59'test_plug.submodule_empty' , 60'test_plug.success1' , 61'test_plug.success2' , 62} , getcompletion ( 'test_plug' , 'checkhealth' )) 63end ) 64 65it ( 'completion checks for vim.health._complete() return type #28456' , function () 66clear () 67exec_lua ( [[vim.health._complete = function() return 1 end]] ) 68eq ( {} , getcompletion ( '' , 'checkhealth' )) 69exec_lua ( [[vim.health._complete = function() return { 1 } end]] ) 70eq ( {} , getcompletion ( '' , 'checkhealth' )) 71assert_alive () 72end ) 73 74it ( 'cmdline completion works with multiple args #35054' , function () 75clear () 76n . feed ( ':checkhealth vim.ls<Tab>' ) 77eq ( 'checkhealth vim.lsp' , fn . getcmdline ()) 78n . feed ( ' vim.prov<Tab>' ) 79eq ( 'checkhealth vim.lsp vim.provider' , fn . getcmdline ()) 80end ) 81 82it ( 'vim.g.health' , function () 83clear { 84args_rm ={ '-u' } , 85args ={ '--clean' , '+set runtimepath+=test/functional/fixtures' } , 86} 87command ( "let g:health = {'style':'float'}" ) 88command ( 'checkhealth lsp' ) 89eq ( 90'editor' , 91exec_lua ( [[ 92return vim.api.nvim_win_get_config(0).relative 93]] ) 94) 95matches ( 'health%.lua:%d+>$' , fn . maparg ( 'q' , 'n' , false , false )) 96 97-- gO should not close the :checkhealth floating window. #34784 98command ( 'checkhealth full_render' ) 99local win =api . nvim_get_current_win () 100api . nvim_win_set_cursor ( win , { 5 , 1 } ) 101n . feed ( 'gO' ) 102eq ( true , api . nvim_win_is_valid ( win )) 103eq ( 'qf' , api . nvim_get_option_value ( 'filetype' , { buf =0 } )) 104end ) 105 106it ( "vim.provider works with a misconfigured 'shell'" , function () 107clear () 108command ( [[set shell=echo\ WRONG!!!]] ) 109command ( 'let g:loaded_perl_provider = 0' ) 110command ( 'let g:loaded_python3_provider = 0' ) 111command ( 'checkhealth vim.provider' ) 112eq ( nil , string . match ( curbuf_contents (), 'WRONG!!!' )) 113end ) 114 115it ( 'vim.lsp warns about unknown filetypes' , function () 116clear () 117exec_lua ( function () 118vim . filetype . add ( { extension ={ mdx ='mdx' } } ) 119vim . lsp . config ( 'builtin_registry_ft' , { 120cmd ={ 'true' } , 121filetypes ={ 'beancount' } , 122} ) 123vim . lsp . config ( 'custom_ft' , { 124cmd ={ 'true' } , 125filetypes ={ 'mdx' } , 126} ) 127vim . lsp . config ( 'bad_ft' , { 128cmd ={ 'true' } , 129filetypes ={ 'hbs' } , 130} ) 131vim . lsp . enable ( 'builtin_registry_ft' ) 132vim . lsp . enable ( 'custom_ft' ) 133vim . lsp . enable ( 'bad_ft' ) 134end ) 135command ( 'checkhealth vim.lsp' ) 136local report =curbuf_contents () 137eq ( nil , report : find ( "Unknown filetype 'beancount'" , 1 , true )) 138eq ( nil , report : find ( "Unknown filetype 'mdx'" , 1 , true )) 139eq ( 140true , 141report : find ( "Unknown filetype 'hbs' (Hint: filename extension != filetype)." , 1 , true ) ~= nil 142) 143eq ( true , report : find ( '- builtin_registry_ft:' , 1 , true ) ~= nil ) 144eq ( true , report : find ( '- custom_ft:' , 1 , true ) ~= nil ) 145eq ( true , report : find ( '- bad_ft:' , 1 , true ) ~= nil ) 146end ) 147 148it ( 'renders report when Nvim starts with -M' , function () 149clear { args ={ '-M' } } 150command ( 'checkhealth lsp' ) 151eq ( true , curbuf_contents () ~= '' ) 152end ) 153end ) 154 155describe ( 'vim.health' , function () 156before_each ( function () 157clear { args ={ '-u' , 'NORC' , '+set runtimepath+=test/functional/fixtures' } } 158end ) 159 160describe ( ':checkhealth' , function () 161it ( 'does not block on vim.health subprocesses' , function () 162exec_lua ( function () 163local system =vim . system 164vim . system =function ( cmd , opts , on_exit ) 165if cmd [ 1 ] == 'git' and cmd [ 2 ] == 'ls-remote' then 166_G . resolve_health_system =function () 167vim . system =system 168on_exit ( { code =1 , signal =0 , stdout ='' , stderr ='failed' } ) 169end 170return 171end 172return system ( cmd , opts , on_exit ) 173end 174end ) 175 176command ( 'checkhealth vim.health' ) 177eq ( 'function' , exec_lua ( 'return type(_G.resolve_health_system)' )) 178eq ( true , api . nvim_get_option_value ( 'modifiable' , { buf =0 } )) 179 180command ( 'let g:healthcheck_responsive = v:true' ) 181eq ( true , exec_lua ( 'return vim.g.healthcheck_responsive' )) 182exec_lua ( '_G.resolve_health_system()' ) 183 184retry ( nil , 5000 , function () 185eq ( false , api . nvim_get_option_value ( 'modifiable' , { buf =0 } )) 186end ) 187eq ( 'checkhealth' , api . nvim_get_option_value ( 'filetype' , { buf =0 } )) 188matches ( 'vim%.health:' , curbuf_contents ()) 189end ) 190 191it ( 'report_xx() renders correctly' , function () 192command ( 'checkhealth full_render' ) 193n . expect ( [[ 194============================================================================== 195test_plug.full_render: 1 ⚠️ 1 ❌ 196 197report 1 ~ 198- ✅ OK life is fine 199- ⚠️ WARNING no what installed 200- ADVICE: 201- pip what 202- make what 203 204report 2 ~ 205- stuff is stable 206- ❌ ERROR why no hardcopy 207- ADVICE: 208- :help |:hardcopy| 209- :help |:TOhtml| 210]] ) 211end ) 212 213it ( 'user FileType handler can modify report' , function () 214-- Define a FileType autocmd that removes emoji chars. 215source [[ 216autocmd FileType checkhealth :set modifiable | silent! %s/\v( ?[^\x00-\x7F])//g 217checkhealth full_render 218]] 219n . expect ( [[ 220============================================================================== 221test_plug.full_render: 1 1 222 223report 1 ~ 224- OK life is fine 225- WARNING no what installed 226- ADVICE: 227- pip what 228- make what 229 230report 2 ~ 231- stuff is stable 232- ERROR why no hardcopy 233- ADVICE: 234- :help |:hardcopy| 235- :help |:TOhtml| 236]] ) 237end ) 238 239it ( 'concatenates multiple reports' , function () 240command ( 'checkhealth success1 success2 test_plug' ) 241retry ( nil , 5000 , function () 242eq ( false , api . nvim_get_option_value ( 'modifiable' , { buf =0 } )) 243end ) 244n . expect ( [[ 245============================================================================== 246test_plug: ✅ 247 248report 1 ~ 249- ✅ OK everything is fine 250 251report 2 ~ 252- ✅ OK nothing to see here 253 254============================================================================== 255test_plug.success1: ✅ 256 257report 1 ~ 258- ✅ OK everything is fine 259 260report 2 ~ 261- ✅ OK nothing to see here 262 263============================================================================== 264test_plug.success2: ✅ 265 266another 1 ~ 267- ✅ OK ok 268]] ) 269end ) 270 271it ( 'lua plugins submodules' , function () 272command ( 'checkhealth test_plug.submodule' ) 273n . expect ( [[ 274============================================================================== 275test_plug.submodule: ✅ 276 277report 1 ~ 278- ✅ OK everything is fine 279 280report 2 ~ 281- ✅ OK nothing to see here 282]] ) 283end ) 284 285it ( '... including empty reports' , function () 286command ( 'checkhealth test_plug.submodule_empty' ) 287n . expect ( [[ 288============================================================================== 289test_plug.submodule_empty: 1 ❌ 290 291- ❌ ERROR The healthcheck report for "test_plug.submodule_empty" plugin is empty. 292]] ) 293end ) 294 295it ( 'highlights OK, ERROR' , function () 296local screen =Screen . new ( 50 , 11 ) 297screen : set_default_attr_ids ( { 298h1 ={ reverse =true } , 299h2 ={ foreground =tonumber ( '0x6a0dad' ) } , 300Ok ={ foreground =Screen . colors . LightGreen } , 301Error ={ foreground =Screen . colors . Red } , 302Done ={ foreground =Screen . colors . NvimDarkGreen } , 303Bar ={ foreground =Screen . colors . LightGrey , background =Screen . colors . DarkGrey } , 304} ) 305command ( 'checkhealth foo success1' ) 306-- Wait for the filetype plugin before changing window options. 307retry ( nil , 5000 , function () 308eq ( 'checkhealth' , api . nvim_get_option_value ( 'filetype' , { buf =0 } )) 309end ) 310command ( 'set nofoldenable nowrap laststatus=0' ) 311screen : expect { 312grid =[[ 313{Bar:^ }| 314{h1:foo: }| 315| 316- ❌ {Error:ERROR} No healthcheck found for "foo" plugin. | 317| 318{Bar: }| 319{h1:test_plug.success1: }| 320| 321{h2:report 1} | 322- ✅ {Ok:OK} everything is fine | 323{Done:checkhealth}: checks done | 324]] , 325} 326end ) 327 328it ( 'gracefully handles invalid healthcheck' , function () 329command ( 'checkhealth non_existent_healthcheck' ) 330-- luacheck: ignore 613 331n . expect ( [[ 332============================================================================== 333non_existent_healthcheck: 1 ❌ 334 335- ❌ ERROR No healthcheck found for "non_existent_healthcheck" plugin. 336]] ) 337end ) 338 339it ( 'does not use vim.health as a healthcheck' , function () 340-- vim.health is not a healthcheck 341command ( 'checkhealth vim' ) 342n . expect ( [[ 343ERROR: No healthchecks found.]] ) 344end ) 345 346it ( 'nested lua/ directory' , function () 347command ( 'checkhealth lua' ) 348n . expect ( [[ 349============================================================================== 350test_plug.lua: ✅ 351 352nested lua/ directory ~ 353- ✅ OK everything is ok 354]] ) 355end ) 356 357it ( '&rtp can contain nested path (by packadd)' , function () 358-- re-add to ensure this appears before new nested rtp 359command ( [[set runtimepath-=test/functional/fixtures]] ) 360command ( [[set runtimepath+=test/functional/fixtures]] ) 361command ( 'set packpath+=test/functional/fixtures' ) 362-- set rtp+=test/functional/fixtures/pack/foo/opt/healthy 363command ( 'packadd healthy' ) 364command ( 'checkhealth nest' ) 365n . expect ( [[ 366============================================================================== 367nest: ✅ 368 369healthy pack ~ 370- ✅ OK healthy ok 371]] ) 372end ) 373end ) 374end ) 375 376describe ( ':checkhealth window' , function () 377before_each ( function () 378clear { args ={ '-u' , 'NORC' , '+set runtimepath+=test/functional/fixtures' } } 379command ( 'set nofoldenable nowrap laststatus=0' ) 380end ) 381 382it ( 'opens directly if no buffer created' , function () 383local screen =Screen . new ( 50 , 11 , { ext_multigrid =true } ) 384screen : set_default_attr_ids { 385h1 ={ reverse =true } , 386h2 ={ foreground =tonumber ( '0x6a0dad' ) } , 387Done ={ foreground =Screen . colors . NvimDarkGreen } , 388[ 1 ] ={ foreground =Screen . colors . Blue , bold =true } , 389[ 14 ] ={ foreground =Screen . colors . LightGrey , background =Screen . colors . DarkGray } , 390[ 32 ] ={ foreground =Screen . colors . PaleGreen2 } , 391} 392command ( 'checkhealth success1' ) 393screen : expect { 394grid =[[ 395## grid 1 396[2:--------------------------------------------------]|*10 397[3:--------------------------------------------------]| 398## grid 2 399{14:^ }| 400{14: } | 401{h1:test_plug. }| 402{h1:success1: }| 403{h1: ✅} | 404| 405{h2:report 1} | 406- ✅ {32:OK} everything is fine | 407| 408{h2:report 2} | 409## grid 3 410{Done:checkhealth}: checks done | 411]] , 412} 413end ) 414 415local function test_health_vsplit ( left , emptybuf , mods ) 416local screen =Screen . new ( 50 , 19 , { ext_multigrid =true } ) 417screen : set_default_attr_ids { 418h1 ={ reverse =true } , 419h2 ={ foreground =tonumber ( '0x6a0dad' ) } , 420Done ={ foreground =Screen . colors . NvimDarkGreen } , 421[ 1 ] ={ foreground =Screen . colors . Blue , bold =true } , 422[ 14 ] ={ foreground =Screen . colors . LightGrey , background =Screen . colors . DarkGray } , 423[ 32 ] ={ foreground =Screen . colors . PaleGreen2 } , 424} 425if not emptybuf then 426insert ( 'hello' ) 427end 428command ( mods .. ' checkhealth success1' ) 429screen : expect ( 430( [[ 431## grid 1 432%s 433[3:--------------------------------------------------]| 434## grid 2 435%s | 436{1:~ }|*17 437## grid 3 438{Done:checkhealth}: checks done | 439## grid 4 440{14:^ }| 441{14: }|*2 442{14: } | 443{h1:test_plug. }| 444{h1:success1: }| 445{h1: }| 446{h1: ✅} | 447| 448{h2:report 1} | 449- ✅ {32:OK} everything is | 450fine | 451| 452{h2:report 2} | 453- ✅ {32:OK} nothing to see | 454here | 455| 456{1:~ }| 457]] ): format ( 458left and '[4:-------------------------]│[2:------------------------]|*18' 459or '[2:------------------------]│[4:-------------------------]|*18' , 460emptybuf and ' ' or 'hello' 461) 462) 463end 464 465for _ , mods in ipairs ( { 'vertical' , 'leftabove vertical' , 'topleft vertical' } ) do 466it (( 'opens in left vsplit window with :%s and no buffer created' ): format ( mods ), function () 467test_health_vsplit ( true , true , mods ) 468end ) 469it (( 'opens in left vsplit window with :%s and non-empty buffer' ): format ( mods ), function () 470test_health_vsplit ( true , false , mods ) 471end ) 472end 473 474for _ , mods in ipairs ( { 'rightbelow vertical' , 'botright vertical' } ) do 475it (( 'opens in right vsplit window with :%s and no buffer created' ): format ( mods ), function () 476test_health_vsplit ( false , true , mods ) 477end ) 478it (( 'opens in right vsplit window with :%s and non-empty buffer' ): format ( mods ), function () 479test_health_vsplit ( false , false , mods ) 480end ) 481end 482 483local function test_health_split ( top , emptybuf , mods ) 484local screen =Screen . new ( 50 , 25 , { ext_multigrid =true } ) 485screen . _default_attr_ids =nil 486if not emptybuf then 487insert ( 'hello' ) 488end 489command ( mods .. ' checkhealth success1' ) 490screen : expect ( 491( [[ 492## grid 1 493%s 494[3:--------------------------------------------------]| 495## grid 2 496%s | 497~ |*10 498## grid 3 499checkhealth: checks done | 500## grid 4 501^ | 502| 503test_plug. | 504success1: | 505✅ | 506| 507report 1 | 508- ✅ OK everything is fine | 509| 510report 2 | 511- ✅ OK nothing to see here | 512| 513]] ): format ( 514top 515and [[ 516[4:--------------------------------------------------]|*12 517health:// [-] | 518[2:--------------------------------------------------]|*11]] 519or ( [[ 520[2:--------------------------------------------------]|*11 521[No Name] %s | 522[4:--------------------------------------------------]|*12]] ): format ( 523emptybuf and ' ' or '[+]' 524), 525emptybuf and ' ' or 'hello' 526) 527) 528end 529 530for _ , mods in ipairs ( { 'horizontal' , 'leftabove' , 'topleft' } ) do 531it (( 'opens in top split window with :%s and no buffer created' ): format ( mods ), function () 532test_health_split ( true , true , mods ) 533end ) 534it (( 'opens in top split window with :%s and non-empty buffer' ): format ( mods ), function () 535test_health_split ( true , false , mods ) 536end ) 537end 538 539for _ , mods in ipairs ( { 'rightbelow' , 'botright' } ) do 540it (( 'opens in bottom split window with :%s and no buffer created' ): format ( mods ), function () 541test_health_split ( false , true , mods ) 542end ) 543it (( 'opens in bottom split window with :%s and non-empty buffer' ): format ( mods ), function () 544test_health_split ( false , false , mods ) 545end ) 546end 547 548it ( 'opens in new tabpage after the current one' , function () 549-- create an empty buffer called "my_buff" 550api . nvim_create_buf ( false , true ) 551command ( 'file my_buff' ) 552command ( 'checkhealth success1' ) 553-- define a function that collects all buffers in each tab 554-- returns a dict like {tab1 = ["buf1", "buf2"], tab2 = ["buf3"]} 555source ( [[ 556function CollectBuffersPerTab() 557let buffs = {} 558for i in range(tabpagenr('$')) 559let key = 'tab' . (i + 1) 560let value = [] 561for j in tabpagebuflist(i + 1) 562call add(value, bufname(j)) 563endfor 564let buffs[key] = value 565endfor 566return buffs 567endfunction 568]] ) 569local buffers_per_tab =fn . CollectBuffersPerTab () 570eq ( buffers_per_tab , { tab1 ={ 'my_buff' } , tab2 ={ 'health://' } } ) 571command ( 'bwipe' ) 572command ( 'tab split | tab split | tab split | tabprevious' ) 573command ( 'checkhealth success1' ) 574buffers_per_tab =fn . CollectBuffersPerTab () 575eq ( buffers_per_tab , { 576tab1 ={ 'my_buff' } , 577tab2 ={ 'my_buff' } , 578tab3 ={ 'my_buff' } , 579tab4 ={ 'health://' } , 580tab5 ={ 'my_buff' } , 581} ) 582end ) 583end )