Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testimp #890

Merged
merged 2 commits into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"lua",
"$VIMRUNTIME",
"${3rd}/busted/library",
"${3rd}/luassert/library",
"${3rd}/luv/library"
],
"checkThirdParty": false
Expand Down
30 changes: 18 additions & 12 deletions test/client/session.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
local uv = require('luv')
local uv = vim.loop
local MsgpackRpcStream = require('test.client.msgpack_rpc_stream')

--- @class Session
--- @class NvimSession
--- @field private _msgpack_rpc_stream MsgpackRpcStream
--- @field private _pending_messages string[]
--- @field private _prepare uv_prepare_t
--- @field private _timer uv_timer_t
--- @field private _prepare uv.uv_prepare_t
--- @field private _timer uv.uv_timer_t
--- @field private _is_running boolean
local Session = {}
Session.__index = Session
Expand Down Expand Up @@ -57,7 +57,17 @@ function Session.new(stream)
}, Session)
end

--- @param timeout integer
--- @return string
function Session:next_message(timeout)
if self._is_running then
error('Event loop already running')
end

if #self._pending_messages > 0 then
return table.remove(self._pending_messages, 1)
end

local function on_request(method, args, response)
table.insert(self._pending_messages, {'request', method, args, response})
uv.stop()
Expand All @@ -68,14 +78,6 @@ function Session:next_message(timeout)
uv.stop()
end

if self._is_running then
error('Event loop already running')
end

if #self._pending_messages > 0 then
return table.remove(self._pending_messages, 1)
end

self:_run(on_request, on_notification, timeout)
return table.remove(self._pending_messages, 1)
end
Expand All @@ -100,6 +102,10 @@ function Session:request(method, ...)
return true, result
end

