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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,272 +2157,263 @@ 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)
eq({ eq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(false, curbuf('get_option', 'modified')) eq(false, curbuf('get_option', 'modified'))
eq('shada', curbuf('get_option', 'filetype')) eq('shada', curbuf('get_option', 'filetype'))
nvim_command('edit ' .. fname_tmp) nvim_command('edit ' .. fname_tmp)
eq({ eq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(false, curbuf('get_option', 'modified')) eq(false, curbuf('get_option', 'modified'))
eq('shada', curbuf('get_option', 'filetype')) eq('shada', curbuf('get_option', 'filetype'))
eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
neq({ neq({
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, 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)
eq({ eq({
'', '',
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(true, curbuf('get_option', 'modified')) eq(true, curbuf('get_option', 'modified'))
neq('shada', curbuf('get_option', 'filetype')) neq('shada', curbuf('get_option', 'filetype'))
nvim_command('1,$read ' .. fname_tmp) nvim_command('1,$read ' .. fname_tmp)
eq({ eq({
'', '',
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, nvim_eval('getline(1, "$")')) }, nvim_eval('getline(1, "$")'))
eq(true, curbuf('get_option', 'modified')) eq(true, curbuf('get_option', 'modified'))
neq('shada', curbuf('get_option', 'filetype')) neq('shada', curbuf('get_option', 'filetype'))
curbuf('set_option', 'modified', false) curbuf('set_option', 'modified', false)
eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
eq({ eq({
'', '',
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "a"', ' - "a"',
'History entry with timestamp ' .. epoch .. ':', 'History entry with timestamp ' .. epoch .. ':',
' @ Description_ Value', ' @ Description_ Value',
' - history type CMD', ' - history type CMD',
' - contents "ab"', ' - contents "ab"',
' - "b"', ' - "b"',
}, 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 .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
}) })
nvim_command('w ' .. fname .. '.tst') nvim_command('w ' .. fname .. '.tst')
nvim_command('w ' .. fname) nvim_command('w ' .. fname)
nvim_command('w ' .. fname_tmp) nvim_command('w ' .. fname_tmp)
eq('++opt not supported', exc_exec('w! ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('w! ++enc=latin1 ' .. fname))
eq(table.concat({ eq(table.concat({
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
}, eol) .. eol, read_file(fname .. '.tst')) }, eol) .. eol, read_file(fname .. '.tst'))
shada_eq({{ shada_eq({{
timestamp=0, timestamp=0,
type=8, type=8,
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}, { }, {
timestamp=0, timestamp=0,
type=8, type=8,
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}}, fname) }}, fname)
shada_eq({{ shada_eq({{
timestamp=0, timestamp=0,
type=8, type=8,
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}, { }, {
timestamp=0, timestamp=0,
type=8, type=8,
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 .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
}) })
nvim_command('1,3w ' .. fname .. '.tst') nvim_command('1,3w ' .. fname .. '.tst')
nvim_command('1,3w ' .. fname) nvim_command('1,3w ' .. fname)
nvim_command('1,3w ' .. fname_tmp) nvim_command('1,3w ' .. fname_tmp)
eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 ' .. fname)) eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 ' .. fname))
eq(table.concat({ eq(table.concat({
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
}, eol) .. eol, read_file(fname .. '.tst')) }, eol) .. eol, read_file(fname .. '.tst'))
shada_eq({{ shada_eq({{
timestamp=0, timestamp=0,
type=8, type=8,
value={n=('A'):byte()}, value={n=('A'):byte()},
}}, fname) }}, fname)
shada_eq({{ shada_eq({{
timestamp=0, timestamp=0,
type=8, type=8,
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 .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
}) })
funcs.writefile({''}, fname .. '.tst', 'b') funcs.writefile({''}, fname .. '.tst', 'b')
funcs.writefile({''}, fname, 'b') funcs.writefile({''}, fname, 'b')
funcs.writefile({''}, fname_tmp, 'b') funcs.writefile({''}, fname_tmp, 'b')
nvim_command('1,3w >> ' .. fname .. '.tst') nvim_command('1,3w >> ' .. fname .. '.tst')
nvim_command('1,3w >> ' .. fname) nvim_command('1,3w >> ' .. fname)
nvim_command('1,3w >> ' .. fname_tmp) nvim_command('1,3w >> ' .. fname_tmp)
nvim_command('w >> ' .. fname .. '.tst') nvim_command('w >> ' .. fname .. '.tst')
nvim_command('w >> ' .. fname) nvim_command('w >> ' .. fname)
nvim_command('w >> ' .. fname_tmp) nvim_command('w >> ' .. fname_tmp)
eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 >> ' .. fname)) eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 >> ' .. fname))
eq(table.concat({ eq(table.concat({
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
'Jump with timestamp ' .. epoch .. ':', 'Jump with timestamp ' .. epoch .. ':',
' % Key________ Description Value', ' % Key________ Description Value',
' + n name \'A\'', ' + n name \'A\'',
' + f file name ["foo"]', ' + f file name ["foo"]',
' + l line number 2', ' + l line number 2',
' + c column -200', ' + c column -200',
}, eol) .. eol, read_file(fname .. '.tst')) }, eol) .. eol, read_file(fname .. '.tst'))
shada_eq({{ shada_eq({{
timestamp=0, timestamp=0,
type=8, type=8,
value={n=('A'):byte()}, value={n=('A'):byte()},
}, { }, {
timestamp=0, timestamp=0,
type=8, type=8,
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}, { }, {
timestamp=0, timestamp=0,
type=8, type=8,
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}}, fname) }}, fname)
shada_eq({{ shada_eq({{
timestamp=0, timestamp=0,
type=8, type=8,
value={n=('A'):byte()}, value={n=('A'):byte()},
}, { }, {
timestamp=0, timestamp=0,
type=8, type=8,
value={c=-200, f={'foo'}, l=2, n=('A'):byte()}, value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
}, { }, {
timestamp=0, timestamp=0,
type=8, type=8,
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) wshada('\004\000\006\146\000\196\002ab')
end) wshada_tmp('\004\001\006\146\000\196\002bc')
it('works', function() eq(0, exc_exec('source ' .. fname))
wshada('\004\000\006\146\000\196\002ab') eq(0, exc_exec('source ' .. fname_tmp))
wshada_tmp('\004\001\006\146\000\196\002bc') eq('bc', funcs.histget(':', -1))
eq(0, exc_exec('source ' .. fname)) eq('ab', funcs.histget(':', -2))
eq(0, exc_exec('source ' .. fname_tmp))
eq('bc', funcs.histget(':', -1))
eq('ab', funcs.histget(':', -2))
end)
end) end)
end) end)