Skip to content

Commit

Permalink
test: reduce delays
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Oct 1, 2023
1 parent e2ca739 commit 88be2b4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 36 deletions.
41 changes: 27 additions & 14 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 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

0 comments on commit 88be2b4

Please sign in to comment.