---@param request_cb fun()?
---@param notification_cb fun()?
---@param setup_cb fun()?
---@param timeout integer?
function Session:run(request_cb, notification_cb, setup_cb, timeout)
local function on_request(method, args, response)
coroutine_exec(request_cb, method, args, function(status, result, flag)
Expand Down
45 changes: 29 additions & 16 deletions test/gitsigns_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ local edit = helpers.edit
local cleanup = helpers.cleanup
local test_file = helpers.test_file
local git = helpers.git
local gitm = helpers.gitm
local scratch = helpers.scratch
local newfile = helpers.newfile
local match_dag = helpers.match_dag
Expand All @@ -34,8 +35,8 @@ local eq = helpers.eq
helpers.env()

describe('gitsigns', function()
local screen
local config
local screen --- @type NvimScreen
local config --- @type table

before_each(function()
clear()
Expand Down Expand Up @@ -254,8 +255,11 @@ describe('gitsigns', function()
else
system("printf 'This\nis\na\nwindows\nfile\n' > "..newfile)
end
git{'add', newfile}
git{"commit", "-m", "commit on main"}

gitm {
{'add', newfile},
{"commit", "-m", "commit on main"}
}

edit(newfile)
feed('gg')
Expand Down Expand Up @@ -337,8 +341,10 @@ describe('gitsigns', function()
feed('oEDIT<esc>')
command('write')

git{'add', test_file}
git{"commit", "-m", "commit on main"}
gitm {
{'add', test_file},
{"commit", "-m", "commit on main"}
}

-- Don't setup gitsigns until the repo has two commits
setup_gitsigns(config)
Expand Down Expand Up @@ -552,21 +558,25 @@ describe('gitsigns', function()
check{ status = {head='master', added=0, changed=1, removed=0} }
command("write")
command("bdelete")
git{'add', test_file}
git{"commit", "-m", "commit on main"}
gitm{
{'add', test_file},
{"commit", "-m", "commit on main"},

-- Create a branch, remove last commit, edit file again
git{'checkout', '-B', 'abranch'}
git{'reset', '--hard', 'HEAD~1'}
-- Create a branch, remove last commit, edit file again
{'checkout', '-B', 'abranch'},
{'reset', '--hard', 'HEAD~1'}
}
edit(test_file)
check{ status = {head='abranch', added=0, changed=0, removed=0} }
feed('idiff')
check{ status = {head='abranch', added=0, changed=1, removed=0} }
command("write")
command("bdelete")
git{'add', test_file}
git{"commit", "-m", "commit on branch"}
git{"rebase", "master"}
gitm{
{'add', test_file},
{"commit", "-m", "commit on branch"},
{"rebase", "master"}
}

-- test_file should have a conflict
edit(test_file)
Expand Down Expand Up @@ -678,8 +688,11 @@ describe('gitsigns', function()
local uni_filename = scratch..'/föobær'

write_to_file(uni_filename, {'Lorem ipsum'})
git{"add", uni_filename}
git{"commit", "-m", "another commit"}

gitm{
{"add", uni_filename},
{"commit", "-m", "another commit"}
}

edit(uni_filename)

Expand Down
58 changes: 36 additions & 22 deletions test/gs_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,50 @@ local test_file_text = {
'content', 'doesn\'t', 'matter,', 'it', 'just', 'needs', 'to', 'be', 'static.'
}

function M.git(args)
exec_lua("vim.loop.sleep(20)")
--- Run a git command
function M.gitf(args)
system{"git", "-C", M.scratch, unpack(args)}
exec_lua("vim.loop.sleep(20)")
end

--- @param cmds string[][]
function M.gitm(cmds)
for _, cmd in ipairs(cmds) do
M.gitf(cmd)
end
helpers.sleep(10)
end

--- Run a git command and add a delay
function M.git(args)
M.gitf(args)
helpers.sleep(10)
end

function M.cleanup()
system{"rm", "-rf", M.scratch}
end

function M.setup_git()
M.git{"init", '-b', 'master'}
M.gitf{"init", '-b', 'master'}

-- Always force color to test settings don't interfere with gitsigns systems
-- commands (addresses #23)
M.git{'config', 'color.branch' , 'always'}
M.git{'config', 'color.ui' , 'always'}
M.git{'config', 'color.diff' , 'always'}
M.git{'config', 'color.interactive', 'always'}
M.git{'config', 'color.status' , 'always'}
M.git{'config', 'color.grep' , 'always'}
M.git{'config', 'color.pager' , 'true'}
M.git{'config', 'color.decorate' , 'always'}
M.git{'config', 'color.showbranch' , 'always'}

M.git{'config', 'merge.conflictStyle', 'merge'}

M.git{'config', 'user.email', 'tester@com.com'}
M.git{'config', 'user.name' , 'tester'}

M.git{'config', 'init.defaultBranch', 'master'}
M.gitf{'config', 'color.branch' , 'always'}
M.gitf{'config', 'color.ui' , 'always'}
M.gitf{'config', 'color.diff' , 'always'}
M.gitf{'config', 'color.interactive', 'always'}
M.gitf{'config', 'color.status' , 'always'}
M.gitf{'config', 'color.grep' , 'always'}
M.gitf{'config', 'color.pager' , 'true'}
M.gitf{'config', 'color.decorate' , 'always'}
M.gitf{'config', 'color.showbranch' , 'always'}

M.gitf{'config', 'merge.conflictStyle', 'merge'}

M.gitf{'config', 'user.email', 'tester@com.com'}
M.gitf{'config', 'user.name' , 'tester'}

M.gitf{'config', 'init.defaultBranch', 'master'}
end

---@param opts? {test_file_text?: string[], no_add?: boolean}
Expand All @@ -84,9 +97,10 @@ function M.setup_test_repo(opts)
system{"touch", M.test_file}
M.write_to_file(M.test_file, text)
if not (opts and opts.no_add) then
M.git{"add", M.test_file}
M.git{"commit", "-m", "init commit"}
M.gitf{"add", M.test_file}
M.gitf{"commit", "-m", "init commit"}
end
helpers.sleep(20)
end

function M.expectf(cond, interval)
Expand Down
Loading
Loading