[INIT]
This commit is contained in:
41
tests/_headless_test.lua
Normal file
41
tests/_headless_test.lua
Normal file
@@ -0,0 +1,41 @@
|
||||
-- headless test for merged-repl-plugin
|
||||
local M = require('merged-repl-plugin')
|
||||
|
||||
local main = [[/home/dai/projects/reperl.nvim/test_main_repo]]
|
||||
local repl = [[/home/dai/projects/reperl.nvim/test_repl_repo]]
|
||||
local repl_file = repl .. '/repl.pl'
|
||||
local sync_out = [[/home/dai/projects/reperl.nvim/tests/sync_result.txt]]
|
||||
local repl_out = [[/home/dai/projects/reperl.nvim/tests/repl_output_captured.log]]
|
||||
|
||||
M.setup{ main_repo_path = main, repl_repo_path = repl, repl_file = repl_file, auto_start = false }
|
||||
|
||||
-- run sync_once and write result to file
|
||||
M.sync_once(function(err, res)
|
||||
local f = io.open(sync_out, 'w')
|
||||
f:write(tostring(err) .. '\n')
|
||||
if res then f:write(vim.inspect(res) .. '\n') end
|
||||
f:close()
|
||||
end)
|
||||
|
||||
-- run the repl using plugin runner
|
||||
M.run_repl()
|
||||
|
||||
-- wait for buffer to appear and capture its contents to repl_out
|
||||
local bufname = 'REPL Output: ' .. vim.fn.fnamemodify(repl, ':t')
|
||||
local ok = vim.wait(2000, function()
|
||||
local bufnr = vim.fn.bufnr(bufname)
|
||||
if bufnr <= 0 then return false end
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
return #lines > 0
|
||||
end, 50)
|
||||
|
||||
local bufnr = vim.fn.bufnr(bufname)
|
||||
if bufnr > 0 then
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
local f = io.open(repl_out, 'w')
|
||||
f:write(table.concat(lines, '\n'))
|
||||
f:close()
|
||||
end
|
||||
|
||||
-- exit
|
||||
vim.cmd('qa!')
|
||||
Reference in New Issue
Block a user