robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
5.3 KiB211 linesraw
1local t = require('test.testutil')
2local n = require('test.functional.testnvim')()
3
4local describe, it, before_each = t.describe, t.it, t.before_each
5local clear = n.clear
6local command = n.command
7local eq = t.eq
8local exec_lua = n.exec_lua
9local matches = t.matches
10local ok = t.ok
11local pcall_err = t.pcall_err
12
13local foo = {
14  active = true,
15  path = '/dev/null',
16  rev = '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
17  spec = {
18    name = 'foo',
19    src = 'https://foo.example/foo/foo',
20  },
21}
22local bar = {
23  active = false,
24  path = '/var/empty',
25  rev = '62cdb7020ff920e5aa642c3d4066950dd1f01f4d',
26  spec = {
27    name = 'bar',
28    src = 'https://foo.example/bar/bar',
29    version = vim.version.range('0.42.42rc1'),
30  },
31}
32
33local function assert_success(fn)
34  exec_lua(fn)
35  ok(exec_lua('return _G.success'), 'true', '_G.success')
36end
37
38local function assert_completion(pat, expected)
39  local completions = exec_lua(function()
40    return vim.fn.getcompletion(pat, 'cmdline')
41  end)
42  eq(expected, completions)
43end
44
45describe(':packupdate', function()
46  before_each(function()
47    clear()
48    exec_lua(function()
49      vim.pack.get = function(names, opts)
50        assert(opts.info == false)
51        return { foo, bar }
52      end
53    end)
54  end)
55
56  it('works', function()
57    assert_success(function()
58      vim.pack.update = function(names, opts)
59        success = names == nil and opts.force ~= true and opts._ex == true
60      end
61      vim.cmd.packupdate()
62
63      vim.pack.update = function(names, opts)
64        success = success
65          and names[1] == 'foo'
66          and names[2] == nil
67          and opts.force ~= true
68          and opts._ex == true
69      end
70      vim.cmd.packupdate { 'foo' }
71    end)
72  end)
73
74  it('handles !', function()
75    assert_success(function()
76      vim.pack.update = function(names, opts)
77        success = opts.force == true
78      end
79      vim.cmd.packupdate { bang = true }
80    end)
81  end)
82
83  it('handles args', function()
84    assert_success(function()
85      vim.pack.update = function(names, opts)
86        success = opts.offline == true
87      end
88      vim.cmd.packupdate { '++offline' }
89
90      vim.pack.update = function(names, opts)
91        success = success and opts.target == 'lockfile'
92      end
93      vim.cmd.packupdate { '++lockfile' }
94    end)
95  end)
96
97  it('shows E5807', function()
98    eq('Vim(packupdate):E5807: Plugin not installed: baz', pcall_err(command, 'packupdate baz'))
99  end)
100
101  it('shows E5808', function()
102    exec_lua(function()
103      vim.pack.get = function(names, opts)
104        return {}
105      end
106    end)
107    eq('Vim(packupdate):E5808: Nothing to update', pcall_err(command, 'packupdate'))
108  end)
109
110  it('has completion', function()
111    assert_completion('packupdate ', { 'bar', 'foo' })
112    assert_completion('packupdate b', { 'bar' })
113    assert_completion('packupdate ++', { '++lockfile', '++offline' })
114  end)
115
116  it('fails if runtime is missing/broken', function()
117    clear {
118      args_rm = { '-u' },
119      args = { '-u', 'NONE' },
120      env = { VIMRUNTIME = 'non-existent' },
121    }
122    matches(
123      [[.*module 'vim%.pack' not found:]],
124      vim.split(t.pcall_err(n.command, 'packupdate foo'), '\n')[1]
125    )
126  end)
127end)
128
129describe(':packdel', function()
130  before_each(function()
131    clear()
132    exec_lua(function()
133      vim.pack.get = function(names, opts)
134        assert(opts.info == false)
135        return { foo, bar }
136      end
137    end)
138  end)
139
140  it('works', function()
141    assert_success(function()
142      vim.pack.del = function(names, opts)
143        success = names[1] == 'bar' and names[2] == nil and opts.force ~= true and opts._ex == true
144      end
145      vim.cmd.packdel { 'bar' }
146    end)
147  end)
148
149  it('handles !', function()
150    assert_success(function()
151      vim.pack.del = function(names, opts)
152        success = opts.force == true
153      end
154      vim.cmd.packdel { 'bar', bang = true }
155    end)
156  end)
157
158  it('handles ++all', function()
159    assert_success(function()
160      vim.pack.del = function(names, opts)
161        success = vim.list_contains(names, 'bar') and not vim.list_contains(names, 'foo')
162      end
163      vim.cmd.packdel { '++all' }
164
165      vim.pack.del = function(names, opts)
166        success = success and vim.list_contains(names, 'foo') and vim.list_contains(names, 'bar')
167      end
168      vim.cmd.packdel { '++all', bang = true }
169    end)
170  end)
171
172  it('shows E5807', function()
173    eq('Vim(packdel):E5807: Plugin not installed: baz', pcall_err(command, 'packdel baz'))
174  end)
175
176  it('shows E5809', function()
177    exec_lua(function()
178      vim.pack.get = function(names, opts)
179        return {}
180      end
181    end)
182    eq('Vim(packdel):E5809: Nothing to remove', pcall_err(command, 'packdel ++all'))
183  end)
184
185  it('shows E5811', function()
186    eq(
187      'Vim(packdel):E5811: Cannot specify plugin names when using ++all',
188      pcall_err(command, 'packdel bar ++all')
189    )
190  end)
191
192  it('has completion', function()
193    assert_completion('packdel ', { 'bar' })
194    assert_completion('packdel! ', { 'bar', 'foo' })
195    assert_completion('packdel! b', { 'bar' })
196    assert_completion('packdel ++', { '++all' })
197    assert_completion('packdel! ++', { '++all' })
198  end)
199
200  it('fails if runtime is missing/broken', function()
201    clear {
202      args_rm = { '-u' },
203      args = { '-u', 'NONE' },
204      env = { VIMRUNTIME = 'non-existent' },
205    }
206    matches(
207      [[.*module 'vim%.pack' not found:]],
208      vim.split(t.pcall_err(n.command, 'packdel foo'), '\n')[1]
209    )
210  end)
211end)