1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# run tests by building `neovim.tests`
{ vimUtils, writeText, neovim, vimPlugins
, lib, neovimUtils, wrapNeovimUnstable
, neovim-unwrapped
, fetchFromGitLab
, runCommandLocal
, pkgs
}:
let
inherit (neovimUtils) makeNeovimConfig;
plugins = with vimPlugins; [
{
plugin = vim-obsession;
config = ''
map <Leader>$ <Cmd>Obsession<CR>
'';
}
];
packagesWithSingleLineConfigs = with vimPlugins; [
{
plugin = vim-obsession;
config = ''map <Leader>$ <Cmd>Obsession<CR>'';
}
{
plugin = trouble-nvim;
config = ''" placeholder config'';
}
];
nvimConfSingleLines = makeNeovimConfig {
plugins = packagesWithSingleLineConfigs;
customRC = ''
" just a comment
'';
};
nvimConfNix = makeNeovimConfig {
inherit plugins;
customRC = ''
" just a comment
'';
};
nvim-with-luasnip = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig {
plugins = [ {
plugin = vimPlugins.luasnip;
}
];
});
nvimAutoDisableWrap = makeNeovimConfig { };
wrapNeovim2 = suffix: config:
wrapNeovimUnstable neovim-unwrapped (config // {
extraName = suffix;
});
nmt = fetchFromGitLab {
owner = "rycee";
repo = "nmt";
rev = "d2cc8c1042b1c2511f68f40e2790a8c0e29eeb42";
sha256 = "1ykcvyx82nhdq167kbnpgwkgjib8ii7c92y3427v986n2s5lsskc";
};
# this plugin checks that it's ftplugin/vim.tex is loaded before $VIMRUNTIME/ftplugin/vim.tex
# $VIMRUNTIME/ftplugin/vim.tex sources $VIMRUNTIME/ftplugin/initex.vim which sets b:did_ftplugin
# we save b:did_ftplugin's value in a `plugin_was_loaded_too_late` file
texFtplugin = (pkgs.runCommandLocal "tex-ftplugin" {} ''
mkdir -p $out/ftplugin
echo 'call system("echo ". exists("b:did_ftplugin") . " > plugin_was_loaded_too_late")' >> $out/ftplugin/tex.vim
echo ':q!' >> $out/ftplugin/tex.vim
'') // { pname = "test-ftplugin"; };
# neovim-drv must be a wrapped neovim
runTest = neovim-drv: buildCommand:
runCommandLocal "test-${neovim-drv.name}" ({
nativeBuildInputs = [ ];
meta.platforms = neovim-drv.meta.platforms;
}) (''
source ${nmt}/bash-lib/assertions.sh
vimrc="${writeText "init.vim" neovim-drv.initRc}"
luarc="${writeText "init.lua" neovim-drv.luaRcContent}"
luarcGeneric="$out/patched.lua"
vimrcGeneric="$out/patched.vim"
mkdir $out
${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$vimrc" > "$vimrcGeneric"
${pkgs.perl}/bin/perl -pe "s|\Q$NIX_STORE\E/[a-z0-9]{32}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" < "$luarc" > "$luarcGeneric"
'' + buildCommand);
in
pkgs.recurseIntoAttrs (
rec {
vim_empty_config = vimUtils.vimrcFile { beforePlugins = ""; customRC = ""; };
### neovim tests
##################
nvim_with_plugins = wrapNeovim2 "-with-plugins" nvimConfNix;
singlelinesconfig = runTest (wrapNeovim2 "-single-lines" nvimConfSingleLines) ''
assertFileContains \
"$luarcGeneric" \
"vim.cmd.source \"/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-init.vim"
assertFileContent \
"$vimrcGeneric" \
"${./init-single-lines.vim}"
'';
nvim_via_override = neovim.override {
extraName = "-via-override";
configure = {
packages.foo.start = [ vimPlugins.ale ];
customRC = ''
:help ale
'';
};
};
nvim_with_aliases = neovim.override {
extraName = "-with-aliases";
vimAlias = true;
viAlias = true;
};
nvim_with_plug = neovim.override {
extraName = "-with-plug";
configure.packages.plugins = with pkgs.vimPlugins; {
start = [
(base16-vim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use"; }))
];
};
configure.customRC = ''
color base16-tomorrow-night
set background=dark
'';
};
run_nvim_with_plug = runTest nvim_with_plug ''
export HOME=$TMPDIR
${nvim_with_plug}/bin/nvim -i NONE -c 'color base16-tomorrow-night' +quit! -e
'';
nvim_with_ftplugin = neovim.override {
extraName = "-with-ftplugin";
configure.packages.plugins = {
start = [
texFtplugin
];
};
};
# regression test that ftplugin files from plugins are loaded before the ftplugin
# files from $VIMRUNTIME
run_nvim_with_ftplugin = runTest nvim_with_ftplugin ''
export HOME=$TMPDIR
echo '\documentclass{article}' > main.tex
${nvim_with_ftplugin}/bin/nvim main.tex -c "set ft?" -c quit
ls -l $TMPDIR
# if the file exists, then our plugin has been loaded instead of neovim's
[ ! -f plugin_was_loaded_too_late ]
'';
# check that the vim-doc hook correctly generates the tag
# we know for a fact packer has a doc folder
checkForTags = vimPlugins.packer-nvim.overrideAttrs(oldAttrs: {
doInstallCheck = true;
installCheckPhase = ''
[ -f $out/doc/tags ]
'';
});
# check that the vim-doc hook correctly generates the tag
# for neovim packages from luaPackages
# we know for a fact gitsigns-nvim has a doc folder and comes from luaPackages
checkForTagsLuaPackages = vimPlugins.gitsigns-nvim.overrideAttrs(oldAttrs: {
doInstallCheck = true;
installCheckPhase = ''
[ -f $out/doc/tags ]
'';
});
nvim_with_gitsigns_plugin = neovim.override {
extraName = "-with-gitsigns-plugin";
configure.packages.plugins = {
start = [
vimPlugins.gitsigns-nvim
];
};
};
checkHelpLuaPackages = runTest nvim_with_gitsigns_plugin ''
export HOME=$TMPDIR
${nvim_with_gitsigns_plugin}/bin/nvim -i NONE -c 'help gitsigns' +quitall! -e
'';
# nixpkgs should detect that no wrapping is necessary
nvimShouldntWrap = wrapNeovim2 "-should-not-wrap" nvimAutoDisableWrap;
# this will generate a neovimRc content but we disable wrapping
nvimDontWrap = wrapNeovim2 "-forced-nowrap" (makeNeovimConfig {
wrapRc = false;
customRC = ''
" this shouldn't trigger the creation of an init.vim
'';
});
force-nowrap = runTest nvimDontWrap ''
! grep -F -- ' -u' ${nvimDontWrap}/bin/nvim
'';
nvim_via_override-test = runTest nvim_via_override ''
assertFileContent \
"$vimrcGeneric" \
"${./init-override.vim}"
'';
checkAliases = runTest nvim_with_aliases ''
folder=${nvim_with_aliases}/bin
assertFileExists "$folder/vi"
assertFileExists "$folder/vim"
'';
# having no RC generated should autodisable init.vim wrapping
nvim_autowrap = runTest nvim_via_override ''
! grep ${nvimShouldntWrap}/bin/nvim
'';
# system remote plugin manifest should be generated, deoplete should be usable
# without the user having to do `UpdateRemotePlugins`. To test, launch neovim
# and do `:call deoplete#enable()`. It will print an error if the remote
# plugin is not registered.
test_nvim_with_remote_plugin = neovim.override {
extraName = "-remote";
configure.packages.foo.start = with vimPlugins; [ deoplete-nvim ];
};
nvimWithLuaPackages = wrapNeovim2 "-with-lua-packages" (makeNeovimConfig {
extraLuaPackages = ps: [ps.mpack];
customRC = ''
lua require("mpack")
'';
});
nvim_with_lua_packages = runTest nvimWithLuaPackages ''
export HOME=$TMPDIR
${nvimWithLuaPackages}/bin/nvim -i NONE --noplugin -es
'';
# nixpkgs should install optional packages in the opt folder
nvim_with_opt_plugin = neovim.override {
extraName = "-with-opt-plugin";
configure.packages.opt-plugins = with pkgs.vimPlugins; {
opt = [
(dashboard-nvim.overrideAttrs(old: { pname = old.pname + "-unique-for-tests-please-dont-use-opt"; }))
];
};
configure.customRC = ''
" Load all autoloaded plugins
packloadall
" Try to run Dashboard, and throw if it succeeds
try
Dashboard
echo "Dashboard found, throwing error"
cquit 1
catch /^Vim\%((\a\+)\)\=:E492/
echo "Dashboard not found"
endtry
" Load Dashboard as an optional
packadd dashboard-nvim-unique-for-tests-please-dont-use-opt
" Try to run Dashboard again, and throw if it fails
let res = exists(':Dashboard')
if res == 0
echo "Dashboard not found, throwing error"
cquit 1
endif
cquit 0
'';
};
run_nvim_with_opt_plugin = runTest nvim_with_opt_plugin ''
export HOME=$TMPDIR
${nvim_with_opt_plugin}/bin/nvim -i NONE +quit! -e
'';
inherit nvim-with-luasnip;
# check that bringing in one plugin with lua deps makes those deps visible from wrapper
# for instance luasnip has a dependency on jsregexp
can_require_transitive_deps =
runTest nvim-with-luasnip ''
export HOME=$TMPDIR
cat ${nvim-with-luasnip}/bin/nvim
${nvim-with-luasnip}/bin/nvim -i NONE --cmd "lua require'jsregexp'" -e
'';
})
|