diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/core/job_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/ex_cmds/write_spec.lua | 41 | ||||
-rw-r--r-- | test/functional/legacy/assert_spec.lua | 15 | ||||
-rw-r--r-- | test/functional/legacy/quickfix_spec.lua | 117 | ||||
-rw-r--r-- | test/functional/terminal/api_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/terminal/ex_terminal_spec.lua | 48 |
6 files changed, 222 insertions, 19 deletions
diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index adbe17d4b5..5872ebe8ee 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -121,14 +121,14 @@ describe('jobs', function() eq({'notification', 'exit', {0, 0}}, next_msg()) end) - it('can preserve newlines', function() + it('preserves newlines', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, "a\\n\\nc\\n\\n\\n\\nb\\n\\n")') eq({'notification', 'stdout', {0, {'a', '', 'c', '', '', '', 'b', '', ''}}}, next_msg()) end) - it('can preserve NULs', function() + it('preserves NULs', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, ["\n123\n", "abc\\nxyz\n", ""])') eq({'notification', 'stdout', {0, {'\n123\n', 'abc\nxyz\n', ''}}}, @@ -137,7 +137,7 @@ describe('jobs', function() eq({'notification', 'exit', {0, 0}}, next_msg()) end) - it('can avoid sending final newline', function() + it('avoids sending final newline', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobsend(j, ["some data", "without\nfinal nl"])') eq({'notification', 'stdout', {0, {'some data', 'without\nfinal nl'}}}, @@ -146,7 +146,7 @@ describe('jobs', function() eq({'notification', 'exit', {0, 0}}, next_msg()) end) - it('can close the job streams with jobclose', function() + it('closes the job streams with jobclose', function() nvim('command', "let j = jobstart(['cat', '-'], g:job_opts)") nvim('command', 'call jobclose(j, "stdin")') eq({'notification', 'exit', {0, 0}}, next_msg()) diff --git a/test/functional/ex_cmds/write_spec.lua b/test/functional/ex_cmds/write_spec.lua index c1bc5d3140..4ac9f312ef 100644 --- a/test/functional/ex_cmds/write_spec.lua +++ b/test/functional/ex_cmds/write_spec.lua @@ -1,20 +1,26 @@ --- Specs for :write - local helpers = require('test.functional.helpers')(after_each) -local eq, eval, clear, write_file, execute, source = - helpers.eq, helpers.eval, helpers.clear, helpers.write_file, - helpers.execute, helpers.source +local eq, eval, clear, write_file, execute, source, insert = + helpers.eq, helpers.eval, helpers.clear, helpers.write_file, + helpers.execute, helpers.source, helpers.insert if helpers.pending_win32(pending) then return end describe(':write', function() - after_each(function() + local function cleanup() os.remove('test_bkc_file.txt') os.remove('test_bkc_link.txt') + os.remove('test_fifo') + end + before_each(function() + clear() + cleanup() + end) + after_each(function() + cleanup() end) it('&backupcopy=auto preserves symlinks', function() - clear('--cmd', 'set backupcopy=auto') + execute('set backupcopy=auto') write_file('test_bkc_file.txt', 'content0') execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") source([[ @@ -27,7 +33,7 @@ describe(':write', function() end) it('&backupcopy=no replaces symlink with new file', function() - clear('--cmd', 'set backupcopy=no') + execute('set backupcopy=no') write_file('test_bkc_file.txt', 'content0') execute("silent !ln -s test_bkc_file.txt test_bkc_link.txt") source([[ @@ -38,4 +44,23 @@ describe(':write', function() eq(eval("['content0']"), eval("readfile('test_bkc_file.txt')")) eq(eval("['content1']"), eval("readfile('test_bkc_link.txt')")) end) + + it("appends FIFO file", function() + if eval("executable('mkfifo')") == 0 then + pending('missing "mkfifo" command', function()end) + return + end + + local text = "some fifo text from write_spec" + assert(os.execute("mkfifo test_fifo")) + insert(text) + + -- Blocks until a consumer reads the FIFO. + execute("write >> test_fifo") + + -- Read the FIFO, this will unblock the :write above. + local fifo = assert(io.open("test_fifo")) + eq(text.."\n", fifo:read("*all")) + fifo:close() + end) end) diff --git a/test/functional/legacy/assert_spec.lua b/test/functional/legacy/assert_spec.lua index 42dd25023a..8a042be7f7 100644 --- a/test/functional/legacy/assert_spec.lua +++ b/test/functional/legacy/assert_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local nvim, call = helpers.meths, helpers.call local clear, eq = helpers.clear, helpers.eq local source, execute = helpers.source, helpers.execute +local exc_exec = helpers.exc_exec local function expected_errors(errors) eq(errors, nvim.get_vvar('errors')) @@ -62,6 +63,20 @@ describe('assert function:', function() call('assert_equal', 'true', 'false') expected_errors({"Expected 'true' but got 'false'"}) end) + + it('should change v:errors when expected is not equal to actual', function() + source([[ + function CheckAssert() + let s:v = {} + let s:x = {"a": s:v} + let s:v["b"] = s:x + let s:w = {"c": s:x, "d": ''} + call assert_equal(s:w, '') + endfunction + ]]) + eq('Vim(call):E724: unable to correctly dump variable with self-referencing container', + exc_exec('call CheckAssert()')) + end) end) -- assert_notequal({expected}, {actual}[, {msg}]) diff --git a/test/functional/legacy/quickfix_spec.lua b/test/functional/legacy/quickfix_spec.lua index df8f2625db..7657b8641b 100644 --- a/test/functional/legacy/quickfix_spec.lua +++ b/test/functional/legacy/quickfix_spec.lua @@ -277,6 +277,118 @@ describe('helpgrep', function() augroup! testgroup endfunction + + " This will test for problems in quickfix: + " A. incorrectly copying location lists which caused the location list to show + " a different name than the file that was actually being displayed. + " B. not reusing the window for which the location list window is opened but + " instead creating new windows. + " C. make sure that the location list window is not reused instead of the + " window it belongs to. + " + " Set up the test environment: + function! ReadTestProtocol(name) + let base = substitute(a:name, '\v^test://(.*)%(\.[^.]+)?', '\1', '') + let word = substitute(base, '\v(.*)\..*', '\1', '') + + setl modifiable + setl noreadonly + setl noswapfile + setl bufhidden=delete + %del _ + " For problem 2: + " 'buftype' has to be set to reproduce the constant opening of new windows + setl buftype=nofile + + call setline(1, word) + + setl nomodified + setl nomodifiable + setl readonly + exe 'doautocmd BufRead ' . substitute(a:name, '\v^test://(.*)', '\1', '') + endfunction + + function Test_locationlist() + enew + + augroup testgroup + au! + autocmd BufReadCmd test://* call ReadTestProtocol(expand("<amatch>")) + augroup END + + let words = [ "foo", "bar", "baz", "quux", "shmoo", "spam", "eggs" ] + + let qflist = [] + for word in words + call add(qflist, {'filename': 'test://' . word . '.txt', 'text': 'file ' . word . '.txt', }) + " NOTE: problem 1: + " intentionally not setting 'lnum' so that the quickfix entries are not + " valid + call setloclist(0, qflist, ' ') + endfor + + " Test A + lrewind + enew + lopen + lnext + lnext + lnext + lnext + vert split + wincmd L + lopen + wincmd p + lnext + let fileName = expand("%") + wincmd p + let locationListFileName = substitute(getline(line('.')), '\([^|]*\)|.*', '\1', '') + let fileName = substitute(fileName, '\\', '/', 'g') + let locationListFileName = substitute(locationListFileName, '\\', '/', 'g') + call assert_equal("test://bar.txt", fileName) + call assert_equal("test://bar.txt", locationListFileName) + + wincmd n | only + + " Test B: + lrewind + lopen + 2 + exe "normal \<CR>" + wincmd p + 3 + exe "normal \<CR>" + wincmd p + 4 + exe "normal \<CR>" + call assert_equal(2, winnr('$')) + wincmd n | only + + " Test C: + lrewind + lopen + " Let's move the location list window to the top to check whether it (the + " first window found) will be reused when we try to open new windows: + wincmd K + 2 + exe "normal \<CR>" + wincmd p + 3 + exe "normal \<CR>" + wincmd p + 4 + exe "normal \<CR>" + 1wincmd w + call assert_equal('quickfix', &buftype) + 2wincmd w + let bufferName = expand("%") + let bufferName = substitute(bufferName, '\\', '/', 'g') + call assert_equal('test://quux.txt', bufferName) + + wincmd n | only + + augroup! testgroup + endfunction ]]) end) @@ -339,4 +451,9 @@ describe('helpgrep', function() call('Test_locationlist_curwin_was_closed') expected_empty() end) + + it('checks locationlist protocol read', function() + call('Test_locationlist') + expected_empty() + end) end) diff --git a/test/functional/terminal/api_spec.lua b/test/functional/terminal/api_spec.lua index 58d6c75940..045bdb0749 100644 --- a/test/functional/terminal/api_spec.lua +++ b/test/functional/terminal/api_spec.lua @@ -22,7 +22,7 @@ describe('api', function() -- Start the socket from the child nvim. child_session.feed_data(":echo serverstart('"..socket_name.."')\n") - -- Wait for socket creation by abusing expect(). + -- Wait for socket creation. screen:expect([[ {1: } | {4:~ }| @@ -37,6 +37,16 @@ describe('api', function() local socket_session2 = helpers.connect(socket_name) child_session.feed_data("i[tui] insert-mode") + -- Wait for stdin to be processed. + screen:expect([[ + [tui] insert-mode{1: } | + {4:~ }| + {4:~ }| + {4:~ }| + {5:[No Name] [+] }| + {3:-- INSERT --} | + {3:-- TERMINAL --} | + ]]) ok(socket_session1:request("nvim_ui_attach", 42, 6, {rgb=true})) ok(socket_session2:request("nvim_ui_attach", 25, 30, {rgb=true})) diff --git a/test/functional/terminal/ex_terminal_spec.lua b/test/functional/terminal/ex_terminal_spec.lua index 09b4eaa8d5..4247be0417 100644 --- a/test/functional/terminal/ex_terminal_spec.lua +++ b/test/functional/terminal/ex_terminal_spec.lua @@ -13,6 +13,42 @@ describe(':terminal', function() clear() screen = Screen.new(50, 4) screen:attach({rgb=false}) + end) + + it("does not interrupt Press-ENTER prompt #2748", function() + -- Ensure that :messages shows Press-ENTER. + source([[ + echomsg "msg1" + echomsg "msg2" + ]]) + -- Invoke a command that emits frequent terminal activity. + execute([[terminal while true; do echo X; done]]) + helpers.feed([[<C-\><C-N>]]) + screen:expect([[ + X | + X | + ^X | + | + ]]) + helpers.sleep(10) -- Let some terminal activity happen. + execute("messages") + screen:expect([[ + X | + msg1 | + msg2 | + Press ENTER or type command to continue^ | + ]]) + end) + +end) + +describe(':terminal (with fake shell)', function() + local screen + + before_each(function() + clear() + screen = Screen.new(50, 4) + screen:attach({rgb=false}) -- shell-test.c is a fake shell that prints its arguments and exits. nvim('set_option', 'shell', nvim_dir..'/shell-test') nvim('set_option', 'shellcmdflag', 'EXE') @@ -20,12 +56,12 @@ describe(':terminal', function() -- Invokes `:terminal {cmd}` using a fake shell (shell-test.c) which prints -- the {cmd} and exits immediately . - local function terminal_run_fake_shell_cmd(cmd) + local function terminal_with_fake_shell(cmd) execute("terminal "..(cmd and cmd or "")) end it('with no argument, acts like termopen()', function() - terminal_run_fake_shell_cmd() + terminal_with_fake_shell() wait() screen:expect([[ ready $ | @@ -36,7 +72,7 @@ describe(':terminal', function() end) it('executes a given command through the shell', function() - terminal_run_fake_shell_cmd('echo hi') + terminal_with_fake_shell('echo hi') wait() screen:expect([[ ready $ echo hi | @@ -47,7 +83,7 @@ describe(':terminal', function() end) it('allows quotes and slashes', function() - terminal_run_fake_shell_cmd([[echo 'hello' \ "world"]]) + terminal_with_fake_shell([[echo 'hello' \ "world"]]) wait() screen:expect([[ ready $ echo 'hello' \ "world" | @@ -66,14 +102,14 @@ describe(':terminal', function() end) it('ignores writes if the backing stream closes', function() - terminal_run_fake_shell_cmd() + terminal_with_fake_shell() helpers.feed('iiXXXXXXX') wait() -- Race: Though the shell exited (and streams were closed by SIGCHLD -- handler), :terminal cleanup is pending on the main-loop. -- This write should be ignored (not crash, #5445). helpers.feed('iiYYYYYYY') - wait() + eq(2, eval("1+1")) -- Still alive? end) end) |