From 68bef0a57de3c376406a0391c9ccd4099f7a0328 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 31 Oct 2017 13:28:16 +0100 Subject: test: has("ttyin"), has("ttyout") --- test/functional/core/startup_spec.lua | 89 +++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/functional/core/startup_spec.lua (limited to 'test') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua new file mode 100644 index 0000000000..08b59db627 --- /dev/null +++ b/test/functional/core/startup_spec.lua @@ -0,0 +1,89 @@ +local helpers = require('test.functional.helpers')(after_each) +local Screen = require('test.functional.ui.screen') + +local clear = helpers.clear +local command = helpers.command +local eq = helpers.eq +local funcs = helpers.funcs +local nvim_prog = helpers.nvim_prog +local nvim_set = helpers.nvim_set +local read_file = helpers.read_file +local retry = helpers.retry + +describe('startup', function() + before_each(function() + clear() + end) + after_each(function() + os.remove('Xtest_startup_ttyout') + end) + + it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function() + -- system() puts a pipe at both ends. + local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless', + '--cmd', nvim_set, + '-c', [[echo has('ttyin') has('ttyout')]], + '+q' }) + eq('0 0', out) + end) + it('with --embed: has("ttyin")==0 has("ttyout")==0', function() + local screen = Screen.new(25, 3) + -- Remote UI connected by --embed. + screen:attach() + command([[echo has('ttyin') has('ttyout')]]) + screen:expect([[ + ^ | + ~ | + 0 0 | + ]]) + end) + it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() + local screen = Screen.new(25, 3) + screen:attach() + -- Running in :terminal + command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] + ..nvim_set..[[\" ]] + ..[[-c \"echo has('ttyin') has('ttyout')\""]] + ..[[, shellescape(v:progpath))]]) + screen:expect([[ + ^ | + 1 1 | + | + ]]) + end) + it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() + local screen = Screen.new(25, 5) + screen:attach() + -- Running in :terminal + command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] + ..nvim_set..[[\" ]] + ..[[-c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]] + ..[[-c q | cat -v"]] -- Output to a pipe. + ..[[, shellescape(v:progpath))]]) + retry(nil, 3000, function() + screen:sleep(1) + eq('1\n0\n', -- stdin is a TTY, stdout is a pipe + read_file('Xtest_startup_ttyout')) + end) + end) + it('input from pipe: has("ttyin")==0 has("ttyout")==1', function() + local screen = Screen.new(25, 5) + screen:attach() + if iswin() then + command([[set shellcmdflag=/s\ /c shellxquote=\"]]) + end + -- Running in :terminal + command([[exe printf("terminal echo foo | ]] -- Input from a pipe. + ..[[%s -u NONE -i NONE --cmd \"]] + ..nvim_set..[[\" ]] + ..[[-c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]] + ..[[-c q -- -"]] + ..[[, shellescape(v:progpath))]]) + retry(nil, 3000, function() + screen:sleep(1) + eq('0\n1\n', -- stdin is a pipe, stdout is a TTY + read_file('Xtest_startup_ttyout')) + end) + end) +end) + -- cgit From 54cac3033f2c6e27c677681e8ca6d21e3fd9fc0a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 2 Nov 2017 11:10:25 +0100 Subject: test: startup_spec: cmd.exe escaping --- test/functional/core/startup_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/functional/core/startup_spec.lua b/test/functional/core/startup_spec.lua index 08b59db627..ae7f949e52 100644 --- a/test/functional/core/startup_spec.lua +++ b/test/functional/core/startup_spec.lua @@ -9,6 +9,7 @@ local nvim_prog = helpers.nvim_prog local nvim_set = helpers.nvim_set local read_file = helpers.read_file local retry = helpers.retry +local iswin = helpers.iswin describe('startup', function() before_each(function() @@ -40,6 +41,9 @@ describe('startup', function() it('in a TTY: has("ttyin")==1 has("ttyout")==1', function() local screen = Screen.new(25, 3) screen:attach() + if iswin() then + command([[set shellcmdflag=/s\ /c shellxquote=\"]]) + end -- Running in :terminal command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] ..nvim_set..[[\" ]] @@ -54,6 +58,9 @@ describe('startup', function() it('output to pipe: has("ttyin")==1 has("ttyout")==0', function() local screen = Screen.new(25, 5) screen:attach() + if iswin() then + command([[set shellcmdflag=/s\ /c shellxquote=\"]]) + end -- Running in :terminal command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]] ..nvim_set..[[\" ]] -- cgit From c67dd5acd0bb9f8d08789dfe6af27d9045e95fb4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Nov 2017 23:54:31 +0100 Subject: NVIM v0.2.1 FEATURES: 0e873a30f307 Lua(Jit) built-in #4411 5b32bce73c93 Windows: `:terminal` #7007 7b0ceb3726e6 UI/API: externalize cmdline #7173 b67f58b2845a UI/API: externalize wildmenu #7454 b23aa1cf099e UI: 'winhighlight' #6597 17531ed0825c UI: command-line coloring (`:help input()-highlight`) #6364 244a1f97db6d API: execute lua directly from the remote api #6704 45626de63f2b API: `get_keymap()` #6236 db999821d45c API: `nvim_get_hl_by_name()`, `nvim_get_hl_by_id()` #7082 dc685387a3d6 menu_get() function #6322 9db42d4ce99c :cquit : take an error code argument #7336 9cc185dc6d9d job-control: serverstart(): support ipv6 #6680 1b7a9bf4d202 job-control: sockopen() #6594 6efe84af6813 clipboard: fallback to tmux clipboard #6894 6016ac270f54 clipboard: customize clipboard with `g:clipboard` #6030 3a86dd54f387 ruby: override ruby host via `g:ruby_host_prog` #6841 16cce1ac1745 debug: $NVIM_LOG_FILE #6827 0cba3da26e46 `:checkhealth` built-in, validates $VIMRUNTIME #7399 FIXES: 105d680aea9f TUI: more terminals, improve scroll/resize #6816 cb912a3edaad :terminal : handle F1-F12, other keys #7241 619838f85da2 inccommand: improve performance #6949 04b3c3277235 inccommand: Fix matches for zero-width #7487 60b1e8ad1237 inccommand: multiline, other fixes #7315 f1f7f3b5123e inccommand: Ignore leading modifiers in the command #6967 1551f7132152 inccommand: fix 'gdefault' lockup #7262 6338199b76e6 API: bufhl: support creating new groups #7414 541dde36e330 API: allow K_EVENT during operator-pending 8c732f727414 terminal: adjust for 'number' #7440 5bec94652c9d UI: preserve wildmenu during jobs/events #7110 c349083155cc UI: disable 'lazyredraw' during ui_refresh. #6259 51808a244eca send FocusGained/FocusLost event instead of pseudokey #7221 133f8bc628c2 shada: preserve unnamed register on restart #4700 1b70a1da0438 shada: avoid assertion on corrupt shada file #6958 9f534f338adf mksession: Restore tab-local working directory #6859 de1084f3c488 fix buf_write() crash #7140 7f7698649fc1 syntax: register 'Normal' highlight group #6973 6e7a8c3fe282 RPC: close channel if stream was closed #7081 85f3084e21e1 clipboard: disallow recursion; show hint only once #7203 8d1ccb606d38 clipboard: performance, avoid weird edge-cases #7193 01487d4385ae 'titleold' #7358 01e53a5cbe67 Windows: better path-handling, separator (slash) hygiene #7349 0f2873ce9943 Windows: multibyte startup arguments #7060 CHANGES: 9ff0cc70855f :terminal : start in normal-mode #6808 032b088c8485 lower priority of 'cursorcolumn', 'colorcolumn' #7364 2a3bcd1ff883 RPC: Don't delay notifications when request is pending #6544 023f67cad8d6 :terminal : Do not change 'number', 'relativenumber' #6796 1ef2d768e719 socket.c: Disable Nagle's algorithm on TCP sockets #6915 6720fe253e92 help: `K` tries Vim help instead of manpage #3104 70683705603e help, man.vim: change "outline" map to `gO` #7405 --- test/functional/fixtures/api_level_3.mpack | Bin 0 -> 19501 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/functional/fixtures/api_level_3.mpack (limited to 'test') diff --git a/test/functional/fixtures/api_level_3.mpack b/test/functional/fixtures/api_level_3.mpack new file mode 100644 index 0000000000..ef36b99c8c Binary files /dev/null and b/test/functional/fixtures/api_level_3.mpack differ -- cgit From 9837a9c40105d3d28fc99d62693e47b32cec0f06 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 9 Nov 2017 02:20:12 +0100 Subject: compat: "v:count" distinct from "count" (#7407) --- test/functional/eval/special_vars_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/functional/eval/special_vars_spec.lua b/test/functional/eval/special_vars_spec.lua index 3d9358447e..b5773a5529 100644 --- a/test/functional/eval/special_vars_spec.lua +++ b/test/functional/eval/special_vars_spec.lua @@ -168,4 +168,11 @@ describe('Special values', function() 'Expected True but got v:null', }, meths.get_vvar('errors')) end) + + describe('compat', function() + it('v:count is distinct from count', function() + command('let count = []') -- v:count is readonly + eq(1, eval('count is# g:["count"]')) + end) + end) end) -- cgit From f5d4da0144c97ba13f530ea7dbd50f7b9768cb34 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 10 Nov 2017 22:37:54 +0100 Subject: :checkhealth : validate 'runtimepath' (#7526) --- test/functional/plugin/health_spec.lua | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index b5374210e6..8ee0f258d0 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -16,6 +16,13 @@ describe(':checkhealth', function() eq(false, status) eq('Invalid $VIMRUNTIME: bogus', string.match(err, 'Invalid.*')) end) + it("detects invalid 'runtimepath'", function() + clear() + command('set runtimepath=bogus') + local status, err = pcall(command, 'checkhealth') + eq(false, status) + eq("Invalid 'runtimepath'", string.match(err, 'Invalid.*')) + end) it("detects invalid $VIM", function() clear() -- Do this after startup, otherwise it just breaks $VIMRUNTIME. -- cgit From cf75de710cfb817871cb614f2091a11f069db2b7 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 9 Nov 2017 23:19:25 -0500 Subject: tui_spec: Convert nil to "" before formatting it This fixes an apparent difference in behavior between Lua and LuaJIT. Lua fails to format nil: test/functional/terminal/tui_spec.lua:381: bad argument #2 to 'format' (string expected, got nil) --- test/functional/terminal/tui_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/functional/terminal/tui_spec.lua b/test/functional/terminal/tui_spec.lua index d36eb46e54..777ef65d9e 100644 --- a/test/functional/terminal/tui_spec.lua +++ b/test/functional/terminal/tui_spec.lua @@ -380,7 +380,7 @@ describe("tui 't_Co' (terminal colors)", function() -- TODO: Revisit this after jobstart/termopen accept `env` dict. screen = thelpers.screen_setup(0, string.format( [=[['sh', '-c', 'LANG=C TERM=%s %s %s -u NONE -i NONE --cmd "silent set noswapfile noshowcmd noruler"']]=], - term, + term or "", (colorterm ~= nil and "COLORTERM="..colorterm or ""), helpers.nvim_prog)) -- cgit From b63cde97f40b962f80ab929036d0eb8c1228b33f Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sun, 12 Nov 2017 14:22:35 -0500 Subject: tests: terminal: Assert for SIGWINCH handling before continuing Fixes test failures like test/functional/terminal/cursor_spec.lua @ 62: terminal cursor with number column is positioned correctly when focused ./test/functional/ui/screen.lua:302: Row 2 did not match. Expected: |{7: 1 }tty ready | |*{7: 2 }{1: } | |{7: 3 } | |{7: 4 } | |{7: 5 } | |{7: 6 } | |{3:-- TERMINAL --} | Actual: |{7: 1 }tty ready | |*{7: 2 }rows: 6, cols: 46 | |{7: 3 }{1: } | |{7: 4 } | |{7: 5 } | |{7: 6 } | |{3:-- TERMINAL --} | --- test/functional/terminal/cursor_spec.lua | 17 +++++++++++++---- test/functional/terminal/window_spec.lua | 15 ++++++++++++--- 2 files changed, 25 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/cursor_spec.lua b/test/functional/terminal/cursor_spec.lua index d49f1bfc23..d942723d02 100644 --- a/test/functional/terminal/cursor_spec.lua +++ b/test/functional/terminal/cursor_spec.lua @@ -50,8 +50,8 @@ describe('terminal cursor', function() it('is positioned correctly when unfocused', function() screen:expect([[ {7: 1 }tty ready | - {7: 2 }{2:^ } | - {7: 3 } | + {7: 2 }^rows: 6, cols: 46 | + {7: 3 }{2: } | {7: 4 } | {7: 5 } | {7: 6 } | @@ -60,12 +60,21 @@ describe('terminal cursor', function() end) it('is positioned correctly when focused', function() + screen:expect([[ + {7: 1 }tty ready | + {7: 2 }^rows: 6, cols: 46 | + {7: 3 }{2: } | + {7: 4 } | + {7: 5 } | + {7: 6 } | + :set number | + ]]) feed('i') helpers.wait() screen:expect([[ {7: 1 }tty ready | - {7: 2 }{1: } | - {7: 3 } | + {7: 2 }rows: 6, cols: 46 | + {7: 3 }{1: } | {7: 4 } | {7: 5 } | {7: 6 } | diff --git a/test/functional/terminal/window_spec.lua b/test/functional/terminal/window_spec.lua index 231618c5da..842a81872e 100644 --- a/test/functional/terminal/window_spec.lua +++ b/test/functional/terminal/window_spec.lua @@ -43,14 +43,23 @@ describe('terminal window', function() -- numberwidth=9 feed([[]]) feed([[:set numberwidth=9 numberi]]) + screen:expect([[ + {7: 1 }tty ready | + {7: 2 }rows: 6, cols: 48 | + {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO| + {7: 4 }WXYZrows: 6, cols: 41 | + {7: 5 }{1: } | + {7: 6 } | + {3:-- TERMINAL --} | + ]]) thelpers.feed_data({' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'}) screen:expect([[ {7: 1 }tty ready | {7: 2 }rows: 6, cols: 48 | {7: 3 }abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO| - {7: 4 }WXYZ abcdefghijklmnopqrstuvwxyzABCDEFGHIJ| - {7: 5 }KLMNOPQRSTUVWXYZrows: 6, cols: 41 | - {7: 6 }{1: } | + {7: 4 }WXYZrows: 6, cols: 41 | + {7: 5 } abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN| + {7: 6 }OPQRSTUVWXYZ{1: } | {3:-- TERMINAL --} | ]]) end) -- cgit From e6beb60da517b6d7d7461687bf91f87d097b9563 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 13 Nov 2017 02:06:32 +0100 Subject: :terminal : fix crash on resize (#7547) closes #7538 Fix wrong window references from #7440 Remove some eager resizing. Still mostly doesn't address #4997. --- test/functional/terminal/mouse_spec.lua | 28 +++---- test/functional/terminal/window_split_tab_spec.lua | 91 +++++++++++----------- 2 files changed, 58 insertions(+), 61 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/mouse_spec.lua b/test/functional/terminal/mouse_spec.lua index 29c62d7be7..5e5558ee0a 100644 --- a/test/functional/terminal/mouse_spec.lua +++ b/test/functional/terminal/mouse_spec.lua @@ -101,7 +101,7 @@ describe('terminal mouse', function() line28 |line28 | line29 |line29 | line30 |line30 | - rows: 5, cols: 25 |rows: 5, cols: 25 | + rows: 5, cols: 24 |rows: 5, cols: 24 | {2:^ } |{2: } | ========== ========== | :vsp | @@ -111,7 +111,7 @@ describe('terminal mouse', function() {7: 1 }^ |line28 | {4:~ }|line29 | {4:~ }|line30 | - {4:~ }|rows: 5, cols: 25 | + {4:~ }|rows: 5, cols: 24 | {4:~ }|{2: } | ========== ========== | :enew | set number | @@ -121,16 +121,16 @@ describe('terminal mouse', function() {7: 27 }line |line28 | {7: 28 }line |line29 | {7: 29 }line |line30 | - {7: 30 }line |rows: 5, cols: 25 | + {7: 30 }line |rows: 5, cols: 24 | {7: 31 }^ |{2: } | ========== ========== | | ]]) feed('li') screen:expect([[ - {7: 27 }line |line29 | - {7: 28 }line |line30 | - {7: 29 }line |rows: 5, cols: 25 | + {7: 27 }line |line28 | + {7: 28 }line |line29 | + {7: 29 }line |line30 | {7: 30 }line |rows: 5, cols: 24 | {7: 31 } |{1: } | ========== ========== | @@ -140,8 +140,8 @@ describe('terminal mouse', function() thelpers.enable_mouse() thelpers.feed_data('mouse enabled\n') screen:expect([[ - {7: 27 }line |line30 | - {7: 28 }line |rows: 5, cols: 25 | + {7: 27 }line |line29 | + {7: 28 }line |line30 | {7: 29 }line |rows: 5, cols: 24 | {7: 30 }line |mouse enabled | {7: 31 } |{1: } | @@ -153,8 +153,8 @@ describe('terminal mouse', function() it('wont lose focus if another window is scrolled', function() feed('<0,0><0,0>') screen:expect([[ - {7: 21 }line |line30 | - {7: 22 }line |rows: 5, cols: 25 | + {7: 21 }line |line29 | + {7: 22 }line |line30 | {7: 23 }line |rows: 5, cols: 24 | {7: 24 }line |mouse enabled | {7: 25 }line |{1: } | @@ -163,8 +163,8 @@ describe('terminal mouse', function() ]]) feed('<0,0>') screen:expect([[ - {7: 26 }line |line30 | - {7: 27 }line |rows: 5, cols: 25 | + {7: 26 }line |line29 | + {7: 27 }line |line30 | {7: 28 }line |rows: 5, cols: 24 | {7: 29 }line |mouse enabled | {7: 30 }line |{1: } | @@ -176,8 +176,8 @@ describe('terminal mouse', function() it('will lose focus if another window is clicked', function() feed('<5,1>') screen:expect([[ - {7: 27 }line |line30 | - {7: 28 }l^ine |rows: 5, cols: 25 | + {7: 27 }line |line29 | + {7: 28 }l^ine |line30 | {7: 29 }line |rows: 5, cols: 24 | {7: 30 }line |mouse enabled | {7: 31 } |{2: } | diff --git a/test/functional/terminal/window_split_tab_spec.lua b/test/functional/terminal/window_split_tab_spec.lua index c5199f620e..714c2476ce 100644 --- a/test/functional/terminal/window_split_tab_spec.lua +++ b/test/functional/terminal/window_split_tab_spec.lua @@ -3,6 +3,9 @@ local thelpers = require('test.functional.terminal.helpers') local clear = helpers.clear local feed, nvim = helpers.feed, helpers.nvim local feed_command = helpers.feed_command +local command = helpers.command +local eq = helpers.eq +local eval = helpers.eval describe('terminal', function() local screen @@ -22,72 +25,66 @@ describe('terminal', function() screen:detach() end) - it('resets its size when entering terminal window', function() + it('next to a closing window', function() + command('split') + command('terminal') + command('vsplit foo') + eq(3, eval("winnr('$')")) + feed('ZQ') -- Close split, should not crash. #7538 + eq(2, eval("1+1")) -- Still alive? + end) + + it('does not change size on WinEnter', function() if helpers.pending_win32(pending) then return end feed('') feed_command('2split') - screen:expect([[ - rows: 2, cols: 50 | - {2:^ } | - ========== | - rows: 2, cols: 50 | - {2: } | - {4:~ }| - {4:~ }| - {4:~ }| - ========== | - :2split | - ]]) - feed_command('wincmd p') screen:expect([[ tty ready | - rows: 2, cols: 50 | + ^rows: 5, cols: 50 | ========== | tty ready | - rows: 2, cols: 50 | rows: 5, cols: 50 | {2: } | - ^ | + | + | ========== | - :wincmd p | + :2split | ]]) feed_command('wincmd p') screen:expect([[ - rows: 2, cols: 50 | - {2:^ } | + tty ready | + rows: 5, cols: 50 | ========== | - rows: 2, cols: 50 | + tty ready | + ^rows: 5, cols: 50 | {2: } | - {4:~ }| - {4:~ }| - {4:~ }| + | + | ========== | :wincmd p | ]]) end) - describe('when the screen is resized', function() - it('will forward a resize request to the program', function() - feed([[:]]) -- Go to cmdline-mode, so cursor is at bottom. - screen:try_resize(screen._width - 3, screen._height - 2) - screen:expect([[ - tty ready | - rows: 7, cols: 47 | - {2: } | - | - | - | - | - :^ | - ]]) - screen:try_resize(screen._width - 6, screen._height - 3) - screen:expect([[ - tty ready | - rows: 7, cols: 47 | - rows: 4, cols: 41 | - {2: } | - :^ | - ]]) - end) + it('forwards resize request to the program', function() + feed([[:]]) -- Go to cmdline-mode, so cursor is at bottom. + screen:try_resize(screen._width - 3, screen._height - 2) + screen:expect([[ + tty ready | + rows: 7, cols: 47 | + {2: } | + | + | + | + | + :^ | + ]]) + screen:try_resize(screen._width - 6, screen._height - 3) + screen:expect([[ + tty ready | + rows: 7, cols: 47 | + rows: 4, cols: 41 | + {2: } | + :^ | + ]]) end) end) -- cgit From d5b7f28b44517a2e9ed07619d9fb828c043f179a Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Mon, 13 Nov 2017 02:28:07 +0100 Subject: test/unit/path_spec: expect correct buffer size (#7514) Fixed-size buffers and lfs.currentdir().. does not compute. The tests would fail if the current working directory was longer than expected. --- test/unit/path_spec.lua | 132 ++++++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 55 deletions(-) (limited to 'test') diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index befb204d0a..ed597eaed7 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -366,134 +366,156 @@ describe('path.c', function() end) describe('vim_FullName', function() - local function vim_FullName(filename, buf, len, force) - filename = to_cstr(filename) - return cimp.vim_FullName(filename, buf, len, force) + local function vim_FullName(filename, buflen, do_expand) + local buf = cstr(buflen, '') + local result = cimp.vim_FullName(to_cstr(filename), buf, buflen, do_expand) + return buf, result end - before_each(function() - -- Create empty string buffer which will contain the resulting path. - length = (string.len(lfs.currentdir())) + 33 - buffer = cstr(length, '') - end) + local function get_buf_len(s, t) + return math.max(string.len(s), string.len(t)) + 1 + end itp('fails if given filename is NULL', function() - local force_expansion = 1 - local result = cimp.vim_FullName(NULL, buffer, length, force_expansion) + local do_expand = 1 + local buflen = 10 + local buf = cstr(buflen, '') + local result = cimp.vim_FullName(NULL, buf, buflen, do_expand) eq(FAIL, result) end) itp('fails safely if given length is wrong #5737', function() - local force_expansion = 1 local filename = 'foo/bar/bazzzzzzz/buz/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/a' local too_short_len = 8 local buf = cstr(too_short_len, '') - local result = cimp.vim_FullName(filename, buf, too_short_len, force_expansion) + local do_expand = 1 + local result = cimp.vim_FullName(filename, buf, too_short_len, do_expand) local expected = string.sub(filename, 1, (too_short_len - 1)) - eq(expected, (ffi.string(buf))) + eq(expected, ffi.string(buf)) eq(FAIL, result) end) itp('uses the filename if the filename is a URL', function() - local force_expansion = 1 local filename = 'http://www.neovim.org' - local result = vim_FullName(filename, buffer, length, force_expansion) - eq(filename, (ffi.string(buffer))) + local buflen = string.len(filename) + 1 + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(filename, ffi.string(buf)) eq(OK, result) end) itp('fails and uses filename if given filename contains non-existing directory', function() - local force_expansion = 1 local filename = 'non_existing_dir/test.file' - local result = vim_FullName(filename, buffer, length, force_expansion) - eq(filename, (ffi.string(buffer))) + local buflen = string.len(filename) + 1 + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(filename, ffi.string(buf)) eq(FAIL, result) end) itp('concatenates filename if it does not contain a slash', function() - local force_expansion = 1 - local result = vim_FullName('test.file', buffer, length, force_expansion) local expected = lfs.currentdir() .. '/test.file' - eq(expected, (ffi.string(buffer))) + local filename = 'test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) itp('concatenates directory name if it does not contain a slash', function() - local force_expansion = 1 - local result = vim_FullName('..', buffer, length, force_expansion) local expected = lfs.currentdir() .. '/..' - eq(expected, (ffi.string(buffer))) + local filename = '..' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) - -- Is it possible for every developer to enter '..' directory while running - -- the unit tests? Which other directory would be better? itp('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function() - local force_expansion = 1 - local result = vim_FullName('../test.file', buffer, length, force_expansion) local old_dir = lfs.currentdir() lfs.chdir('..') local expected = lfs.currentdir() .. '/test.file' lfs.chdir(old_dir) - eq(expected, (ffi.string(buffer))) + local filename = '../test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) itp('just copies the path if it is already absolute and force=0', function() - local force_expansion = 0 local absolute_path = '/absolute/path' - local result = vim_FullName(absolute_path, buffer, length, force_expansion) - eq(absolute_path, (ffi.string(buffer))) + local buflen = string.len(absolute_path) + 1 + local do_expand = 0 + local buf, result = vim_FullName(absolute_path, buflen, do_expand) + eq(absolute_path, ffi.string(buf)) eq(OK, result) end) itp('fails and uses filename when the path is relative to HOME', function() eq(false, cimp.os_isdir('~')) -- sanity check: no literal "~" directory. - local force_expansion = 1 local absolute_path = '~/home.file' - local result = vim_FullName(absolute_path, buffer, length, force_expansion) - eq(absolute_path, (ffi.string(buffer))) + local buflen = string.len(absolute_path) + 1 + local do_expand = 1 + local buf, result = vim_FullName(absolute_path, buflen, do_expand) + eq(absolute_path, ffi.string(buf)) eq(FAIL, result) end) itp('works with some "normal" relative path with directories', function() - local force_expansion = 1 - local result = vim_FullName('unit-test-directory/test.file', buffer, length, force_expansion) + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local filename = 'unit-test-directory/test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) end) itp('does not modify the given filename', function() - local force_expansion = 1 + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' local filename = to_cstr('unit-test-directory/test.file') - -- Don't use the wrapper here but pass a cstring directly to the c - -- function. - local result = cimp.vim_FullName(filename, buffer, length, force_expansion) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) - eq('unit-test-directory/test.file', (ffi.string(filename))) + local buflen = string.len(expected) + 1 + local buf = cstr(buflen, '') + local do_expand = 1 + -- Don't use the wrapper but pass a cstring directly to the c function. + eq('unit-test-directory/test.file', ffi.string(filename)) + local result = cimp.vim_FullName(filename, buf, buflen, do_expand) + eq(expected, ffi.string(buf)) eq(OK, result) end) itp('works with directories that have one path component', function() - local force_expansion = 1 - local filename = to_cstr('/tmp') - local result = cimp.vim_FullName(filename, buffer, length, force_expansion) - eq('/tmp', ffi.string(buffer)) + local filename = '/tmp' + local expected = filename + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) + eq('/tmp', ffi.string(buf)) eq(OK, result) end) itp('expands "./" to the current directory #7117', function() - local force_expansion = 1 - local result = vim_FullName('./unit-test-directory/test.file', buffer, length, force_expansion) + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local filename = './unit-test-directory/test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) eq(OK, result) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) + eq(expected, ffi.string(buf)) end) itp('collapses "foo/../foo" to "foo" #7117', function() - local force_expansion = 1 - local result = vim_FullName('unit-test-directory/../unit-test-directory/test.file', buffer, length, force_expansion) + local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local filename = 'unit-test-directory/../unit-test-directory/test.file' + local buflen = get_buf_len(expected, filename) + local do_expand = 1 + local buf, result = vim_FullName(filename, buflen, do_expand) eq(OK, result) - eq(lfs.currentdir() .. '/unit-test-directory/test.file', (ffi.string(buffer))) + eq(expected, ffi.string(buf)) end) end) -- cgit From 30a21830d06f1e99431c2a632133577841b10c32 Mon Sep 17 00:00:00 2001 From: nateozem Date: Mon, 13 Nov 2017 16:43:52 -0800 Subject: doc: test/README.md: migrate wiki info (#7552) --- test/README.md | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 215 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/README.md b/test/README.md index 44558f0981..010a2c9c12 100644 --- a/test/README.md +++ b/test/README.md @@ -1,10 +1,224 @@ Tests ===== -Tests are run by `/cmake/RunTests.cmake` file, using busted. +Tests are run by `/cmake/RunTests.cmake` file, using `busted`. For some failures, `.nvimlog` (or `$NVIM_LOG_FILE`) may provide insight. +--- + +- [Running tests](#running-tests) +- [Unit tests](#unit-tests) +- [Lint](#lint) +- [Environment variables](#environment-variables) + +--- + +Running tests +------------- + +Neovim uses third-party tooling to execute tests. So be sure, from the +repository directory, to build the tools before testing: + + make cmake + +## Executing Tests + +To run all _non-legacy_ (unit + functional) tests: + + make test + +To run only _unit_ tests: + + make unittest + +To run only _functional_ tests: + + make functionaltest + +--- + +## Filter Tests + +### Filter by name + +Another filter method is by setting a pattern of test name to `TEST_FILTER`. + +``` lua +it('foo api',function() + ... +end) +it('bar api',function() + ... +end) +``` + +To run only test with filter name: + + TEST_TAG='foo.*api' make functionaltest + +### Filter by file + +To run a *specific* unit test: + + TEST_FILE=test/unit/foo.lua make unittest + +To run a *specific* functional test: + + TEST_FILE=test/functional/foo.lua make functionaltest + +To *repeat* a test many times: + + .deps/usr/bin/busted --filter 'foo' --repeat 1000 test/functional/ui/foo_spec.lua + +### Filter by tag + +Tests can be "tagged" by adding `#` before a token in the test description. + +``` lua +it('#foo bar baz', function() + ... +end) +it('#foo another test', function() + ... +end) +``` + +To run only the tagged tests: + + TEST_TAG=foo make functionaltest + +**NOTES**: +* Tags are mainly used for testing issues (ex: `#1234`), so use the following + method. +* `TEST_FILE` is not a pattern string like `TEST_TAG` or `TEST_FILTER`. The + given value to `TEST_FILE` must be a path to an existing file. +* Both `TEST_TAG` and `TEST_FILTER` filter tests by the strings from either + `it()` or `describe()` functions. + +--- + +### Legacy + +To run all legacy (Vim) integration tests: + + make oldtest + +To run a *single* legacy test, run `make` with `TEST_FILE=test_name.res`. E.g. +to run `test_syntax.vim`: + + TEST_FILE=test_syntax.res make oldtest + +- The `.res` extension (instead of `.vim`) is required. +- Specify only the test file name, not the full path. + +### Functional tests + +`$GDB` can be set to [run tests under +gdbserver](https://github.com/neovim/neovim/pull/1527). If `$VALGRIND` is also +set, it will add the `--vgdb=yes` option to valgrind instead of +starting gdbserver directly. + +Unit tests +---------- + +Tests are broadly divided into *unit tests* +([test/unit](https://github.com/neovim/neovim/tree/master/test/unit) directory) +and *functional tests* +([test/functional](https://github.com/neovim/neovim/tree/master/test/functional) +directory). Use any of the existing tests as a template to start writing new +tests. + +- _Unit_ testing is achieved by compiling the tests as a shared library which is + loaded and called by LuaJit [FFI](http://luajit.org/ext_ffi.html). +- _Functional_ tests are driven by RPC, so they do not require LuaJit (as + opposed to Lua). + +You can learn the [key concepts of Lua in 15 +minutes](http://learnxinyminutes.com/docs/lua/). + +## Guidelines for writing tests + +- Consider [BDD](http://en.wikipedia.org/wiki/Behavior-driven_development) + guidelines for organization and readability of tests. Describe what you're + testing (and the environment if applicable) and create specs that assert its + behavior. +- For testing static functions or functions that have side effects visible only + in module-global variables, create accessors for the modified variables. For + example, say you are testing a function in misc1.c that modifies a static + variable, create a file `test/c-helpers/misc1.c` and add a function that + retrieves the value after the function call. Files under `test/c-helpers` will + only be compiled when building the test shared library. +- Luajit needs to know about type and constant declarations used in function + prototypes. The + [helpers.lua](https://github.com/neovim/neovim/blob/master/test/unit/helpers.lua) + file automatically parses `types.h`, so types used in the tested functions + must be moved to it to avoid having to rewrite the declarations in the test + files (even though this is how it's currently done currently in the misc1/fs + modules, but contributors are encouraged to refactor the declarations). + - Macro constants must be rewritten as enums so they can be "visible" to the + tests automatically. +- Busted supports various "output providers". The + **[gtest](https://github.com/Olivine-Labs/busted/pull/394) output provider** + shows verbose details that can be useful to diagnose hung tests. Either modify + the Makefile or compile with `make + CMAKE_EXTRA_FLAGS=-DBUSTED_OUTPUT_TYPE=gtest` to enable it. +- **Use busted's `pending()` feature** to skip tests + ([example](https://github.com/neovim/neovim/commit/5c1dc0fbe7388528875aff9d7b5055ad718014de#diff-bf80b24c724b0004e8418102f68b0679R18)). + Do not silently skip the test with `if-else`. If a functional test depends on + some external factor (e.g. the existence of `md5sum` on `$PATH`), *and* you + can't mock or fake the dependency, then skip the test via `pending()` if the + external factor is missing. This ensures that the *total* test-count (success + + fail + error + pending) is the same in all environments. + - *Note:* `pending()` is ignored if it is missing an argument _unless_ it is + [contained in an `it()` + block](https://github.com/neovim/neovim/blob/d21690a66e7eb5ebef18046c7a79ef898966d786/test/functional/ex_cmds/grep_spec.lua#L11). + Provide empty function argument if the `pending()` call is outside of + `it()` + ([example](https://github.com/neovim/neovim/commit/5c1dc0fbe7388528875aff9d7b5055ad718014de#diff-bf80b24c724b0004e8418102f68b0679R18)). +- Use `make testlint` for using the shipped luacheck program ([supported by + syntastic](https://github.com/scrooloose/syntastic/blob/d6b96c079be137c83009827b543a83aa113cc011/doc/syntastic-checkers.txt#L3546)) + to lint all tests. + +### Where tests go + +- _Unit tests_ + ([test/unit](https://github.com/neovim/neovim/tree/master/test/unit)) should + match 1-to-1 with the structure of `src/nvim/`, because they are testing + functions directly. E.g. unit-tests for `src/nvim/undo.c` should live in + `test/unit/undo_spec.lua`. +- _Functional tests_ + ([test/functional](https://github.com/neovim/neovim/tree/master/test/functional)) + are higher-level (plugins and user input) than unit tests; they are organized + by concept. + - Try to find an existing `test/functional/*/*_spec.lua` group that makes + sense, before creating a new one. + +## Checklist for migrating legacy tests + +**Note:** Only "old style" (`src/testdir/*.in`) legacy tests should be +converted. Please _do not_ convert "new style" Vim tests (`src/testdir/*.vim`). +The "new style" Vim tests are faster than the old ones, and converting them +takes time and effort better spent elsewhere. + +- Remove the test from the Makefile (`src/nvim/testdir/Makefile`). +- Remove the associated `test.in`, `test.out`, and `test.ok` files from + `src/nvim/testdir/`. +- Make sure the lua test ends in `_spec.lua`. +- Make sure the test count increases accordingly in the build log. +- Make sure the new test contains the same control characters (`^]`, ...) as the + old test. + - Instead of the actual control characters, use an equivalent textual + representation (e.g. `` instead of `^]`). The + `scripts/legacy2luatest.pl` script does some of these conversions + automatically. + +## Tips + +- Really long `source([=[...]=])` blocks may break syntax highlighting. Try + `:syntax sync fromstart` to fix it. + + Lint ---- -- cgit From 67e45292925daf08d353581c1a9999eb0e2202dd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Nov 2017 20:55:25 +0100 Subject: defaults: scrollback=10000 (#7556) --- test/functional/terminal/scrollback_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/functional/terminal/scrollback_spec.lua b/test/functional/terminal/scrollback_spec.lua index af9b414311..c665e64a80 100644 --- a/test/functional/terminal/scrollback_spec.lua +++ b/test/functional/terminal/scrollback_spec.lua @@ -462,10 +462,10 @@ describe("'scrollback' option", function() screen:detach() end) - it('defaults to 1000 in terminal buffers', function() + it('defaults to 10000 in terminal buffers', function() set_fake_shell() command('terminal') - eq(1000, curbufmeths.get_option('scrollback')) + eq(10000, curbufmeths.get_option('scrollback')) end) it('error if set to invalid value', function() -- cgit From a6de144c3e5cc888ab3cb7c2034a762b23566919 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Fri, 27 Oct 2017 10:48:24 -0400 Subject: 'viewoptions': add "curdir" flag #7447 The flag enables the current local directory set by ":lcd" to be saved to views which is the current default behaviour. The option can be removed to disable this behaviour. closes #7435 vim-patch:8.0.1289 --- test/functional/ex_cmds/mkview_spec.lua | 67 +++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 test/functional/ex_cmds/mkview_spec.lua (limited to 'test') diff --git a/test/functional/ex_cmds/mkview_spec.lua b/test/functional/ex_cmds/mkview_spec.lua new file mode 100644 index 0000000000..97a49dbbd5 --- /dev/null +++ b/test/functional/ex_cmds/mkview_spec.lua @@ -0,0 +1,67 @@ +local lfs = require('lfs') +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local command = helpers.command +local get_pathsep = helpers.get_pathsep +local eq = helpers.eq +local funcs = helpers.funcs +local rmdir = helpers.rmdir + +local file_prefix = 'Xtest-functional-ex_cmds-mkview_spec' + +describe(':mkview', function() + local tmp_file_base = file_prefix .. '-tmpfile' + local local_dir = file_prefix .. '.d' + local view_dir = file_prefix .. '.view.d' + + before_each(function() + clear() + lfs.mkdir(view_dir) + lfs.mkdir(local_dir) + end) + + after_each(function() + -- Remove any views created in the view directory + rmdir(view_dir) + lfs.rmdir(local_dir) + end) + + it('viewoption curdir restores local current directory', function() + local cwd_dir = funcs.getcwd() + local set_view_dir_command = 'set viewdir=' .. cwd_dir .. + get_pathsep() .. view_dir + + -- By default the local current directory should save + command(set_view_dir_command) + command('edit ' .. tmp_file_base .. '1') + command('lcd ' .. local_dir) + command('mkview') + + -- Create a new instance of Nvim to remove the 'lcd' + clear() + + -- Disable saving the local current directory for the second view + command(set_view_dir_command) + command('set viewoptions-=curdir') + command('edit ' .. tmp_file_base .. '2') + command('lcd ' .. local_dir) + command('mkview') + + -- Create a new instance of Nvim to test saved 'lcd' option + clear() + command(set_view_dir_command) + + -- Load the view without a saved local current directory + command('edit ' .. tmp_file_base .. '2') + command('loadview') + -- The view's current directory should not have changed + eq(cwd_dir, funcs.getcwd()) + -- Load the view with a saved local current directory + command('edit ' .. tmp_file_base .. '1') + command('loadview') + -- The view's local directory should have been saved + eq(cwd_dir .. get_pathsep() .. local_dir, funcs.getcwd()) + end) + +end) -- cgit