aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/061_undo_tree_spec.lua
diff options
context:
space:
mode:
authorLucas Hoffmann <l-m-h@web.de>2015-06-22 16:01:39 +0200
committerLucas Hoffmann <l-m-h@web.de>2015-06-22 17:05:10 +0200
commitc411fb6cda9a9688785117346e791461cd52a1b5 (patch)
tree742c66d06be5e2ed5dfb1d8d7c1cb873fd104d01 /test/functional/legacy/061_undo_tree_spec.lua
parent1c7372361ffcc540d8a84fb414f103ea612fbac2 (diff)
downloadrneovim-c411fb6cda9a9688785117346e791461cd52a1b5.tar.gz
rneovim-c411fb6cda9a9688785117346e791461cd52a1b5.tar.bz2
rneovim-c411fb6cda9a9688785117346e791461cd52a1b5.zip
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.
Diffstat (limited to 'test/functional/legacy/061_undo_tree_spec.lua')
-rw-r--r--test/functional/legacy/061_undo_tree_spec.lua143
1 files changed, 81 insertions, 62 deletions
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<esc>')
- feed('Ab<esc>')
- feed('Ac<esc>')
- 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<esc>')
+ feed('Ab<esc>')
+ feed('Ac<esc>')
+ 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<esc>')
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)