|
2 | 2 | let |
3 | 3 | inherit (pkgs) lib; |
4 | 4 |
|
5 | | - # Count plugins of given type excluding 'build.extraFiles' |
6 | | - pluginCount = |
7 | | - pkg: files: type: |
8 | | - builtins.length (builtins.filter (p: p != files) pkg.packpathDirs.myNeovimPackages.${type}); |
| 5 | + # Assertion for a number of plugins of given type defined in nvimPackage.packpathDirs |
| 6 | + expectNPlugins = |
| 7 | + config: type: n: |
| 8 | + let |
| 9 | + # 'build.extraFiles' must not be combined, so exclude it from counting |
| 10 | + plugins = builtins.filter ( |
| 11 | + p: p != config.build.extraFiles |
| 12 | + ) config.build.nvimPackage.packpathDirs.myNeovimPackages.${type}; |
| 13 | + numPlugins = builtins.length plugins; |
| 14 | + in |
| 15 | + { |
| 16 | + assertion = numPlugins == n; |
| 17 | + message = "Expected ${toString n} '${type}' plugins defined in 'nvimPackage.packpathDirs', got ${toString numPlugins}: ${ |
| 18 | + lib.concatMapStringsSep ", " lib.getName plugins |
| 19 | + }."; |
| 20 | + }; |
| 21 | + # Assertion that exactly one start plugin is defined in nvimPackage.packpathDirs |
| 22 | + expectOneStartPlugin = config: expectNPlugins config "start" 1; |
9 | 23 |
|
10 | 24 | # Stub plugins |
11 | 25 | mkPlugin = |
|
111 | 125 | assert(vim.fn.getcompletion("${name}", "help")[1], "no help tags for '${name}'") |
112 | 126 | '') (map lib.getName extraPlugins); |
113 | 127 | assertions = [ |
114 | | - { |
115 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
116 | | - message = "More than one plugin is defined in packpathDirs, expected one plugin pack."; |
117 | | - } |
| 128 | + (expectOneStartPlugin config) |
118 | 129 | ]; |
119 | 130 | }; |
120 | 131 |
|
|
141 | 152 | end), "plugin '${name}' isn't found in runtime as a separate entry, expected not to be combined") |
142 | 153 | '') (map lib.getName extraPlugins); |
143 | 154 | assertions = [ |
144 | | - { |
145 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" >= 2; |
146 | | - message = "Only one plugin is defined in packpathDirs, expected at least two."; |
147 | | - } |
| 155 | + (expectNPlugins config "start" (builtins.length extraPlugins)) |
148 | 156 | ]; |
149 | 157 | }; |
150 | 158 |
|
|
175 | 183 | require("simple-plugin-3") |
176 | 184 | ''; |
177 | 185 | assertions = [ |
178 | | - { |
179 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
180 | | - message = "More than one plugin is defined in packpathDirs."; |
181 | | - } |
| 186 | + (expectOneStartPlugin config) |
182 | 187 | ]; |
183 | 188 | }; |
184 | 189 |
|
|
199 | 204 | ) |
200 | 205 | ''; |
201 | 206 | assertions = [ |
202 | | - { |
203 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
204 | | - message = "More than one plugin is defined in packpathDirs."; |
205 | | - } |
| 207 | + (expectOneStartPlugin config) |
206 | 208 | ]; |
207 | 209 | }; |
208 | 210 |
|
|
226 | 228 | vim.cmd.py3("import requests") |
227 | 229 | ''; |
228 | 230 | assertions = [ |
229 | | - { |
230 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
231 | | - message = "More than one plugin is defined in packpathDirs."; |
232 | | - } |
| 231 | + (expectOneStartPlugin config) |
233 | 232 | ]; |
234 | 233 | }; |
235 | 234 |
|
|
255 | 254 | require("nui.popup") |
256 | 255 | ''; |
257 | 256 | assertions = [ |
258 | | - { |
259 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
260 | | - message = "More than one plugin is defined in packpathDirs."; |
261 | | - } |
| 257 | + (expectOneStartPlugin config) |
262 | 258 | ]; |
263 | 259 | }; |
264 | 260 |
|
|
307 | 303 | assert(num_plugins == 1, "expected 1 copy of simplePlugin1, got " .. num_plugins) |
308 | 304 | ''; |
309 | 305 | assertions = [ |
310 | | - { |
311 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
312 | | - message = "More than one start plugin is defined in packpathDirs"; |
313 | | - } |
314 | | - { |
315 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "opt" == 2; |
316 | | - message = "Less than two opt plugins are defined in packpathDirs"; |
317 | | - } |
| 306 | + (expectOneStartPlugin config) |
| 307 | + # simplePlugin3 pluginWithDeps1 |
| 308 | + (expectNPlugins config "opt" 2) |
318 | 309 | ]; |
319 | 310 | }; |
320 | 311 |
|
|
344 | 335 | assert(vim.g.simple_plugin_3 == 1, "simplePlugin3's config isn't evaluated") |
345 | 336 | ''; |
346 | 337 | assertions = [ |
347 | | - { |
348 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
349 | | - message = "More than one start plugin is defined in packpathDirs"; |
350 | | - } |
| 338 | + (expectOneStartPlugin config) |
351 | 339 | ]; |
352 | 340 | }; |
353 | 341 |
|
|
388 | 376 | end |
389 | 377 | ''; |
390 | 378 | assertions = [ |
391 | | - { |
392 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 1; |
393 | | - message = "More than one start plugin is defined in packpathDirs"; |
394 | | - } |
| 379 | + (expectOneStartPlugin config) |
395 | 380 | ]; |
396 | 381 | }; |
397 | 382 |
|
|
445 | 430 | end |
446 | 431 | ''; |
447 | 432 | assertions = [ |
448 | | - { |
449 | | - # plugin-pack, simplePlugin1, pluginWithDeps2, simplePlugin3 |
450 | | - assertion = pluginCount config.build.nvimPackage config.build.extraFiles "start" == 4; |
451 | | - message = "Wrong number of plugins in packpathDirs"; |
452 | | - } |
| 433 | + # plugin-pack, simplePlugin1, pluginWithDeps2, simplePlugin3 |
| 434 | + (expectNPlugins config "start" 4) |
453 | 435 | ]; |
454 | 436 | }; |
455 | 437 |
|
|
0 commit comments