test/shada_spec: avoid exit_event race #10951

Doing clear() multiple times in quick succession provokes the
`exit_event` race described in #8813.

- Avoid it by removing unnecessary reset() call.
- Replace unnecessary nested describe() blocks with it() blocks.

ref d4a0b6c4e1
This commit is contained in:
Justin M. Keyes
2019-09-05 09:48:34 -07:00
committed by GitHub
parent 79ea47d478
commit 607d610d06

View File

@@ -12,9 +12,7 @@ local shada_helpers = require('test.functional.shada.helpers')
local get_shada_rw = shada_helpers.get_shada_rw local get_shada_rw = shada_helpers.get_shada_rw
local function reset(shada_file) local function reset(shada_file)
clear{ args={'-u', 'NORC', clear{ args={'-u', 'NORC', '-i', shada_file or 'NONE', }}
'-i', shada_file or 'NONE',
}}
end end
local mpack_eq = function(expected, mpack_result) local mpack_eq = function(expected, mpack_result)
@@ -2143,7 +2141,7 @@ describe('plugin/shada.vim', function()
local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)
local eol = helpers.iswin() and '\r\n' or '\n' local eol = helpers.iswin() and '\r\n' or '\n'
before_each(function() before_each(function()
reset() -- Note: reset() is called explicitly in each test.
os.remove(fname) os.remove(fname)
os.remove(fname .. '.tst') os.remove(fname .. '.tst')
os.remove(fname_tmp) os.remove(fname_tmp)
@@ -2159,8 +2157,8 @@ describe('plugin/shada.vim', function()
mpack_eq(expected, mpack_result) mpack_eq(expected, mpack_result)
end end
describe('event BufReadCmd', function() it('event BufReadCmd', function()
it('works', function() reset()
wshada('\004\000\009\147\000\196\002ab\196\001a') wshada('\004\000\009\147\000\196\002ab\196\001a')
wshada_tmp('\004\000\009\147\000\196\002ab\196\001b') wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
nvim_command('edit ' .. fname) nvim_command('edit ' .. fname)
@@ -2193,10 +2191,9 @@ describe('plugin/shada.vim', function()
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
neq(true, curbuf('get_option', 'modified')) neq(true, curbuf('get_option', 'modified'))
end) end)
end)
describe('event FileReadCmd', function() it('event FileReadCmd', function()
it('works', function() reset()
wshada('\004\000\009\147\000\196\002ab\196\001a') wshada('\004\000\009\147\000\196\002ab\196\001a')
wshada_tmp('\004\000\009\147\000\196\002ab\196\001b') wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
nvim_command('$read ' .. fname) nvim_command('$read ' .. fname)
@@ -2243,10 +2240,9 @@ describe('plugin/shada.vim', function()
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
neq(true, curbuf('get_option', 'modified')) neq(true, curbuf('get_option', 'modified'))
end) end)
end)
describe('event BufWriteCmd', function() it('event BufWriteCmd', function()
it('works', function() reset()
nvim('set_var', 'shada#add_own_header', 0) nvim('set_var', 'shada#add_own_header', 0)
curbuf('set_lines', 0, 1, true, { curbuf('set_lines', 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
@@ -2299,10 +2295,9 @@ describe('plugin/shada.vim', function()
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}}, fname_tmp) }}, fname_tmp)
end) end)
end)
describe('event FileWriteCmd', function() it('event FileWriteCmd', function()
it('works', function() reset()
nvim('set_var', 'shada#add_own_header', 0) nvim('set_var', 'shada#add_own_header', 0)
curbuf('set_lines', 0, 1, true, { curbuf('set_lines', 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
@@ -2338,10 +2333,9 @@ describe('plugin/shada.vim', function()
value={n=('A'):byte()}, value={n=('A'):byte()},
}}, fname_tmp) }}, fname_tmp)
end) end)
end)
describe('event FileAppendCmd', function() it('event FileAppendCmd', function()
it('works', function() reset()
nvim('set_var', 'shada#add_own_header', 0) nvim('set_var', 'shada#add_own_header', 0)
curbuf('set_lines', 0, 1, true, { curbuf('set_lines', 0, 1, true, {
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
@@ -2411,13 +2405,9 @@ describe('plugin/shada.vim', function()
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}}, fname_tmp) }}, fname_tmp)
end) end)
end)
describe('event SourceCmd', function() it('event SourceCmd', function()
before_each(function()
reset(fname) reset(fname)
end)
it('works', function()
wshada('\004\000\006\146\000\196\002ab') wshada('\004\000\006\146\000\196\002ab')
wshada_tmp('\004\001\006\146\000\196\002bc') wshada_tmp('\004\001\006\146\000\196\002bc')
eq(0, exc_exec('source ' .. fname)) eq(0, exc_exec('source ' .. fname))
@@ -2426,7 +2416,6 @@ describe('plugin/shada.vim', function()
eq('ab', funcs.histget(':', -2)) eq('ab', funcs.histget(':', -2))
end) end)
end) end)
end)
describe('ftplugin/shada.vim', function() describe('ftplugin/shada.vim', function()
local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0) local epoch = os.date('%Y-%m-%dT%H:%M:%S', 0)