From 8c999a9d6cbf892d66900ee626a3600ddc7d9849 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Fri, 15 May 2015 19:03:48 +0200 Subject: tests: Migrate legacy test 61. This test is real time based as it also tests the `:earlier` and `:later` commands with time arguments (using `:sleep`). This can sometimes case the test to fail on systems that are under heavy load or where the time interval between creating the expected buffer state and the `:earlier` or `:later` command that tries to jump to it changes. To be system independent we use nvim's `:sleep` command and `wait()` for it in the test suit. The legacy vim test writes to test.out a lot with `:.w >>test.out`. This does currently not work in the lua test suite so the test is modernized to use busted's assertions instead of the output file. This test was treated special in the legacy Makefile but after the conversion the related code can be removed. --- test/functional/legacy/061_undo_tree_spec.lua | 209 ++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 test/functional/legacy/061_undo_tree_spec.lua (limited to 'test/functional/legacy/061_undo_tree_spec.lua') diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua new file mode 100644 index 0000000000..e3f3997440 --- /dev/null +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -0,0 +1,209 @@ +-- Tests for undo tree. +-- Since this script is sourced we need to explicitly break changes up in +-- undo-able pieces. Do that by setting 'undolevels'. +-- Also tests :earlier and :later. + +local helpers = require('test.functional.helpers') +local feed, insert, source, eq, eval, clear, execute, expect, wait = + helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval, + helpers.clear, helpers.execute, helpers.expect, helpers.wait + +describe('the undo tree', function() + setup(clear) + teardown(function() + os.remove('Xtest') + end) + + it('is working', function() + -- Assert that no undo history is present. + eq({}, eval('undotree().entries')) + insert([[ + + 123456789]]) + + -- Clear the undo history after the insertion (see :h clear-undo) + execute('let old_undolevels = &undolevels') + execute('set undolevels=-1') + feed('a ') + execute('let &undolevels = old_undolevels') + execute('unlet old_undolevels') + eq({}, eval('undotree().entries')) + + -- Delete three characters and undo. + feed('Gx') + execute('set ul=100') + feed('x') + execute('set ul=100') + feed('x') + eq('456789', eval('getline(".")')) + feed('g-') + eq('3456789', eval('getline(".")')) + feed('g-') + eq('23456789', eval('getline(".")')) + feed('g-') + eq('123456789', eval('getline(".")')) + feed('g-') + eq('123456789', eval('getline(".")')) + + -- Delete three other characters and go back in time step by step. + feed('$x') + execute('set ul=100') + feed('x') + execute('set ul=100') + feed('x') + eq('123456', eval('getline(".")')) + execute('sleep 1') + wait() + feed('g-') + eq('1234567', eval('getline(".")')) + feed('g-') + eq('12345678', eval('getline(".")')) + feed('g-') + eq('456789', eval('getline(".")')) + feed('g-') + eq('3456789', eval('getline(".")')) + feed('g-') + eq('23456789', eval('getline(".")')) + feed('g-') + eq('123456789', eval('getline(".")')) + feed('g-') + eq('123456789', eval('getline(".")')) + feed('g-') + eq('123456789', eval('getline(".")')) + feed('10g+') + eq('123456', eval('getline(".")')) + + -- Delay for three seconds and go some seconds forward and backward. + execute('sleep 2') + wait() + feed('Aa') + execute('set ul=100') + feed('Ab') + execute('set ul=100') + feed('Ac') + execute('set ul=100') + eq('123456abc', eval('getline(".")')) + execute('ear 1s') + eq('123456', eval('getline(".")')) + execute('ear 3s') + eq('123456789', eval('getline(".")')) + execute('later 1s') + eq('123456', eval('getline(".")')) + execute('later 1h') + eq('123456abc', eval('getline(".")')) + + -- Test undojoin. + feed('Goaaaa') + execute('set ul=100') + feed('obbbbu') + eq('aaaa', eval('getline(".")')) + feed('obbbb') + execute('set ul=100') + execute('undojoin') + feed('occccu') + -- TODO At this point the original test will write "aaaa" to test.out. + -- Why is the line "bbbb" here? + eq('bbbb', eval('getline(".")')) + + execute('e! Xtest') + feed('ione one one') + execute('set ul=100') + execute('w!') + feed('otwo') + execute('set ul=100') + feed('otwo') + execute('set ul=100') + execute('w') + feed('othree') + execute('earlier 1f') + expect([[ + one one one + two + two]]) + execute('earlier 1f') + expect('one one one') + execute('earlier 1f') + -- Expect an empty line (the space is needed for helpers.dedent but + -- removed). + expect(' ') + execute('later 1f') + expect('one one one') + execute('later 1f') + expect([[ + one one one + two + two]]) + execute('later 1f') + expect([[ + one one one + two + two + three]]) + + execute('enew!') + feed('oa') + execute('set ul=100') + feed('ob') + execute('set ul=100') + feed([[o1a2=setline('.','1234')]]) + expect([[ + + a + b + 12034]]) + + feed('uu') + expect([[ + + a + b + 1]]) + feed('oc') + execute('set ul=100') + feed([[o1a2=setline('.','1234')]]) + expect([[ + + a + b + 1 + c + 12034]]) + feed('u') + expect([[ + + a + b + 1 + c + 12]]) + feed('od') + execute('set ul=100') + feed('o1a2=string(123)') + expect([[ + + a + b + 1 + c + 12 + d + 12123]]) + + -- TODO there is a difference between the original test and this test at + -- this point. The original tests expects the last line to go away after + -- the undo. I do not know why this should be the case as the "o" and "a" + -- above are seperate changes. I was able to confirm this manually with + -- vim and nvim. Both end up in this state (treat "o" and "a" as two + -- edits). + feed('u') + expect([[ + + a + b + 1 + c + 12 + d + 1]]) + end) +end) -- cgit From 981dd23f8df346086738c8606d102aa2cd346b13 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 18 Jun 2015 13:11:32 +0200 Subject: tests: Don't set ul in migrated test 61. The legacy test uses `set ul=100` to break the changes into blocks that can be undone separately. This is needed because the legacy test is sourced from a file and changes would be grouped into on undo block by default. The lua test suite does not have this restriction. Also add a new test case to test this effect of using `set ul=100` in a sourced script. --- test/functional/legacy/061_undo_tree_spec.lua | 75 ++++++++++++++++----------- 1 file changed, 46 insertions(+), 29 deletions(-) (limited to 'test/functional/legacy/061_undo_tree_spec.lua') diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index e3f3997440..c4fc5356ac 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -1,13 +1,16 @@ --- Tests for undo tree. --- Since this script is sourced we need to explicitly break changes up in --- undo-able pieces. Do that by setting 'undolevels'. --- Also tests :earlier and :later. +-- Tests for undo tree and :earlier and :later. local helpers = require('test.functional.helpers') local feed, insert, source, eq, eval, clear, execute, expect, wait = helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval, helpers.clear, helpers.execute, helpers.expect, helpers.wait +local expect_empty_buffer = function() + -- The space will be removed by helpers.dedent but is needed as dedent will + -- throw an error if it can not find the common indent of the given lines. + expect(' ') +end + describe('the undo tree', function() setup(clear) teardown(function() @@ -30,11 +33,7 @@ describe('the undo tree', function() eq({}, eval('undotree().entries')) -- Delete three characters and undo. - feed('Gx') - execute('set ul=100') - feed('x') - execute('set ul=100') - feed('x') + feed('Gxxx') eq('456789', eval('getline(".")')) feed('g-') eq('3456789', eval('getline(".")')) @@ -46,11 +45,7 @@ describe('the undo tree', function() eq('123456789', eval('getline(".")')) -- Delete three other characters and go back in time step by step. - feed('$x') - execute('set ul=100') - feed('x') - execute('set ul=100') - feed('x') + feed('$xxx') eq('123456', eval('getline(".")')) execute('sleep 1') wait() @@ -77,11 +72,8 @@ describe('the undo tree', function() execute('sleep 2') wait() feed('Aa') - execute('set ul=100') feed('Ab') - execute('set ul=100') feed('Ac') - execute('set ul=100') eq('123456abc', eval('getline(".")')) execute('ear 1s') eq('123456', eval('getline(".")')) @@ -92,13 +84,47 @@ describe('the undo tree', function() execute('later 1h') eq('123456abc', eval('getline(".")')) + -- Test that setting 'ul' breaks change blocks, we need to use source() in + -- order to test this, as interactive changes are not grouped. + execute('new') + -- First verify that scripts produce single big undo blocks. + source([[ + normal Aaaaa + normal obbbb + normal occcc + ]]) + expect([[ + aaaa + bbbb + cccc]]) + feed('u') + expect_empty_buffer() + -- Verify that undo blocks can be broken inside scripts by setting 'ul'. + source([[ + normal Aaaaa + set ul=100 + normal obbbb + set ul=100 + normal occcc + ]]) + expect([[ + aaaa + bbbb + cccc]]) + feed('u') + expect([[ + aaaa + bbbb]]) + feed('u') + expect('aaaa') + feed('u') + expect_empty_buffer() + -- Test undojoin. feed('Goaaaa') - execute('set ul=100') feed('obbbbu') eq('aaaa', eval('getline(".")')) feed('obbbb') - execute('set ul=100') execute('undojoin') feed('occccu') -- TODO At this point the original test will write "aaaa" to test.out. @@ -107,12 +133,9 @@ describe('the undo tree', function() execute('e! Xtest') feed('ione one one') - execute('set ul=100') execute('w!') feed('otwo') - execute('set ul=100') feed('otwo') - execute('set ul=100') execute('w') feed('othree') execute('earlier 1f') @@ -123,9 +146,7 @@ describe('the undo tree', function() execute('earlier 1f') expect('one one one') execute('earlier 1f') - -- Expect an empty line (the space is needed for helpers.dedent but - -- removed). - expect(' ') + expect_empty_buffer() execute('later 1f') expect('one one one') execute('later 1f') @@ -142,9 +163,7 @@ describe('the undo tree', function() execute('enew!') feed('oa') - execute('set ul=100') feed('ob') - execute('set ul=100') feed([[o1a2=setline('.','1234')]]) expect([[ @@ -159,7 +178,6 @@ describe('the undo tree', function() b 1]]) feed('oc') - execute('set ul=100') feed([[o1a2=setline('.','1234')]]) expect([[ @@ -177,7 +195,6 @@ describe('the undo tree', function() c 12]]) feed('od') - execute('set ul=100') feed('o1a2=string(123)') expect([[ -- cgit From 2ce3656754acc846177cd1bca66d5cf0d4fc571d Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Thu, 18 Jun 2015 18:01:19 +0200 Subject: tests: Fix an further simplify migrated test 61. :undojoin can only be used inside scripts and command chains. So it has to be tested inside an explicit `source()` call. Also add a new test case for the different behavior when sourceing normal mode commands from a script or inserting them interactively. --- test/functional/legacy/061_undo_tree_spec.lua | 131 +++++++++++++++----------- 1 file changed, 78 insertions(+), 53 deletions(-) (limited to 'test/functional/legacy/061_undo_tree_spec.lua') diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index c4fc5356ac..f098f54d7c 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -5,84 +5,89 @@ local feed, insert, source, eq, eval, clear, execute, expect, wait = helpers.feed, helpers.insert, helpers.source, helpers.eq, helpers.eval, helpers.clear, helpers.execute, helpers.expect, helpers.wait -local expect_empty_buffer = function() +local function expect_empty_buffer() -- The space will be removed by helpers.dedent but is needed as dedent will -- throw an error if it can not find the common indent of the given lines. - expect(' ') + return expect(' ') +end +local function expect_line(line) + return eq(line, eval('getline(".")')) +end +local function write_file(name, text) + local file = io.open(name, 'w') + file:write(text) + file:flush() + file:close() end + describe('the undo tree', function() - setup(clear) + setup(function() + clear() + write_file('Xtest.source', 'o1\x1ba2\x12=string(123)\n\x1b') + write_file('Xtest0', '\n123456789\n') + end) teardown(function() + os.remove('Xtest0') os.remove('Xtest') + os.remove('Xtest.source') end) it('is working', function() + execute('e Xtest0') -- Assert that no undo history is present. eq({}, eval('undotree().entries')) - insert([[ - - 123456789]]) - - -- Clear the undo history after the insertion (see :h clear-undo) - execute('let old_undolevels = &undolevels') - execute('set undolevels=-1') - feed('a ') - execute('let &undolevels = old_undolevels') - execute('unlet old_undolevels') - eq({}, eval('undotree().entries')) - -- Delete three characters and undo. feed('Gxxx') - eq('456789', eval('getline(".")')) + expect_line('456789') feed('g-') - eq('3456789', eval('getline(".")')) + expect_line('3456789') feed('g-') - eq('23456789', eval('getline(".")')) + expect_line('23456789') feed('g-') - eq('123456789', eval('getline(".")')) + expect_line('123456789') feed('g-') - eq('123456789', eval('getline(".")')) + expect_line('123456789') -- Delete three other characters and go back in time step by step. feed('$xxx') - eq('123456', eval('getline(".")')) + expect_line('123456') execute('sleep 1') wait() feed('g-') - eq('1234567', eval('getline(".")')) + expect_line('1234567') feed('g-') - eq('12345678', eval('getline(".")')) + expect_line('12345678') feed('g-') - eq('456789', eval('getline(".")')) + expect_line('456789') feed('g-') - eq('3456789', eval('getline(".")')) + expect_line('3456789') feed('g-') - eq('23456789', eval('getline(".")')) + expect_line('23456789') feed('g-') - eq('123456789', eval('getline(".")')) + expect_line('123456789') feed('g-') - eq('123456789', eval('getline(".")')) + expect_line('123456789') feed('g-') - eq('123456789', eval('getline(".")')) + expect_line('123456789') feed('10g+') - eq('123456', eval('getline(".")')) + expect_line('123456') - -- Delay for three seconds and go some seconds forward and backward. + -- Delay for two seconds and go some seconds forward and backward. execute('sleep 2') wait() feed('Aa') feed('Ab') feed('Ac') - eq('123456abc', eval('getline(".")')) - execute('ear 1s') - eq('123456', eval('getline(".")')) - execute('ear 3s') - eq('123456789', eval('getline(".")')) + expect_line('123456abc') + execute('earlier 1s') + expect_line('123456') + execute('earlier 3s') + expect_line('123456789') execute('later 1s') - eq('123456', eval('getline(".")')) + expect_line('123456') execute('later 1h') - eq('123456abc', eval('getline(".")')) + expect_line('123456abc') -- Test that setting 'ul' breaks change blocks, we need to use source() in -- order to test this, as interactive changes are not grouped. @@ -123,13 +128,15 @@ describe('the undo tree', function() -- Test undojoin. feed('Goaaaa') feed('obbbbu') - eq('aaaa', eval('getline(".")')) - feed('obbbb') - execute('undojoin') - feed('occccu') - -- TODO At this point the original test will write "aaaa" to test.out. - -- Why is the line "bbbb" here? - eq('bbbb', eval('getline(".")')) + expect_line('aaaa') + source([[ + normal obbbb + set ul=100 + undojoin + normal occcc + ]]) + feed('u') + expect_line('aaaa') execute('e! Xtest') feed('ione one one') @@ -195,7 +202,32 @@ describe('the undo tree', function() c 12]]) feed('od') - feed('o1a2=string(123)') + -- The file Xtest.source is written during setup. It contains this text + -- (nvim like escape sequences interpreted): + -- o1a2=string(123) + execute('so! Xtest.source') + expect([[ + + a + b + 1 + c + 12 + d + 12123]]) + feed('u') + expect([[ + + a + b + 1 + c + 12 + d]]) + -- The above behaviour was tested in the legacy vim test because the + -- legacy tests were executed with ':so!'. The behavior differs for + -- interactive use (even in vim, where the result was the same): + feed(io.open('Xtest.source'):read('*all')) expect([[ a @@ -205,13 +237,6 @@ describe('the undo tree', function() 12 d 12123]]) - - -- TODO there is a difference between the original test and this test at - -- this point. The original tests expects the last line to go away after - -- the undo. I do not know why this should be the case as the "o" and "a" - -- above are seperate changes. I was able to confirm this manually with - -- vim and nvim. Both end up in this state (treat "o" and "a" as two - -- edits). feed('u') expect([[ -- cgit From 1c7372361ffcc540d8a84fb414f103ea612fbac2 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 22 Jun 2015 11:15:50 +0200 Subject: tests: Split test 61 into several it() blocks. --- test/functional/legacy/061_undo_tree_spec.lua | 217 ++++++++++++++------------ 1 file changed, 113 insertions(+), 104 deletions(-) (limited to 'test/functional/legacy/061_undo_tree_spec.lua') diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index f098f54d7c..c5edf32cbf 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -20,79 +20,113 @@ local function write_file(name, text) file:close() end - -describe('the undo tree', function() - setup(function() - clear() - write_file('Xtest.source', 'o1\x1ba2\x12=string(123)\n\x1b') - write_file('Xtest0', '\n123456789\n') - end) +describe('undo:', function() + before_each(clear) teardown(function() - os.remove('Xtest0') - os.remove('Xtest') os.remove('Xtest.source') end) - it('is working', function() - execute('e Xtest0') - -- Assert that no undo history is present. - eq({}, eval('undotree().entries')) - -- Delete three characters and undo. - feed('Gxxx') - expect_line('456789') - feed('g-') - expect_line('3456789') - feed('g-') - expect_line('23456789') - feed('g-') - expect_line('123456789') - feed('g-') - expect_line('123456789') + describe(':earlier and :later', function() + before_each(function() + os.remove('Xtest') + end) + teardown(function() + os.remove('Xtest') + end) + + it('work with time specifications and g- and g+', function() + -- We write the test text to a file in order to prevent nvim to record + -- the inserting of the text into the undo history. + write_file('Xtest', '\n123456789\n') + execute('e Xtest') + -- Assert that no undo history is present. + eq({}, eval('undotree().entries')) + -- Delete three characters and undo. + feed('Gxxx') + expect_line('456789') + feed('g-') + expect_line('3456789') + feed('g-') + expect_line('23456789') + feed('g-') + expect_line('123456789') + feed('g-') + expect_line('123456789') + + -- Delete three other characters and go back in time step by step. + feed('$xxx') + expect_line('123456') + execute('sleep 1') + wait() + feed('g-') + expect_line('1234567') + feed('g-') + expect_line('12345678') + feed('g-') + expect_line('456789') + feed('g-') + expect_line('3456789') + feed('g-') + expect_line('23456789') + feed('g-') + expect_line('123456789') + feed('g-') + expect_line('123456789') + feed('g-') + expect_line('123456789') + feed('10g+') + expect_line('123456') - -- Delete three other characters and go back in time step by step. - feed('$xxx') - expect_line('123456') - execute('sleep 1') - wait() - feed('g-') - expect_line('1234567') - feed('g-') - expect_line('12345678') - feed('g-') - expect_line('456789') - feed('g-') - expect_line('3456789') - feed('g-') - expect_line('23456789') - feed('g-') - expect_line('123456789') - feed('g-') - expect_line('123456789') - feed('g-') - expect_line('123456789') - feed('10g+') - expect_line('123456') + -- Delay for two seconds and go some seconds forward and backward. + execute('sleep 2') + wait() + feed('Aa') + feed('Ab') + feed('Ac') + expect_line('123456abc') + execute('earlier 1s') + expect_line('123456') + execute('earlier 3s') + expect_line('123456789') + execute('later 1s') + expect_line('123456') + execute('later 1h') + expect_line('123456abc') + end) - -- Delay for two seconds and go some seconds forward and backward. - execute('sleep 2') - wait() - feed('Aa') - feed('Ab') - feed('Ac') - expect_line('123456abc') - execute('earlier 1s') - expect_line('123456') - execute('earlier 3s') - expect_line('123456789') - execute('later 1s') - expect_line('123456') - execute('later 1h') - expect_line('123456abc') + it('work with file write specifications', function() + feed('ione one one') + execute('w Xtest') + feed('otwo') + feed('otwo') + execute('w') + feed('othree') + execute('earlier 1f') + expect([[ + one one one + two + two]]) + execute('earlier 1f') + expect('one one one') + execute('earlier 1f') + expect_empty_buffer() + execute('later 1f') + expect('one one one') + execute('later 1f') + expect([[ + one one one + two + two]]) + execute('later 1f') + expect([[ + one one one + two + two + three]]) + end) + end) - -- Test that setting 'ul' breaks change blocks, we need to use source() in - -- order to test this, as interactive changes are not grouped. - execute('new') - -- First verify that scripts produce single big undo blocks. + it('scripts produce one undo block for all changes by default', function() source([[ normal Aaaaa normal obbbb @@ -104,7 +138,11 @@ describe('the undo tree', function() cccc]]) feed('u') expect_empty_buffer() - -- Verify that undo blocks can be broken inside scripts by setting 'ul'. + end) + + it('setting undolevel can break change blocks (inside scripts)', function() + -- We need to use source() in order to test this, as interactive changes + -- are not grouped. source([[ normal Aaaaa set ul=100 @@ -124,8 +162,9 @@ describe('the undo tree', function() expect('aaaa') feed('u') expect_empty_buffer() - - -- Test undojoin. + end) + + it(':undojoin can join change blocks inside scripts', function() feed('Goaaaa') feed('obbbbu') expect_line('aaaa') @@ -137,38 +176,12 @@ describe('the undo tree', function() ]]) feed('u') expect_line('aaaa') + end) - execute('e! Xtest') - feed('ione one one') - execute('w!') - feed('otwo') - feed('otwo') - execute('w') - feed('othree') - execute('earlier 1f') - expect([[ - one one one - two - two]]) - execute('earlier 1f') - expect('one one one') - execute('earlier 1f') - expect_empty_buffer() - execute('later 1f') - expect('one one one') - execute('later 1f') - expect([[ - one one one - two - two]]) - execute('later 1f') - expect([[ - one one one - two - two - three]]) + it('undoing pastes from the expression register is working', function() + local normal_commands = 'o1\x1ba2\x12=string(123)\n\x1b' + write_file('Xtest.source', normal_commands) - execute('enew!') feed('oa') feed('ob') feed([[o1a2=setline('.','1234')]]) @@ -177,7 +190,6 @@ describe('the undo tree', function() a b 12034]]) - feed('uu') expect([[ @@ -202,9 +214,6 @@ describe('the undo tree', function() c 12]]) feed('od') - -- The file Xtest.source is written during setup. It contains this text - -- (nvim like escape sequences interpreted): - -- o1a2=string(123) execute('so! Xtest.source') expect([[ @@ -227,7 +236,7 @@ describe('the undo tree', function() -- The above behaviour was tested in the legacy vim test because the -- legacy tests were executed with ':so!'. The behavior differs for -- interactive use (even in vim, where the result was the same): - feed(io.open('Xtest.source'):read('*all')) + feed(normal_commands) expect([[ a -- cgit From c411fb6cda9a9688785117346e791461cd52a1b5 Mon Sep 17 00:00:00 2001 From: Lucas Hoffmann Date: Mon, 22 Jun 2015 16:01:39 +0200 Subject: tests: Repeat a flaky part of the migrated test 61. This is the part of the test that relies on wall clock time and sometimes fails if the system is under load. The test is repeated up to three times before a failure is reported to the user. --- test/functional/legacy/061_undo_tree_spec.lua | 143 +++++++++++++++----------- 1 file changed, 81 insertions(+), 62 deletions(-) (limited to 'test/functional/legacy/061_undo_tree_spec.lua') diff --git a/test/functional/legacy/061_undo_tree_spec.lua b/test/functional/legacy/061_undo_tree_spec.lua index c5edf32cbf..651c928e17 100644 --- a/test/functional/legacy/061_undo_tree_spec.lua +++ b/test/functional/legacy/061_undo_tree_spec.lua @@ -38,60 +38,79 @@ describe('undo:', function() -- We write the test text to a file in order to prevent nvim to record -- the inserting of the text into the undo history. write_file('Xtest', '\n123456789\n') - execute('e Xtest') - -- Assert that no undo history is present. - eq({}, eval('undotree().entries')) - -- Delete three characters and undo. - feed('Gxxx') - expect_line('456789') - feed('g-') - expect_line('3456789') - feed('g-') - expect_line('23456789') - feed('g-') - expect_line('123456789') - feed('g-') - expect_line('123456789') - -- Delete three other characters and go back in time step by step. - feed('$xxx') - expect_line('123456') - execute('sleep 1') - wait() - feed('g-') - expect_line('1234567') - feed('g-') - expect_line('12345678') - feed('g-') - expect_line('456789') - feed('g-') - expect_line('3456789') - feed('g-') - expect_line('23456789') - feed('g-') - expect_line('123456789') - feed('g-') - expect_line('123456789') - feed('g-') - expect_line('123456789') - feed('10g+') - expect_line('123456') - -- Delay for two seconds and go some seconds forward and backward. - execute('sleep 2') - wait() - feed('Aa') - feed('Ab') - feed('Ac') - expect_line('123456abc') - execute('earlier 1s') - expect_line('123456') - execute('earlier 3s') - expect_line('123456789') - execute('later 1s') - expect_line('123456') - execute('later 1h') - expect_line('123456abc') + -- `:earlier` and `:later` are (obviously) time-sensitive, so this test + -- sometimes fails if the system is under load. It is wrapped in a local + -- function to allow multiple attempts. + local function test_earlier_later() + clear() + execute('e Xtest') + -- Assert that no undo history is present. + eq({}, eval('undotree().entries')) + -- Delete three characters and undo. + feed('Gxxx') + expect_line('456789') + feed('g-') + expect_line('3456789') + feed('g-') + expect_line('23456789') + feed('g-') + expect_line('123456789') + feed('g-') + expect_line('123456789') + + -- Delete three other characters and go back in time step by step. + feed('$xxx') + expect_line('123456') + execute('sleep 1') + wait() + feed('g-') + expect_line('1234567') + feed('g-') + expect_line('12345678') + feed('g-') + expect_line('456789') + feed('g-') + expect_line('3456789') + feed('g-') + expect_line('23456789') + feed('g-') + expect_line('123456789') + feed('g-') + expect_line('123456789') + feed('g-') + expect_line('123456789') + feed('10g+') + expect_line('123456') + + -- Delay for two seconds and go some seconds forward and backward. + execute('sleep 2') + wait() + feed('Aa') + feed('Ab') + feed('Ac') + expect_line('123456abc') + execute('earlier 1s') + expect_line('123456') + execute('earlier 3s') + expect_line('123456789') + execute('later 1s') + expect_line('123456') + execute('later 1h') + expect_line('123456abc') + end + local success, result = false, '' + for i = 1, 2 do + success, result = pcall(test_earlier_later) + if success then + return + end + end + -- We did not return in the loop so there was an error or failure. + -- We now try to run the test again but will not catch further errors, + -- so the user will see them. + test_earlier_later() end) it('work with file write specifications', function() @@ -103,9 +122,9 @@ describe('undo:', function() feed('othree') execute('earlier 1f') expect([[ - one one one - two - two]]) + one one one + two + two]]) execute('earlier 1f') expect('one one one') execute('earlier 1f') @@ -114,15 +133,15 @@ describe('undo:', function() expect('one one one') execute('later 1f') expect([[ - one one one - two - two]]) + one one one + two + two]]) execute('later 1f') expect([[ - one one one - two - two - three]]) + one one one + two + two + three]]) end) end) -- cgit