blob: 765f8b5efb53e909d36f6c363da79d94ccbe2517 [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
53
54 " define tools location
55 if has('win32')
56
57 if executable('git')
58 let git_path = trim(system('powershell -Command "Split-Path (Split-Path (gcm git).Source)"'))
59 endif
60
61 if executable('bunzip2')
62 let g:GetLatestVimScripts_bunzip2= "bunzip2"
63 elseif executable('7z')
64 let g:GetLatestVimScripts_bunzip2= "7z x"
65 elseif exists('git_path')
66 let g:GetLatestVimScripts_bunzip2= $'{git_path}\usr\bin\bunzip2'
67 else
68 call assert_report("Missing tool to decompress .bz2 files")
69 endif
70
71 if executable('gunzip')
72 let g:GetLatestVimScripts_gunzip= "gunzip"
73 elseif executable('7z')
74 let g:GetLatestVimScripts_gunzip="7z e"
75 elseif exists('git_path')
76 let g:GetLatestVimScripts_gunzip= $'{git_path}\usr\bin\gunzip'
77 else
78 call assert_report("Missing tool to decompress .gz files")
79 endif
80
81 if executable('unxz')
82 let g:GetLatestVimScripts_unxz= "unxz"
83 elseif executable('7z')
84 let g:GetLatestVimScripts_unxz="7z x"
85 elseif exists('git_path')
86 let g:GetLatestVimScripts_unxz= $'{git_path}\mingw64\bin\unxz'
87 else
88 call assert_report("Missing tool to decompress .xz files")
89 endif
90
91 endif
92
93endfunc
94
95" After each test remove the contents of the .vim dir and reset the script
96func TearDown()
97 call delete($"{$HOME}/{s:dotvim}", "rf")
98
99 " getscript.vim include guard
100 unlet! g:loaded_getscript g:loaded_getscriptPlugin
101 " remove all globals (shell dependents)
102 let script_globals = keys(g:)
103 call filter(script_globals, 'v:val =~ "GetLatestVimScripts_"')
104 if len(script_globals)
105 call map(script_globals, '"g:" . v:val')
106 exe "unlet " . script_globals->join()
107 endif
108endfunc
109
110" Ancillary functions
111
112func SetShell(shell)
113
114 " select different shells
115 if a:shell == "default"
116 set shell& shellcmdflag& shellxquote& shellpipe& shellredir&
117 elseif a:shell == "powershell" " help dos-powershell
118 " powershell desktop is windows only
119 if !has("win32")
120 throw 'Skipped: powershell desktop is missing'
121 endif
122 set shell=powershell shellcmdflag=-NoProfile\ -Command shellxquote=\"
123 set shellpipe=2>&1\ \|\ Out-File\ -Encoding\ default shellredir=2>&1\ \|\ Out-File\ -Encoding\ default
124 elseif a:shell == "pwsh" " help dos-powershell
125 " powershell core works crossplatform
126 if !executable("pwsh")
127 throw 'Skipped: powershell core is missing'
128 endif
129 set shell=pwsh shellcmdflag=-NoProfile\ -c shellpipe=>%s\ 2>&1 shellredir=>%s\ 2>&1
130 if has("win32")
131 set shellxquote=\"
132 else
133 set shellxquote=
134 endif
135 else
136 call assert_report("Trying to select and unknown shell")
137 endif
138
139 " reload script to force new shell options
140 runtime autoload/getscript.vim
141
142endfunc
143
144func SelectScript(package)
145
146 " add the corresponding file
147 exe $"split {s:scriptdir}/GetLatestVimScripts.dat"
148 let scripts =<< trim END
149 ScriptID SourceID Filename
150 --------------------------
151 END
152 call setline(1, scripts)
153 call append(line('$'), s:packages[a:package]['spec'])
154 w!
155 bwipe!
156
157endfunc
158
159func ValidateInstall(package)
160 " check the package is expected
161 call assert_true(s:packages->has_key(a:package), "This package is unexpected")
162
163 " check if installation work out
164 if s:packages[a:package]->has_key('package')
165 let check = filereadable($"{$HOME}/{s:dotvim}/".s:packages[a:package]['package'])
166 call assert_true(check, "The plugin was not downloaded")
167 endif
168
169 call assert_true(s:packages[a:package]->has_key('files'), "This package lacks validation files")
170 for file in s:packages[a:package]['files']
171 let check = filereadable($"{$HOME}/{s:dotvim}/".file)
172 call assert_true(check, "The plugin was not installed")
173 endfor
174endfunc
175
176" Tests
177"
178func Test_glvs_default_vmb()
179
180 " select different shells
181 call SetShell('default')
182
183 " add the corresponding script
184 call SelectScript('vmb')
185
186 " load the plugins specified
187 GLVS
188
189 call ValidateInstall('vmb')
190
191endfunc
192
193func Test_glvs_pwsh_vmb()
194
195 " select different shells
196 call SetShell('pwsh')
197
198 " add the corresponding script
199 call SelectScript('vmb')
200
201 " load the plugins specified
202 GLVS
203
204 call ValidateInstall('vmb')
205
206endfunc
207
208func Test_glvs_powershell_vmb()
209
210 " select different shells
211 call SetShell('powershell')
212
213 " add the corresponding script
214 call SelectScript('vmb')
215
216 " load the plugins specified
217 GLVS
218
219 call ValidateInstall('vmb')
220
221endfunc
222
223func Test_glvs_default_vim_bz2()
224
225 " select different shells
226 call SetShell('default')
227
228 " add the corresponding script
229 call SelectScript('vim.bz2')
230
231 " load the plugins specified
232 GLVS
233
234 call ValidateInstall('vim.bz2')
235
236endfunc
237
238func Test_glvs_powershell_vim_bz2()
239
240 " select different shells
241 call SetShell('powershell')
242
243 " add the corresponding script
244 call SelectScript('vim.bz2')
245
246 " load the plugins specified
247 GLVS
248
249 call ValidateInstall('vim.bz2')
250
251endfunc
252
253func Test_glvs_pwsh_vim_bz2()
254
255 " select different shells
256 call SetShell('pwsh')
257
258 " add the corresponding script
259 call SelectScript('vim.bz2')
260
261 " load the plugins specified
262 GLVS
263
264 call ValidateInstall('vim.bz2')
265
266endfunc
267
268func Test_glvs_default_vba_gz()
269
270 " select different shells
271 call SetShell('default')
272
273 " add the corresponding script
274 call SelectScript('vba.gz')
275
276 " load the plugins specified
277 GLVS
278
279 call ValidateInstall('vba.gz')
280
281endfunc
282
283func Test_glvs_powershell_vba_gz()
284
285 " select different shells
286 call SetShell('powershell')
287
288 " add the corresponding script
289 call SelectScript('vba.gz')
290
291 " load the plugins specified
292 GLVS
293
294 call ValidateInstall('vba.gz')
295
296endfunc
297
298func Test_glvs_pwsh_vba_gz()
299
300 " select different shells
301 call SetShell('pwsh')
302
303 " add the corresponding script
304 call SelectScript('vba.gz')
305
306 " load the plugins specified
307 GLVS
308
309 call ValidateInstall('vba.gz')
310
311endfunc
312
313func Test_glvs_default_tar_xz()
314
315 " select different shells
316 call SetShell('default')
317
318 " add the corresponding script
319 call SelectScript('tar.xz')
320
321 " load the plugins specified
322 GLVS
323
324 call ValidateInstall('tar.xz')
325
326endfunc
327
328func Test_glvs_powershell_tar_xz()
329
330 " select different shells
331 call SetShell('powershell')
332
333 " add the corresponding script
334 call SelectScript('tar.xz')
335
336 " load the plugins specified
337 GLVS
338
339 call ValidateInstall('tar.xz')
340
341endfunc
342
343func Test_glvs_pwsh_tar_xz()
344
345 " select different shells
346 call SetShell('pwsh')
347
348 " add the corresponding script
349 call SelectScript('tar.xz')
350
351 " load the plugins specified
352 GLVS
353
354 call ValidateInstall('tar.xz')
355
356endfunc