GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 1 | " Tests for GetLatestVimScripts plugin |
| 2 | |
| 3 | " vim feature |
| 4 | set nocp |
| 5 | set cpo&vim |
| 6 | |
| 7 | " constants |
| 8 | const s:dotvim= has("win32") ? "vimfiles" : ".vim" |
| 9 | const s:scriptdir = $"{$HOME}/{s:dotvim}/GetLatest" |
| 10 | const s:vimdir = expand("<script>:h:h:h") |
| 11 | const s:packages = { |
| 12 | \ 'vmb': { |
| 13 | \ 'spec': '4979 1 :AutoInstall: AnsiEsc.vim', |
| 14 | \ 'files': ['plugin/AnsiEscPlugin.vim', 'autoload/AnsiEsc.vim'] |
| 15 | \ }, |
| 16 | \ 'vim.bz2': { |
| 17 | \ 'spec': '514 1 :AutoInstall: mrswin.vim', |
| 18 | \ 'files': ['plugin/mrswin.vim'] |
| 19 | \ }, |
| 20 | \ 'vba.gz': { |
| 21 | \ 'spec': '120 1 :AutoInstall: Decho.vim', |
| 22 | \ 'package': 'GetLatest/Installed/Decho.vba', |
| 23 | \ 'files': ['plugin/Decho.vim', 'syntax/Decho.vim'] |
| 24 | \ }, |
| 25 | \ 'tar.xz': { |
| 26 | \ 'spec': '5632 1 :AutoInstall: dumpx', |
| 27 | \ 'package': 'GetLatest/Installed/dumpx.tar', |
| 28 | \ 'files': ['dumpx/plugin/dumpx.vim', 'dumpx/doc/dumpx.txt'] |
| 29 | \ } |
| 30 | \ } |
| 31 | |
| 32 | " Before each test recreate the .vim dir structure expected by GLVS and load the plugin |
| 33 | func SetUp() |
| 34 | |
| 35 | " add the required GetLatest dir (note $HOME is a dummy) |
| 36 | call mkdir(s:scriptdir, "p") |
| 37 | let &runtimepath = $"{$HOME}/{s:dotvim},{s:vimdir}/runtime" |
| 38 | |
| 39 | " add plugin dir |
| 40 | call mkdir($"{$HOME}/{s:dotvim}/plugin") |
| 41 | |
| 42 | " doc file is required for the packages which use :helptags |
| 43 | let docdir = $"{$HOME}/{s:dotvim}/doc" |
| 44 | call mkdir(docdir, "p") |
| 45 | exe $"split {docdir}/tags" |
| 46 | w! |
| 47 | bwipe! |
| 48 | |
| 49 | " load required plugins, getscript.vim would be loaded manually by the test |
| 50 | " (instead of relying on autoload) because set up depends on shell selection |
| 51 | runtime plugin/vimballPlugin.vim |
| 52 | runtime plugin/getscriptPlugin.vim |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 53 | endfunc |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 54 | |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 55 | func CheckTool(tool) |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 56 | " define tools location |
| 57 | if has('win32') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 58 | if executable('git') |
| 59 | let git_path = trim(system('powershell -Command "Split-Path (Split-Path (gcm git).Source)"')) |
| 60 | endif |
| 61 | |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 62 | if a:tool == 'bunzip2' |
| 63 | if executable('bunzip2') |
| 64 | let g:GetLatestVimScripts_bunzip2= "bunzip2" |
| 65 | elseif executable('7z') |
| 66 | let g:GetLatestVimScripts_bunzip2= "7z x" |
| 67 | elseif exists('git_path') |
| 68 | let g:GetLatestVimScripts_bunzip2= $'{git_path}\usr\bin\bunzip2' |
| 69 | else |
| 70 | throw "Skipped: Missing tool to decompress .bz2 files" |
| 71 | endif |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 72 | endif |
| 73 | |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 74 | if a:tool == 'gunzip' |
| 75 | if executable('gunzip') |
| 76 | let g:GetLatestVimScripts_gunzip= "gunzip" |
| 77 | elseif executable('7z') |
| 78 | let g:GetLatestVimScripts_gunzip="7z e" |
| 79 | elseif exists('git_path') |
| 80 | let g:GetLatestVimScripts_gunzip= $'{git_path}\usr\bin\gunzip' |
| 81 | else |
| 82 | throw "Skipped: Missing tool to decompress .gz files" |
| 83 | endif |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 84 | endif |
| 85 | |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 86 | if a:tool == 'unxz' |
| 87 | if executable('unxz') |
| 88 | let g:GetLatestVimScripts_unxz= "unxz" |
| 89 | elseif executable('7z') |
| 90 | let g:GetLatestVimScripts_unxz="7z x" |
| 91 | elseif exists('git_path') |
| 92 | let g:GetLatestVimScripts_unxz= $'{git_path}\mingw64\bin\unxz' |
| 93 | else |
| 94 | throw "Skipped: Missing tool to decompress .xz files" |
| 95 | endif |
| 96 | endif |
| 97 | else |
| 98 | " Mac or Unix |
| 99 | if a:tool == 'bunzip2' |
| 100 | if executable('bunzip2') |
| 101 | let g:GetLatestVimScripts_bunzip2= "bunzip2" |
| 102 | else |
| 103 | throw "Skipped: Missing tool to decompress .bz2 files" |
| 104 | endif |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 105 | endif |
| 106 | |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 107 | if a:tool == 'gunzip' |
| 108 | if executable('gunzip') |
| 109 | let g:GetLatestVimScripts_gunzip= "gunzip" |
| 110 | else |
| 111 | throw "Skipped: Missing tool to decompress .bz2 files" |
| 112 | endif |
| 113 | endif |
| 114 | |
| 115 | if a:tool == 'unxz' |
| 116 | if executable('unxz') |
| 117 | let g:GetLatestVimScripts_unxz= "unxz" |
| 118 | else |
| 119 | throw "Skipped: Missing tool to decompress .xz files" |
| 120 | endif |
| 121 | endif |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 122 | endif |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 123 | endfunc |
| 124 | |
| 125 | " After each test remove the contents of the .vim dir and reset the script |
| 126 | func TearDown() |
| 127 | call delete($"{$HOME}/{s:dotvim}", "rf") |
| 128 | |
| 129 | " getscript.vim include guard |
| 130 | unlet! g:loaded_getscript g:loaded_getscriptPlugin |
| 131 | " remove all globals (shell dependents) |
| 132 | let script_globals = keys(g:) |
| 133 | call filter(script_globals, 'v:val =~ "GetLatestVimScripts_"') |
| 134 | if len(script_globals) |
| 135 | call map(script_globals, '"g:" . v:val') |
| 136 | exe "unlet " . script_globals->join() |
| 137 | endif |
| 138 | endfunc |
| 139 | |
| 140 | " Ancillary functions |
| 141 | |
| 142 | func SetShell(shell) |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 143 | " select different shells |
| 144 | if a:shell == "default" |
| 145 | set shell& shellcmdflag& shellxquote& shellpipe& shellredir& |
| 146 | elseif a:shell == "powershell" " help dos-powershell |
| 147 | " powershell desktop is windows only |
| 148 | if !has("win32") |
| 149 | throw 'Skipped: powershell desktop is missing' |
| 150 | endif |
| 151 | set shell=powershell shellcmdflag=-NoProfile\ -Command shellxquote=\" |
| 152 | set shellpipe=2>&1\ \|\ Out-File\ -Encoding\ default shellredir=2>&1\ \|\ Out-File\ -Encoding\ default |
| 153 | elseif a:shell == "pwsh" " help dos-powershell |
| 154 | " powershell core works crossplatform |
| 155 | if !executable("pwsh") |
| 156 | throw 'Skipped: powershell core is missing' |
| 157 | endif |
| 158 | set shell=pwsh shellcmdflag=-NoProfile\ -c shellpipe=>%s\ 2>&1 shellredir=>%s\ 2>&1 |
| 159 | if has("win32") |
| 160 | set shellxquote=\" |
| 161 | else |
| 162 | set shellxquote= |
| 163 | endif |
| 164 | else |
| 165 | call assert_report("Trying to select and unknown shell") |
| 166 | endif |
| 167 | |
| 168 | " reload script to force new shell options |
| 169 | runtime autoload/getscript.vim |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 170 | endfunc |
| 171 | |
| 172 | func SelectScript(package) |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 173 | " add the corresponding file |
| 174 | exe $"split {s:scriptdir}/GetLatestVimScripts.dat" |
| 175 | let scripts =<< trim END |
| 176 | ScriptID SourceID Filename |
| 177 | -------------------------- |
| 178 | END |
| 179 | call setline(1, scripts) |
| 180 | call append(line('$'), s:packages[a:package]['spec']) |
| 181 | w! |
| 182 | bwipe! |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 183 | endfunc |
| 184 | |
| 185 | func ValidateInstall(package) |
| 186 | " check the package is expected |
| 187 | call assert_true(s:packages->has_key(a:package), "This package is unexpected") |
| 188 | |
| 189 | " check if installation work out |
| 190 | if s:packages[a:package]->has_key('package') |
| 191 | let check = filereadable($"{$HOME}/{s:dotvim}/".s:packages[a:package]['package']) |
| 192 | call assert_true(check, "The plugin was not downloaded") |
| 193 | endif |
| 194 | |
| 195 | call assert_true(s:packages[a:package]->has_key('files'), "This package lacks validation files") |
| 196 | for file in s:packages[a:package]['files'] |
| 197 | let check = filereadable($"{$HOME}/{s:dotvim}/".file) |
| 198 | call assert_true(check, "The plugin was not installed") |
| 199 | endfor |
| 200 | endfunc |
| 201 | |
| 202 | " Tests |
| 203 | " |
| 204 | func Test_glvs_default_vmb() |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 205 | " select different shells |
| 206 | call SetShell('default') |
| 207 | |
| 208 | " add the corresponding script |
| 209 | call SelectScript('vmb') |
| 210 | |
| 211 | " load the plugins specified |
| 212 | GLVS |
| 213 | |
| 214 | call ValidateInstall('vmb') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 215 | endfunc |
| 216 | |
| 217 | func Test_glvs_pwsh_vmb() |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 218 | " select different shells |
| 219 | call SetShell('pwsh') |
| 220 | |
| 221 | " add the corresponding script |
| 222 | call SelectScript('vmb') |
| 223 | |
| 224 | " load the plugins specified |
| 225 | GLVS |
| 226 | |
| 227 | call ValidateInstall('vmb') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 228 | endfunc |
| 229 | |
| 230 | func Test_glvs_powershell_vmb() |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 231 | " select different shells |
| 232 | call SetShell('powershell') |
| 233 | |
| 234 | " add the corresponding script |
| 235 | call SelectScript('vmb') |
| 236 | |
| 237 | " load the plugins specified |
| 238 | GLVS |
| 239 | |
| 240 | call ValidateInstall('vmb') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 241 | endfunc |
| 242 | |
| 243 | func Test_glvs_default_vim_bz2() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 244 | call CheckTool('bunzip2') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 245 | |
| 246 | " select different shells |
| 247 | call SetShell('default') |
| 248 | |
| 249 | " add the corresponding script |
| 250 | call SelectScript('vim.bz2') |
| 251 | |
| 252 | " load the plugins specified |
| 253 | GLVS |
| 254 | |
| 255 | call ValidateInstall('vim.bz2') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 256 | endfunc |
| 257 | |
| 258 | func Test_glvs_powershell_vim_bz2() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 259 | call CheckTool('bunzip2') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 260 | |
| 261 | " select different shells |
| 262 | call SetShell('powershell') |
| 263 | |
| 264 | " add the corresponding script |
| 265 | call SelectScript('vim.bz2') |
| 266 | |
| 267 | " load the plugins specified |
| 268 | GLVS |
| 269 | |
| 270 | call ValidateInstall('vim.bz2') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 271 | endfunc |
| 272 | |
| 273 | func Test_glvs_pwsh_vim_bz2() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 274 | call CheckTool('bunzip2') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 275 | |
| 276 | " select different shells |
| 277 | call SetShell('pwsh') |
| 278 | |
| 279 | " add the corresponding script |
| 280 | call SelectScript('vim.bz2') |
| 281 | |
| 282 | " load the plugins specified |
| 283 | GLVS |
| 284 | |
| 285 | call ValidateInstall('vim.bz2') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 286 | endfunc |
| 287 | |
| 288 | func Test_glvs_default_vba_gz() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 289 | call CheckTool('gunzip') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 290 | |
| 291 | " select different shells |
| 292 | call SetShell('default') |
| 293 | |
| 294 | " add the corresponding script |
| 295 | call SelectScript('vba.gz') |
| 296 | |
| 297 | " load the plugins specified |
| 298 | GLVS |
| 299 | |
| 300 | call ValidateInstall('vba.gz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 301 | endfunc |
| 302 | |
| 303 | func Test_glvs_powershell_vba_gz() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 304 | call CheckTool('gunzip') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 305 | |
| 306 | " select different shells |
| 307 | call SetShell('powershell') |
| 308 | |
| 309 | " add the corresponding script |
| 310 | call SelectScript('vba.gz') |
| 311 | |
| 312 | " load the plugins specified |
| 313 | GLVS |
| 314 | |
| 315 | call ValidateInstall('vba.gz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 316 | endfunc |
| 317 | |
| 318 | func Test_glvs_pwsh_vba_gz() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 319 | call CheckTool('gunzip') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 320 | |
| 321 | " select different shells |
| 322 | call SetShell('pwsh') |
| 323 | |
| 324 | " add the corresponding script |
| 325 | call SelectScript('vba.gz') |
| 326 | |
| 327 | " load the plugins specified |
| 328 | GLVS |
| 329 | |
| 330 | call ValidateInstall('vba.gz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 331 | endfunc |
| 332 | |
| 333 | func Test_glvs_default_tar_xz() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 334 | call CheckTool('unxz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 335 | |
| 336 | " select different shells |
| 337 | call SetShell('default') |
| 338 | |
| 339 | " add the corresponding script |
| 340 | call SelectScript('tar.xz') |
| 341 | |
| 342 | " load the plugins specified |
| 343 | GLVS |
| 344 | |
| 345 | call ValidateInstall('tar.xz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 346 | endfunc |
| 347 | |
| 348 | func Test_glvs_powershell_tar_xz() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 349 | call CheckTool('unxz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 350 | |
| 351 | " select different shells |
| 352 | call SetShell('powershell') |
| 353 | |
| 354 | " add the corresponding script |
| 355 | call SelectScript('tar.xz') |
| 356 | |
| 357 | " load the plugins specified |
| 358 | GLVS |
| 359 | |
| 360 | call ValidateInstall('tar.xz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 361 | endfunc |
| 362 | |
| 363 | func Test_glvs_pwsh_tar_xz() |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 364 | call CheckTool('unxz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 365 | |
| 366 | " select different shells |
| 367 | call SetShell('pwsh') |
| 368 | |
| 369 | " add the corresponding script |
| 370 | call SelectScript('tar.xz') |
| 371 | |
| 372 | " load the plugins specified |
| 373 | GLVS |
| 374 | |
| 375 | call ValidateInstall('tar.xz') |
GuyBrush | 13a6605 | 2024-11-12 20:18:14 +0100 | [diff] [blame] | 376 | endfunc |
Christian Brabandt | 85e3f24 | 2025-01-31 17:02:32 +0100 | [diff] [blame] | 377 | |
| 378 | " vim: set sw=4 ts=4 et: |