aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/functional/terminal/buffer_spec.lua38
-rw-r--r--test/helpers.lua14
2 files changed, 50 insertions, 2 deletions
diff --git a/test/functional/terminal/buffer_spec.lua b/test/functional/terminal/buffer_spec.lua
index 7dcca231ee..f25cfa2039 100644
--- a/test/functional/terminal/buffer_spec.lua
+++ b/test/functional/terminal/buffer_spec.lua
@@ -6,9 +6,11 @@ local poke_eventloop = helpers.poke_eventloop
local eval, feed_command, source = helpers.eval, helpers.feed_command, helpers.source
local eq, neq = helpers.eq, helpers.neq
local write_file = helpers.write_file
-local command= helpers.command
+local command = helpers.command
local exc_exec = helpers.exc_exec
local matches = helpers.matches
+local exec_lua = helpers.exec_lua
+local sleep = helpers.sleep
describe(':terminal buffer', function()
local screen
@@ -328,3 +330,37 @@ describe('No heap-buffer-overflow when', function()
assert_alive()
end)
end)
+
+describe('on_lines does not emit out-of-bounds line indexes when', function()
+ before_each(function()
+ clear()
+ exec_lua([[
+ function _G.register_callback(bufnr)
+ _G.cb_error = ''
+ vim.api.nvim_buf_attach(bufnr, false, {
+ on_lines = function(_, bufnr, _, firstline, _, _)
+ local status, msg = pcall(vim.api.nvim_buf_get_offset, bufnr, firstline)
+ if not status then
+ _G.cb_error = msg
+ end
+ end
+ })
+ end
+ ]])
+ end)
+
+ it('creating a terminal buffer #16394', function()
+ feed_command([[autocmd TermOpen * ++once call v:lua.register_callback(expand("<abuf>"))]])
+ feed_command('terminal')
+ sleep(500)
+ eq('', exec_lua([[return _G.cb_error]]))
+ end)
+
+ it('deleting a terminal buffer #16394', function()
+ feed_command('terminal')
+ sleep(500)
+ feed_command('lua _G.register_callback(0)')
+ feed_command('bdelete!')
+ eq('', exec_lua([[return _G.cb_error]]))
+ end)
+end)
diff --git a/test/helpers.lua b/test/helpers.lua
index 09b113c01d..87431e4342 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -741,9 +741,20 @@ function module.read_file_list(filename, start)
if not file then
return nil
end
+
+ -- There is no need to read more than the last 2MB of the log file, so seek
+ -- to that.
+ local file_size = file:seek("end")
+ local offset = file_size - 2000000
+ if offset < 0 then
+ offset = 0
+ end
+ file:seek("set", offset)
+
local lines = {}
local i = 1
- for line in file:lines() do
+ local line = file:read("*l")
+ while line ~= nil do
if i >= start then
table.insert(lines, line)
if #lines > maxlines then
@@ -751,6 +762,7 @@ function module.read_file_list(filename, start)
end
end
i = i + 1
+ line = file:read("*l")
end
file:close()
return lines