robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3 4local describe , it , before_each =t . describe , t . it , t . before_each 5local clear =n . clear 6local command =n . command 7local eq =t . eq 8local exec_lua =n . exec_lua 9local matches =t . matches 10local ok =t . ok 11local pcall_err =t . pcall_err 12 13local foo ={ 14active =true , 15path ='/dev/null' , 16rev ='0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' , 17spec ={ 18name ='foo' , 19src ='https://foo.example/foo/foo' , 20} , 21} 22local bar ={ 23active =false , 24path ='/var/empty' , 25rev ='62cdb7020ff920e5aa642c3d4066950dd1f01f4d' , 26spec ={ 27name ='bar' , 28src ='https://foo.example/bar/bar' , 29version =vim . version . range ( '0.42.42rc1' ), 30} , 31} 32 33local function assert_success ( fn ) 34exec_lua ( fn ) 35ok ( exec_lua ( 'return _G.success' ), 'true' , '_G.success' ) 36end 37 38local function assert_completion ( pat , expected ) 39local completions =exec_lua ( function () 40return vim . fn . getcompletion ( pat , 'cmdline' ) 41end ) 42eq ( expected , completions ) 43end 44 45describe ( ':packupdate' , function () 46before_each ( function () 47clear () 48exec_lua ( function () 49vim . pack . get =function ( names , opts ) 50assert ( opts . info == false ) 51return { foo , bar } 52end 53end ) 54end ) 55 56it ( 'works' , function () 57assert_success ( function () 58vim . pack . update =function ( names , opts ) 59success =names == nil and opts . force ~= true and opts . _ex == true 60end 61vim . cmd . packupdate () 62 63vim . pack . update =function ( names , opts ) 64success =success 65and names [ 1 ] == 'foo' 66and names [ 2 ] == nil 67and opts . force ~= true 68and opts . _ex == true 69end 70vim . cmd . packupdate { 'foo' } 71end ) 72end ) 73 74it ( 'handles !' , function () 75assert_success ( function () 76vim . pack . update =function ( names , opts ) 77success =opts . force == true 78end 79vim . cmd . packupdate { bang =true } 80end ) 81end ) 82 83it ( 'handles args' , function () 84assert_success ( function () 85vim . pack . update =function ( names , opts ) 86success =opts . offline == true 87end 88vim . cmd . packupdate { '++offline' } 89 90vim . pack . update =function ( names , opts ) 91success =success and opts . target == 'lockfile' 92end 93vim . cmd . packupdate { '++lockfile' } 94end ) 95end ) 96 97it ( 'shows E5807' , function () 98eq ( 'Vim(packupdate):E5807: Plugin not installed: baz' , pcall_err ( command , 'packupdate baz' )) 99end ) 100 101it ( 'shows E5808' , function () 102exec_lua ( function () 103vim . pack . get =function ( names , opts ) 104return {} 105end 106end ) 107eq ( 'Vim(packupdate):E5808: Nothing to update' , pcall_err ( command , 'packupdate' )) 108end ) 109 110it ( 'has completion' , function () 111assert_completion ( 'packupdate ' , { 'bar' , 'foo' } ) 112assert_completion ( 'packupdate b' , { 'bar' } ) 113assert_completion ( 'packupdate ++' , { '++lockfile' , '++offline' } ) 114end ) 115 116it ( 'fails if runtime is missing/broken' , function () 117clear { 118args_rm ={ '-u' } , 119args ={ '-u' , 'NONE' } , 120env ={ VIMRUNTIME ='non-existent' } , 121} 122matches ( 123[[.*module 'vim%.pack' not found:]] , 124vim . split ( t . pcall_err ( n . command , 'packupdate foo' ), '\n' )[ 1 ] 125) 126end ) 127end ) 128 129describe ( ':packdel' , function () 130before_each ( function () 131clear () 132exec_lua ( function () 133vim . pack . get =function ( names , opts ) 134assert ( opts . info == false ) 135return { foo , bar } 136end 137end ) 138end ) 139 140it ( 'works' , function () 141assert_success ( function () 142vim . pack . del =function ( names , opts ) 143success =names [ 1 ] == 'bar' and names [ 2 ] == nil and opts . force ~= true and opts . _ex == true 144end 145vim . cmd . packdel { 'bar' } 146end ) 147end ) 148 149it ( 'handles !' , function () 150assert_success ( function () 151vim . pack . del =function ( names , opts ) 152success =opts . force == true 153end 154vim . cmd . packdel { 'bar' , bang =true } 155end ) 156end ) 157 158it ( 'handles ++all' , function () 159assert_success ( function () 160vim . pack . del =function ( names , opts ) 161success =vim . list_contains ( names , 'bar' ) and not vim . list_contains ( names , 'foo' ) 162end 163vim . cmd . packdel { '++all' } 164 165vim . pack . del =function ( names , opts ) 166success =success and vim . list_contains ( names , 'foo' ) and vim . list_contains ( names , 'bar' ) 167end 168vim . cmd . packdel { '++all' , bang =true } 169end ) 170end ) 171 172it ( 'shows E5807' , function () 173eq ( 'Vim(packdel):E5807: Plugin not installed: baz' , pcall_err ( command , 'packdel baz' )) 174end ) 175 176it ( 'shows E5809' , function () 177exec_lua ( function () 178vim . pack . get =function ( names , opts ) 179return {} 180end 181end ) 182eq ( 'Vim(packdel):E5809: Nothing to remove' , pcall_err ( command , 'packdel ++all' )) 183end ) 184 185it ( 'shows E5811' , function () 186eq ( 187'Vim(packdel):E5811: Cannot specify plugin names when using ++all' , 188pcall_err ( command , 'packdel bar ++all' ) 189) 190end ) 191 192it ( 'has completion' , function () 193assert_completion ( 'packdel ' , { 'bar' } ) 194assert_completion ( 'packdel! ' , { 'bar' , 'foo' } ) 195assert_completion ( 'packdel! b' , { 'bar' } ) 196assert_completion ( 'packdel ++' , { '++all' } ) 197assert_completion ( 'packdel! ++' , { '++all' } ) 198end ) 199 200it ( 'fails if runtime is missing/broken' , function () 201clear { 202args_rm ={ '-u' } , 203args ={ '-u' , 'NONE' } , 204env ={ VIMRUNTIME ='non-existent' } , 205} 206matches ( 207[[.*module 'vim%.pack' not found:]] , 208vim . split ( t . pcall_err ( n . command , 'packdel foo' ), '\n' )[ 1 ] 209) 210end ) 211end )