aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-09-05 09:48:34 -0700
committerGitHub <noreply@github.com>2019-09-05 09:48:34 -0700
commit607d610d06d6a8aedf7642bd43abf69feb534f17 (patch)
treee7d0ca818882994e39bd15b6d92cc5dd3fe2c325
parent79ea47d47836154cfb5a9574faa5c2af8422486a (diff)
downloadrneovim-607d610d06d6a8aedf7642bd43abf69feb534f17.tar.gz
rneovim-607d610d06d6a8aedf7642bd43abf69feb534f17.tar.bz2
rneovim-607d610d06d6a8aedf7642bd43abf69feb534f17.zip
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 d4a0b6c4e1d7
-rw-r--r--test/functional/plugin/shada_spec.lua509
1 files changed, 249 insertions, 260 deletions
diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua
index d96b479a62..5663f248bf 100644
--- a/test/functional/plugin/shada_spec.lua
+++ b/test/functional/plugin/shada_spec.lua
@@ -12,9 +12,7 @@ local shada_helpers = require('test.functional.shada.helpers')
local get_shada_rw = shada_helpers.get_shada_rw
local function reset(shada_file)
- clear{ args={'-u', 'NORC',
- '-i', shada_file or 'NONE',
- }}
+ clear{ args={'-u', 'NORC', '-i', shada_file or 'NONE', }}
end
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 eol = helpers.iswin() and '\r\n' or '\n'
before_each(function()
- reset()
+ -- Note: reset() is called explicitly in each test.
os.remove(fname)
os.remove(fname .. '.tst')
os.remove(fname_tmp)
@@ -2159,272 +2157,263 @@ describe('plugin/shada.vim', function()
mpack_eq(expected, mpack_result)
end
- describe('event BufReadCmd', function()
- it('works', function()
- wshada('\004\000\009\147\000\196\002ab\196\001a')
- wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
- nvim_command('edit ' .. fname)
- eq({
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "a"',
- }, nvim_eval('getline(1, "$")'))
- eq(false, curbuf('get_option', 'modified'))
- eq('shada', curbuf('get_option', 'filetype'))
- nvim_command('edit ' .. fname_tmp)
- eq({
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "b"',
- }, nvim_eval('getline(1, "$")'))
- eq(false, curbuf('get_option', 'modified'))
- eq('shada', curbuf('get_option', 'filetype'))
- eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
- neq({
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "a"',
- }, nvim_eval('getline(1, "$")'))
- neq(true, curbuf('get_option', 'modified'))
- end)
+ it('event BufReadCmd', function()
+ reset()
+ wshada('\004\000\009\147\000\196\002ab\196\001a')
+ wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
+ nvim_command('edit ' .. fname)
+ eq({
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "a"',
+ }, nvim_eval('getline(1, "$")'))
+ eq(false, curbuf('get_option', 'modified'))
+ eq('shada', curbuf('get_option', 'filetype'))
+ nvim_command('edit ' .. fname_tmp)
+ eq({
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "b"',
+ }, nvim_eval('getline(1, "$")'))
+ eq(false, curbuf('get_option', 'modified'))
+ eq('shada', curbuf('get_option', 'filetype'))
+ eq('++opt not supported', exc_exec('edit ++enc=latin1 ' .. fname))
+ neq({
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "a"',
+ }, nvim_eval('getline(1, "$")'))
+ neq(true, curbuf('get_option', 'modified'))
end)
- describe('event FileReadCmd', function()
- it('works', function()
- wshada('\004\000\009\147\000\196\002ab\196\001a')
- wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
- nvim_command('$read ' .. fname)
- eq({
- '',
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "a"',
- }, nvim_eval('getline(1, "$")'))
- eq(true, curbuf('get_option', 'modified'))
- neq('shada', curbuf('get_option', 'filetype'))
- nvim_command('1,$read ' .. fname_tmp)
- eq({
- '',
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "a"',
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "b"',
- }, nvim_eval('getline(1, "$")'))
- eq(true, curbuf('get_option', 'modified'))
- neq('shada', curbuf('get_option', 'filetype'))
- curbuf('set_option', 'modified', false)
- eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
- eq({
- '',
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "a"',
- 'History entry with timestamp ' .. epoch .. ':',
- ' @ Description_ Value',
- ' - history type CMD',
- ' - contents "ab"',
- ' - "b"',
- }, nvim_eval('getline(1, "$")'))
- neq(true, curbuf('get_option', 'modified'))
- end)
+ it('event FileReadCmd', function()
+ reset()
+ wshada('\004\000\009\147\000\196\002ab\196\001a')
+ wshada_tmp('\004\000\009\147\000\196\002ab\196\001b')
+ nvim_command('$read ' .. fname)
+ eq({
+ '',
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "a"',
+ }, nvim_eval('getline(1, "$")'))
+ eq(true, curbuf('get_option', 'modified'))
+ neq('shada', curbuf('get_option', 'filetype'))
+ nvim_command('1,$read ' .. fname_tmp)
+ eq({
+ '',
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "a"',
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "b"',
+ }, nvim_eval('getline(1, "$")'))
+ eq(true, curbuf('get_option', 'modified'))
+ neq('shada', curbuf('get_option', 'filetype'))
+ curbuf('set_option', 'modified', false)
+ eq('++opt not supported', exc_exec('$read ++enc=latin1 ' .. fname))
+ eq({
+ '',
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "a"',
+ 'History entry with timestamp ' .. epoch .. ':',
+ ' @ Description_ Value',
+ ' - history type CMD',
+ ' - contents "ab"',
+ ' - "b"',
+ }, nvim_eval('getline(1, "$")'))
+ neq(true, curbuf('get_option', 'modified'))
end)
- describe('event BufWriteCmd', function()
- it('works', function()
- nvim('set_var', 'shada#add_own_header', 0)
- curbuf('set_lines', 0, 1, true, {
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- })
- nvim_command('w ' .. fname .. '.tst')
- nvim_command('w ' .. fname)
- nvim_command('w ' .. fname_tmp)
- eq('++opt not supported', exc_exec('w! ++enc=latin1 ' .. fname))
- eq(table.concat({
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- }, eol) .. eol, read_file(fname .. '.tst'))
- shada_eq({{
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }, {
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }}, fname)
- shada_eq({{
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }, {
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }}, fname_tmp)
- end)
+ it('event BufWriteCmd', function()
+ reset()
+ nvim('set_var', 'shada#add_own_header', 0)
+ curbuf('set_lines', 0, 1, true, {
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ })
+ nvim_command('w ' .. fname .. '.tst')
+ nvim_command('w ' .. fname)
+ nvim_command('w ' .. fname_tmp)
+ eq('++opt not supported', exc_exec('w! ++enc=latin1 ' .. fname))
+ eq(table.concat({
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ }, eol) .. eol, read_file(fname .. '.tst'))
+ shada_eq({{
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }, {
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }}, fname)
+ shada_eq({{
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }, {
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }}, fname_tmp)
end)
- describe('event FileWriteCmd', function()
- it('works', function()
- nvim('set_var', 'shada#add_own_header', 0)
- curbuf('set_lines', 0, 1, true, {
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- })
- nvim_command('1,3w ' .. fname .. '.tst')
- nvim_command('1,3w ' .. fname)
- nvim_command('1,3w ' .. fname_tmp)
- eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 ' .. fname))
- eq(table.concat({
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- }, eol) .. eol, read_file(fname .. '.tst'))
- shada_eq({{
- timestamp=0,
- type=8,
- value={n=('A'):byte()},
- }}, fname)
- shada_eq({{
- timestamp=0,
- type=8,
- value={n=('A'):byte()},
- }}, fname_tmp)
- end)
+ it('event FileWriteCmd', function()
+ reset()
+ nvim('set_var', 'shada#add_own_header', 0)
+ curbuf('set_lines', 0, 1, true, {
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ })
+ nvim_command('1,3w ' .. fname .. '.tst')
+ nvim_command('1,3w ' .. fname)
+ nvim_command('1,3w ' .. fname_tmp)
+ eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 ' .. fname))
+ eq(table.concat({
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ }, eol) .. eol, read_file(fname .. '.tst'))
+ shada_eq({{
+ timestamp=0,
+ type=8,
+ value={n=('A'):byte()},
+ }}, fname)
+ shada_eq({{
+ timestamp=0,
+ type=8,
+ value={n=('A'):byte()},
+ }}, fname_tmp)
end)
- describe('event FileAppendCmd', function()
- it('works', function()
- nvim('set_var', 'shada#add_own_header', 0)
- curbuf('set_lines', 0, 1, true, {
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- })
- funcs.writefile({''}, fname .. '.tst', 'b')
- funcs.writefile({''}, fname, 'b')
- funcs.writefile({''}, fname_tmp, 'b')
- nvim_command('1,3w >> ' .. fname .. '.tst')
- nvim_command('1,3w >> ' .. fname)
- nvim_command('1,3w >> ' .. fname_tmp)
- nvim_command('w >> ' .. fname .. '.tst')
- nvim_command('w >> ' .. fname)
- nvim_command('w >> ' .. fname_tmp)
- eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 >> ' .. fname))
- eq(table.concat({
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- 'Jump with timestamp ' .. epoch .. ':',
- ' % Key________ Description Value',
- ' + n name \'A\'',
- ' + f file name ["foo"]',
- ' + l line number 2',
- ' + c column -200',
- }, eol) .. eol, read_file(fname .. '.tst'))
- shada_eq({{
- timestamp=0,
- type=8,
- value={n=('A'):byte()},
- }, {
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }, {
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }}, fname)
- shada_eq({{
- timestamp=0,
- type=8,
- value={n=('A'):byte()},
- }, {
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }, {
- timestamp=0,
- type=8,
- value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
- }}, fname_tmp)
- end)
+ it('event FileAppendCmd', function()
+ reset()
+ nvim('set_var', 'shada#add_own_header', 0)
+ curbuf('set_lines', 0, 1, true, {
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ })
+ funcs.writefile({''}, fname .. '.tst', 'b')
+ funcs.writefile({''}, fname, 'b')
+ funcs.writefile({''}, fname_tmp, 'b')
+ nvim_command('1,3w >> ' .. fname .. '.tst')
+ nvim_command('1,3w >> ' .. fname)
+ nvim_command('1,3w >> ' .. fname_tmp)
+ nvim_command('w >> ' .. fname .. '.tst')
+ nvim_command('w >> ' .. fname)
+ nvim_command('w >> ' .. fname_tmp)
+ eq('++opt not supported', exc_exec('1,3w! ++enc=latin1 >> ' .. fname))
+ eq(table.concat({
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ 'Jump with timestamp ' .. epoch .. ':',
+ ' % Key________ Description Value',
+ ' + n name \'A\'',
+ ' + f file name ["foo"]',
+ ' + l line number 2',
+ ' + c column -200',
+ }, eol) .. eol, read_file(fname .. '.tst'))
+ shada_eq({{
+ timestamp=0,
+ type=8,
+ value={n=('A'):byte()},
+ }, {
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }, {
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }}, fname)
+ shada_eq({{
+ timestamp=0,
+ type=8,
+ value={n=('A'):byte()},
+ }, {
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }, {
+ timestamp=0,
+ type=8,
+ value={c=-200, f={'foo'}, l=2, n=('A'):byte()},
+ }}, fname_tmp)
end)
- describe('event SourceCmd', function()
- before_each(function()
- reset(fname)
- end)
- it('works', function()
- wshada('\004\000\006\146\000\196\002ab')
- wshada_tmp('\004\001\006\146\000\196\002bc')
- eq(0, exc_exec('source ' .. fname))
- eq(0, exc_exec('source ' .. fname_tmp))
- eq('bc', funcs.histget(':', -1))
- eq('ab', funcs.histget(':', -2))
- end)
+ it('event SourceCmd', function()
+ reset(fname)
+ wshada('\004\000\006\146\000\196\002ab')
+ wshada_tmp('\004\001\006\146\000\196\002bc')
+ eq(0, exc_exec('source ' .. fname))
+ eq(0, exc_exec('source ' .. fname_tmp))
+ eq('bc', funcs.histget(':', -1))
+ eq('ab', funcs.histget(':', -2))
end)
end)