blob: 1970826ce6f46f31d14374c7f93cbf4b15625399 [file] [log] [blame]
GuyBrush13a66052024-11-12 20:18:14 +01001" Tests for GetLatestVimScripts plugin
2
3" vim feature
4set nocp
5set cpo&vim
6
7" constants
8const s:dotvim= has("win32") ? "vimfiles" : ".vim"
9const s:scriptdir = $"{$HOME}/{s:dotvim}/GetLatest"
10const s:vimdir = expand("<script>:h:h:h")
11const 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
33func 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 Brabandt85e3f242025-01-31 17:02:32 +010053endfunc
GuyBrush13a66052024-11-12 20:18:14 +010054
Christian Brabandt85e3f242025-01-31 17:02:32 +010055func CheckTool(tool)
GuyBrush13a66052024-11-12 20:18:14 +010056 " define tools location
57 if has('win32')
GuyBrush13a66052024-11-12 20:18:14 +010058 if executable('git')
59 let git_path = trim(system('powershell -Command "Split-Path (Split-Path (gcm git).Source)"'))
60 endif
61
Christian Brabandt85e3f242025-01-31 17:02:32 +010062 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
GuyBrush13a66052024-11-12 20:18:14 +010072 endif
73
Christian Brabandt85e3f242025-01-31 17:02:32 +010074 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
GuyBrush13a66052024-11-12 20:18:14 +010084 endif
85
Christian Brabandt85e3f242025-01-31 17:02:32 +010086 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
GuyBrush13a66052024-11-12 20:18:14 +0100105 endif
106
Christian Brabandt85e3f242025-01-31 17:02:32 +0100107 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
GuyBrush13a66052024-11-12 20:18:14 +0100122 endif
GuyBrush13a66052024-11-12 20:18:14 +0100123endfunc
124
125" After each test remove the contents of the .vim dir and reset the script
126func 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
138endfunc
139
140" Ancillary functions
141
142func SetShell(shell)
GuyBrush13a66052024-11-12 20:18:14 +0100143 " 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
GuyBrush13a66052024-11-12 20:18:14 +0100170endfunc
171
172func SelectScript(package)
GuyBrush13a66052024-11-12 20:18:14 +0100173 " 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!
GuyBrush13a66052024-11-12 20:18:14 +0100183endfunc
184
185func 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
200endfunc
201
202" Tests
203"
204func Test_glvs_default_vmb()
GuyBrush13a66052024-11-12 20:18:14 +0100205 " 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')
GuyBrush13a66052024-11-12 20:18:14 +0100215endfunc
216
217func Test_glvs_pwsh_vmb()
GuyBrush13a66052024-11-12 20:18:14 +0100218 " 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')
GuyBrush13a66052024-11-12 20:18:14 +0100228endfunc
229
230func Test_glvs_powershell_vmb()
GuyBrush13a66052024-11-12 20:18:14 +0100231 " 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')
GuyBrush13a66052024-11-12 20:18:14 +0100241endfunc
242
243func Test_glvs_default_vim_bz2()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100244 call CheckTool('bunzip2')
GuyBrush13a66052024-11-12 20:18:14 +0100245
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')
GuyBrush13a66052024-11-12 20:18:14 +0100256endfunc
257
258func Test_glvs_powershell_vim_bz2()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100259 call CheckTool('bunzip2')
GuyBrush13a66052024-11-12 20:18:14 +0100260
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')
GuyBrush13a66052024-11-12 20:18:14 +0100271endfunc
272
273func Test_glvs_pwsh_vim_bz2()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100274 call CheckTool('bunzip2')
GuyBrush13a66052024-11-12 20:18:14 +0100275
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')
GuyBrush13a66052024-11-12 20:18:14 +0100286endfunc
287
288func Test_glvs_default_vba_gz()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100289 call CheckTool('gunzip')
GuyBrush13a66052024-11-12 20:18:14 +0100290
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')
GuyBrush13a66052024-11-12 20:18:14 +0100301endfunc
302
303func Test_glvs_powershell_vba_gz()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100304 call CheckTool('gunzip')
GuyBrush13a66052024-11-12 20:18:14 +0100305
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')
GuyBrush13a66052024-11-12 20:18:14 +0100316endfunc
317
318func Test_glvs_pwsh_vba_gz()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100319 call CheckTool('gunzip')
GuyBrush13a66052024-11-12 20:18:14 +0100320
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')
GuyBrush13a66052024-11-12 20:18:14 +0100331endfunc
332
333func Test_glvs_default_tar_xz()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100334 call CheckTool('unxz')
GuyBrush13a66052024-11-12 20:18:14 +0100335
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')
GuyBrush13a66052024-11-12 20:18:14 +0100346endfunc
347
348func Test_glvs_powershell_tar_xz()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100349 call CheckTool('unxz')
GuyBrush13a66052024-11-12 20:18:14 +0100350
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')
GuyBrush13a66052024-11-12 20:18:14 +0100361endfunc
362
363func Test_glvs_pwsh_tar_xz()
Christian Brabandt85e3f242025-01-31 17:02:32 +0100364 call CheckTool('unxz')
GuyBrush13a66052024-11-12 20:18:14 +0100365
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')
GuyBrush13a66052024-11-12 20:18:14 +0100376endfunc
Christian Brabandt85e3f242025-01-31 17:02:32 +0100377
378" vim: set sw=4 ts=4 et: