neovim/test/functional/legacy/023_edit_arguments_spec.lua
Thiago de Arruda 168a46fd31 test: Improve test environment setup and error handling/reporting
During test setup, we used to call a vimscript function(BeforeEachTest) that
attempted to restore Nvim to it's initial state as much as possible in order to
provide a clean environment for running new tests. This approach has proven to
be unreliable, as some tests leave state that can affect other tests, eventually
causing failures that are difficult to debug.

This commit changes the 'clear' function so it will restart Nvim every time it
is called, which is a slower, but more reliable solution that will simplify
spotting bugs in the future.

Some other improvements/fixes were also performed:

- Whenever an error is detected in a handler passed to "run()", the event loop
  will be stopped and the error will be propagated to the main thread.
- Errors and the "cleanup()" function will always send a quit command to the
  current Nvim instance. This should prevent memory starvation when running
  tests under valgrind(where each Nvim instance can consume a lot of memory).
- Fixed a wrong assertion in server_requests_spec.lua. Previously the failure
  was undetected in a notification handler.
- Fixed some tests to expect fully clean registers. The deleted cleanup function
  used to put an empty string in every register, but that resulted in a extra
  line being added.
2014-11-07 00:55:58 -03:00

53 lines
1.1 KiB
Lua

-- Tests for complicated + argument to :edit command
local helpers = require('test.functional.helpers')
local clear, feed, insert = helpers.clear, helpers.feed, helpers.insert
local execute, expect = helpers.execute, helpers.expect
describe(':edit', function()
setup(clear)
it('is working', function()
insert([[
The result should be in Xfile1: "fooPIPEbar", in Xfile2: "fooSLASHbar"
foo|bar
foo/bar]])
-- Prepare some test files
execute('$-1w! Xfile1')
execute('$w! Xfile2')
execute('w! Xfile0')
-- Open Xfile using '+' range
execute('edit +1 Xfile1')
execute('s/|/PIPE/')
execute('yank A')
execute('w! Xfile1')
-- Open Xfile2 using '|' range
execute('edit Xfile2|1')
execute("s/\\//SLASH/")
execute('yank A')
execute('w! Xfile2')
-- Clean first buffer and put @a
execute('bf')
execute('%d')
execute('0put a')
-- Remove empty line
execute('$d')
-- The buffer should now contain
expect([[
fooPIPEbar
fooSLASHbar]])
end)
teardown(function()
os.remove('Xfile0')
os.remove('Xfile1')
os.remove('Xfile2')
end)
end)