mirror of
https://github.com/neovim/neovim.git
synced 2026-07-31 12:49:11 +00:00
Problem: The magic globals `it`, `describe`, etc., are more trouble than they are worth. - Hooking into `after_each` requires `getfenv()` hacks. - They confuse luals/emmylua, because the top-level `.luarc.json` isn't merged with `test/.luarc.json` (apparently a luals limitation?) - They totally defeat discoverability because the user just has to "know" about the various magic symbols. So they harm DX, which means they serve no purpose at all. Solution: - Expose the test API from `testutil`, so tests can call `t.it()`, `t.describe()`, etc., in the conventional way. - Drop `getfenv()` hacks. - Drop the `setfenv()` injection in `load_chunk`. - Drop `test/_meta.lua`.
73 lines
2.0 KiB
Lua
73 lines
2.0 KiB
Lua
local t = require('test.testutil')
|
|
local describe, it, before_each, after_each, pending =
|
|
t.describe, t.it, t.before_each, t.after_each, t.pending
|
|
local pcall_err = t.pcall_err
|
|
local n = require('test.functional.testnvim')()
|
|
|
|
local clear, source = n.clear, n.source
|
|
local eq, eval, command = t.eq, n.eval, n.command
|
|
|
|
describe('Test for delete()', function()
|
|
before_each(clear)
|
|
after_each(function()
|
|
os.remove('Xfile')
|
|
end)
|
|
|
|
it('file delete', function()
|
|
command('split Xfile')
|
|
command("call setline(1, ['a', 'b'])")
|
|
command('wq')
|
|
eq(eval("['a', 'b']"), eval("readfile('Xfile')"))
|
|
eq(0, eval("delete('Xfile')"))
|
|
eq(-1, eval("delete('Xfile')"))
|
|
end)
|
|
|
|
it('directory delete', function()
|
|
command("call mkdir('Xdir1')")
|
|
eq(1, eval("isdirectory('Xdir1')"))
|
|
eq(0, eval("delete('Xdir1', 'd')"))
|
|
eq(0, eval("isdirectory('Xdir1')"))
|
|
eq(-1, eval("delete('Xdir1', 'd')"))
|
|
end)
|
|
|
|
it('symlink delete', function()
|
|
source([[
|
|
split Xfile
|
|
call setline(1, ['a', 'b'])
|
|
wq
|
|
if has('win32')
|
|
silent !mklink Xlink Xfile
|
|
else
|
|
silent !ln -s Xfile Xlink
|
|
endif
|
|
]])
|
|
if eval('v:shell_error') ~= 0 then
|
|
pending('Cannot create symlink')
|
|
end
|
|
-- Delete the link, not the file
|
|
eq(0, eval("delete('Xlink')"))
|
|
eq(-1, eval("delete('Xlink')"))
|
|
eq(0, eval("delete('Xfile')"))
|
|
end)
|
|
|
|
it('symlink directory delete', function()
|
|
command("call mkdir('Xdir1')")
|
|
if t.is_os('win') then
|
|
command('silent !mklink /j Xlink Xdir1')
|
|
else
|
|
command('silent !ln -s Xdir1 Xlink')
|
|
end
|
|
eq(1, eval("isdirectory('Xdir1')"))
|
|
eq(1, eval("isdirectory('Xlink')"))
|
|
-- Delete the link, not the directory
|
|
eq(0, eval("delete('Xlink')"))
|
|
eq(-1, eval("delete('Xlink')"))
|
|
eq(0, eval("delete('Xdir1', 'd')"))
|
|
end)
|
|
|
|
it('gives correct emsgs', function()
|
|
eq('Vim(call):E474: Invalid argument', pcall_err(command, "call delete('')"))
|
|
eq('Vim(call):E15: Invalid expression: "0"', pcall_err(command, "call delete('foo', 0)"))
|
|
end)
|
|
end)
|