diff options
author | dundargoc <gocdundar@gmail.com> | 2024-04-20 17:44:13 +0200 |
---|---|---|
committer | dundargoc <33953936+dundargoc@users.noreply.github.com> | 2024-04-23 18:17:04 +0200 |
commit | 052498ed42780a76daea589d063cd8947a894673 (patch) | |
tree | b6c85416a4d7ced5eabb0a7a3866f5e0fee886cc /test/functional/editor | |
parent | c5af5c0b9ab84c86f84e32210512923e7eb641ba (diff) | |
download | rneovim-052498ed42780a76daea589d063cd8947a894673.tar.gz rneovim-052498ed42780a76daea589d063cd8947a894673.tar.bz2 rneovim-052498ed42780a76daea589d063cd8947a894673.zip |
test: improve test conventions
Specifically, functions that are run in the context of the test runner
are put in module `test/testutil.lua` while the functions that are run
in the context of the test session are put in
`test/functional/testnvim.lua`.
Closes https://github.com/neovim/neovim/issues/27004.
Diffstat (limited to 'test/functional/editor')
-rw-r--r-- | test/functional/editor/K_spec.lua | 14 | ||||
-rw-r--r-- | test/functional/editor/completion_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/editor/count_spec.lua | 11 | ||||
-rw-r--r-- | test/functional/editor/ctrl_c_spec.lua | 10 | ||||
-rw-r--r-- | test/functional/editor/fold_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/editor/jump_spec.lua | 15 | ||||
-rw-r--r-- | test/functional/editor/lang_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/editor/langmap_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/editor/macro_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/editor/mark_spec.lua | 40 | ||||
-rw-r--r-- | test/functional/editor/meta_key_spec.lua | 16 | ||||
-rw-r--r-- | test/functional/editor/mode_cmdline_spec.lua | 12 | ||||
-rw-r--r-- | test/functional/editor/mode_insert_spec.lua | 20 | ||||
-rw-r--r-- | test/functional/editor/mode_normal_spec.lua | 14 | ||||
-rw-r--r-- | test/functional/editor/put_spec.lua | 19 | ||||
-rw-r--r-- | test/functional/editor/search_spec.lua | 8 | ||||
-rw-r--r-- | test/functional/editor/tabpage_spec.lua | 21 | ||||
-rw-r--r-- | test/functional/editor/undo_spec.lua | 25 |
18 files changed, 172 insertions, 144 deletions
diff --git a/test/functional/editor/K_spec.lua b/test/functional/editor/K_spec.lua index 91038e5f4e..3c58892731 100644 --- a/test/functional/editor/K_spec.lua +++ b/test/functional/editor/K_spec.lua @@ -1,5 +1,7 @@ -local t = require('test.functional.testutil')() -local eq, clear, eval, feed, api, retry = t.eq, t.clear, t.eval, t.feed, t.api, t.retry +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local eq, clear, eval, feed, api, retry = t.eq, n.clear, n.eval, n.feed, n.api, t.retry describe('K', function() local test_file = 'K_spec_out' @@ -12,19 +14,19 @@ describe('K', function() end) it("invokes colon-prefixed 'keywordprg' as Vim command", function() - t.source([[ + n.source([[ let @a='fnord' set keywordprg=:put]]) -- K on the text "a" resolves to `:put a`. feed('ia<ESC>K') - t.expect([[ + n.expect([[ a fnord]]) end) it("invokes non-prefixed 'keywordprg' as shell command", function() - t.source([[ + n.source([[ let @a='fnord' set keywordprg=echo\ fnord>>]]) @@ -42,7 +44,7 @@ describe('K', function() end) it("<esc> kills the buffer for a running 'keywordprg' command", function() - t.source('set keywordprg=less') + n.source('set keywordprg=less') eval('writefile(["hello", "world"], "' .. test_file .. '")') feed('i' .. test_file .. '<esc>K') eq('t', eval('mode()')) diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index c479a9ccf1..62bb7e19f3 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -1,13 +1,15 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local assert_alive = t.assert_alive -local clear, feed = t.clear, t.feed -local eval, eq, neq = t.eval, t.eq, t.neq -local feed_command, source, expect = t.feed_command, t.source, t.expect -local fn = t.fn -local command = t.command -local api = t.api -local poke_eventloop = t.poke_eventloop + +local assert_alive = n.assert_alive +local clear, feed = n.clear, n.feed +local eval, eq, neq = n.eval, t.eq, t.neq +local feed_command, source, expect = n.feed_command, n.source, n.expect +local fn = n.fn +local command = n.command +local api = n.api +local poke_eventloop = n.poke_eventloop describe('completion', function() local screen diff --git a/test/functional/editor/count_spec.lua b/test/functional/editor/count_spec.lua index 6a3efcf515..d158497cb8 100644 --- a/test/functional/editor/count_spec.lua +++ b/test/functional/editor/count_spec.lua @@ -1,10 +1,11 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local eq = t.eq -local eval = t.eval -local feed = t.feed -local clear = t.clear -local command = t.command +local eval = n.eval +local feed = n.feed +local clear = n.clear +local command = n.command describe('v:count/v:count1', function() before_each(function() diff --git a/test/functional/editor/ctrl_c_spec.lua b/test/functional/editor/ctrl_c_spec.lua index b0160630d9..e1258c7df8 100644 --- a/test/functional/editor/ctrl_c_spec.lua +++ b/test/functional/editor/ctrl_c_spec.lua @@ -1,8 +1,10 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear, feed, source = t.clear, t.feed, t.source -local command = t.command -local poke_eventloop = t.poke_eventloop + +local clear, feed, source = n.clear, n.feed, n.source +local command = n.command +local poke_eventloop = n.poke_eventloop local sleep = vim.uv.sleep describe('CTRL-C (mapped)', function() diff --git a/test/functional/editor/fold_spec.lua b/test/functional/editor/fold_spec.lua index 336b97b15e..ee3f268a2a 100644 --- a/test/functional/editor/fold_spec.lua +++ b/test/functional/editor/fold_spec.lua @@ -1,12 +1,13 @@ -local t = require('test.functional.testutil')() - -local clear = t.clear -local insert = t.insert -local exec = t.exec -local feed = t.feed -local expect = t.expect -local command = t.command -local fn = t.fn +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local insert = n.insert +local exec = n.exec +local feed = n.feed +local expect = n.expect +local command = n.command +local fn = n.fn local eq = t.eq local neq = t.neq @@ -376,7 +377,7 @@ a]], end) it('splits folds according to >N and <N with foldexpr', function() - t.source([[ + n.source([[ function TestFoldExpr(lnum) let thisline = getline(a:lnum) if thisline == 'a' diff --git a/test/functional/editor/jump_spec.lua b/test/functional/editor/jump_spec.lua index 5911fcdbfb..880831d9f8 100644 --- a/test/functional/editor/jump_spec.lua +++ b/test/functional/editor/jump_spec.lua @@ -1,15 +1,16 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear -local command = t.command +local clear = n.clear +local command = n.command local dedent = t.dedent local eq = t.eq -local fn = t.fn -local feed = t.feed -local exec_capture = t.exec_capture +local fn = n.fn +local feed = n.feed +local exec_capture = n.exec_capture local write_file = t.write_file -local api = t.api +local api = n.api describe('jumplist', function() local fname1 = 'Xtest-functional-normal-jump' diff --git a/test/functional/editor/lang_spec.lua b/test/functional/editor/lang_spec.lua index 0e11a53999..74d83bcfa8 100644 --- a/test/functional/editor/lang_spec.lua +++ b/test/functional/editor/lang_spec.lua @@ -1,8 +1,10 @@ -local t = require('test.functional.testutil')() -local clear, insert, eq = t.clear, t.insert, t.eq -local command, expect = t.command, t.expect -local feed, eval = t.feed, t.eval -local exc_exec = t.exc_exec +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear, insert, eq = n.clear, n.insert, t.eq +local command, expect = n.command, n.expect +local feed, eval = n.feed, n.eval +local exc_exec = n.exc_exec describe('gu and gU', function() before_each(clear) diff --git a/test/functional/editor/langmap_spec.lua b/test/functional/editor/langmap_spec.lua index a17bbc4f16..e50e19a468 100644 --- a/test/functional/editor/langmap_spec.lua +++ b/test/functional/editor/langmap_spec.lua @@ -1,10 +1,11 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local eq, neq, call = t.eq, t.neq, t.call -local eval, feed, clear = t.eval, t.feed, t.clear -local command, insert, expect = t.command, t.insert, t.expect -local feed_command = t.feed_command -local curwin = t.api.nvim_get_current_win +local eq, neq, call = t.eq, t.neq, n.call +local eval, feed, clear = n.eval, n.feed, n.clear +local command, insert, expect = n.command, n.insert, n.expect +local feed_command = n.feed_command +local curwin = n.api.nvim_get_current_win describe("'langmap'", function() before_each(function() @@ -133,7 +134,7 @@ describe("'langmap'", function() hello]]) end) it('command-line CTRL-R', function() - t.source([[ + n.source([[ let i_value = 0 let j_value = 0 call setreg('i', 'i_value') @@ -171,7 +172,7 @@ describe("'langmap'", function() end) it('prompt for number', function() command('set langmap=12,21') - t.source([[ + n.source([[ let gotten_one = 0 function Map() let answer = inputlist(['a', '1.', '2.', '3.']) @@ -214,7 +215,7 @@ describe("'langmap'", function() end feed('qa' .. command_string .. 'q') expect(expect_string) - eq(expect_macro or t.fn.nvim_replace_termcodes(command_string, true, true, true), eval('@a')) + eq(expect_macro or n.fn.nvim_replace_termcodes(command_string, true, true, true), eval('@a')) if setup_function then setup_function() end diff --git a/test/functional/editor/macro_spec.lua b/test/functional/editor/macro_spec.lua index 4e32e5b3af..27c5eddac8 100644 --- a/test/functional/editor/macro_spec.lua +++ b/test/functional/editor/macro_spec.lua @@ -1,14 +1,15 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local eq = t.eq -local eval = t.eval -local feed = t.feed -local clear = t.clear -local expect = t.expect -local command = t.command -local fn = t.fn -local api = t.api -local insert = t.insert +local eval = n.eval +local feed = n.feed +local clear = n.clear +local expect = n.expect +local command = n.command +local fn = n.fn +local api = n.api +local insert = n.insert describe('macros with default mappings', function() before_each(function() diff --git a/test/functional/editor/mark_spec.lua b/test/functional/editor/mark_spec.lua index dfbf1e3e58..69cb95e1c3 100644 --- a/test/functional/editor/mark_spec.lua +++ b/test/functional/editor/mark_spec.lua @@ -1,15 +1,17 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local api = t.api -local clear = t.clear -local command = t.command -local fn = t.fn + +local api = n.api +local clear = n.clear +local command = n.command +local fn = n.fn local eq = t.eq -local feed = t.feed +local feed = n.feed local write_file = t.write_file local pcall_err = t.pcall_err local cursor = function() - return t.api.nvim_win_get_cursor(0) + return n.api.nvim_win_get_cursor(0) end describe('named marks', function() @@ -39,59 +41,59 @@ describe('named marks', function() it('errors when set out of range with :mark', function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, '1000mark x') + local err = pcall_err(n.exec_capture, '1000mark x') eq('nvim_exec2(): Vim(mark):E16: Invalid range: 1000mark x', err) end) it('errors when set out of range with :k', function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, '1000kx') + local err = pcall_err(n.exec_capture, '1000kx') eq('nvim_exec2(): Vim(k):E16: Invalid range: 1000kx', err) end) it('errors on unknown mark name with :mark', function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, 'mark #') + local err = pcall_err(n.exec_capture, 'mark #') eq('nvim_exec2(): Vim(mark):E191: Argument must be a letter or forward/backward quote', err) end) it("errors on unknown mark name with '", function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, "normal! '#") + local err = pcall_err(n.exec_capture, "normal! '#") eq('nvim_exec2(): Vim(normal):E78: Unknown mark', err) end) it('errors on unknown mark name with `', function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, 'normal! `#') + local err = pcall_err(n.exec_capture, 'normal! `#') eq('nvim_exec2(): Vim(normal):E78: Unknown mark', err) end) it("errors when moving to a mark that is not set with '", function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, "normal! 'z") + local err = pcall_err(n.exec_capture, "normal! 'z") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) - err = pcall_err(t.exec_capture, "normal! '.") + err = pcall_err(n.exec_capture, "normal! '.") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it('errors when moving to a mark that is not set with `', function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, 'normal! `z') + local err = pcall_err(n.exec_capture, 'normal! `z') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) - err = pcall_err(t.exec_capture, 'normal! `>') + err = pcall_err(n.exec_capture, 'normal! `>') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it("errors when moving to a global mark that is not set with '", function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, "normal! 'Z") + local err = pcall_err(n.exec_capture, "normal! 'Z") eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) it('errors when moving to a global mark that is not set with `', function() command('edit ' .. file1) - local err = pcall_err(t.exec_capture, 'normal! `Z') + local err = pcall_err(n.exec_capture, 'normal! `Z') eq('nvim_exec2(): Vim(normal):E20: Mark not set', err) end) @@ -166,7 +168,7 @@ describe('named marks', function() feed('mA') command('next') command('bw! ' .. file1) - local err = pcall_err(t.exec_capture, "normal! 'A") + local err = pcall_err(n.exec_capture, "normal! 'A") eq('nvim_exec2(): Vim(normal):E92: Buffer 1 not found', err) os.remove(file1) end) diff --git a/test/functional/editor/meta_key_spec.lua b/test/functional/editor/meta_key_spec.lua index 0dc6884fac..87fe395608 100644 --- a/test/functional/editor/meta_key_spec.lua +++ b/test/functional/editor/meta_key_spec.lua @@ -1,10 +1,12 @@ -local t = require('test.functional.testutil')() -local clear, feed, insert = t.clear, t.feed, t.insert -local command = t.command -local exec_lua = t.exec_lua -local eval = t.eval -local expect = t.expect -local fn = t.fn +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear, feed, insert = n.clear, n.feed, n.insert +local command = n.command +local exec_lua = n.exec_lua +local eval = n.eval +local expect = n.expect +local fn = n.fn local eq = t.eq describe('meta-keys #8226 #13042', function() diff --git a/test/functional/editor/mode_cmdline_spec.lua b/test/functional/editor/mode_cmdline_spec.lua index e52eb7aaba..70bdc5d4c2 100644 --- a/test/functional/editor/mode_cmdline_spec.lua +++ b/test/functional/editor/mode_cmdline_spec.lua @@ -1,11 +1,13 @@ -- Cmdline-mode tests. -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear, insert, fn, eq, feed = t.clear, t.insert, t.fn, t.eq, t.feed -local eval = t.eval -local command = t.command -local api = t.api + +local clear, insert, fn, eq, feed = n.clear, n.insert, n.fn, t.eq, n.feed +local eval = n.eval +local command = n.command +local api = n.api describe('cmdline', function() before_each(clear) diff --git a/test/functional/editor/mode_insert_spec.lua b/test/functional/editor/mode_insert_spec.lua index 6d075cdf36..fb3dda4bf4 100644 --- a/test/functional/editor/mode_insert_spec.lua +++ b/test/functional/editor/mode_insert_spec.lua @@ -1,14 +1,16 @@ -- Insert-mode tests. -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear, feed, insert = t.clear, t.feed, t.insert -local expect = t.expect -local command = t.command + +local clear, feed, insert = n.clear, n.feed, n.insert +local expect = n.expect +local command = n.command local eq = t.eq -local eval = t.eval -local curbuf_contents = t.curbuf_contents -local api = t.api +local eval = n.eval +local curbuf_contents = n.curbuf_contents +local api = n.api describe('insert-mode', function() before_each(function() @@ -223,10 +225,10 @@ describe('insert-mode', function() end local function test_cols(expected_cols) - local cols = { { t.fn.col('.'), t.fn.virtcol('.') } } + local cols = { { n.fn.col('.'), n.fn.virtcol('.') } } for _ = 2, #expected_cols do feed('<BS>') - table.insert(cols, { t.fn.col('.'), t.fn.virtcol('.') }) + table.insert(cols, { n.fn.col('.'), n.fn.virtcol('.') }) end eq(expected_cols, cols) end diff --git a/test/functional/editor/mode_normal_spec.lua b/test/functional/editor/mode_normal_spec.lua index b80723a5b9..b3ef4866dc 100644 --- a/test/functional/editor/mode_normal_spec.lua +++ b/test/functional/editor/mode_normal_spec.lua @@ -1,11 +1,13 @@ -- Normal mode tests. -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear -local feed = t.feed -local fn = t.fn -local command = t.command + +local clear = n.clear +local feed = n.feed +local fn = n.fn +local command = n.command local eq = t.eq describe('Normal mode', function() @@ -25,7 +27,7 @@ describe('Normal mode', function() local screen = Screen.new(60, 17) screen:attach() fn.termopen( - { t.nvim_prog, '--clean', '--cmd', 'startinsert' }, + { n.nvim_prog, '--clean', '--cmd', 'startinsert' }, { env = { VIMRUNTIME = os.getenv('VIMRUNTIME') } } ) screen:expect({ diff --git a/test/functional/editor/put_spec.lua b/test/functional/editor/put_spec.lua index 85580498b7..0f6936cd31 100644 --- a/test/functional/editor/put_spec.lua +++ b/test/functional/editor/put_spec.lua @@ -1,17 +1,18 @@ +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local t = require('test.functional.testutil')() -local clear = t.clear -local insert = t.insert -local feed = t.feed -local expect = t.expect +local clear = n.clear +local insert = n.insert +local feed = n.feed +local expect = n.expect local eq = t.eq local map = vim.tbl_map local filter = vim.tbl_filter -local feed_command = t.feed_command -local command = t.command -local curbuf_contents = t.curbuf_contents -local fn = t.fn +local feed_command = n.feed_command +local command = n.command +local curbuf_contents = n.curbuf_contents +local fn = n.fn local dedent = t.dedent local function reset() diff --git a/test/functional/editor/search_spec.lua b/test/functional/editor/search_spec.lua index c8c7c688f6..770a4f387d 100644 --- a/test/functional/editor/search_spec.lua +++ b/test/functional/editor/search_spec.lua @@ -1,6 +1,8 @@ -local t = require('test.functional.testutil')() -local clear = t.clear -local command = t.command +local t = require('test.testutil') +local n = require('test.functional.testnvim')() + +local clear = n.clear +local command = n.command local eq = t.eq local pcall_err = t.pcall_err diff --git a/test/functional/editor/tabpage_spec.lua b/test/functional/editor/tabpage_spec.lua index 4b880e21bf..0b26494436 100644 --- a/test/functional/editor/tabpage_spec.lua +++ b/test/functional/editor/tabpage_spec.lua @@ -1,17 +1,18 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() local Screen = require('test.functional.ui.screen') -local clear = t.clear -local command = t.command +local clear = n.clear +local command = n.command local eq = t.eq local neq = t.neq -local feed = t.feed -local eval = t.eval -local exec = t.exec -local fn = t.fn -local api = t.api -local curwin = t.api.nvim_get_current_win -local assert_alive = t.assert_alive +local feed = n.feed +local eval = n.eval +local exec = n.exec +local fn = n.fn +local api = n.api +local curwin = n.api.nvim_get_current_win +local assert_alive = n.assert_alive describe('tabpage', function() before_each(clear) diff --git a/test/functional/editor/undo_spec.lua b/test/functional/editor/undo_spec.lua index 70ed5b6756..12056394d2 100644 --- a/test/functional/editor/undo_spec.lua +++ b/test/functional/editor/undo_spec.lua @@ -1,16 +1,17 @@ -local t = require('test.functional.testutil')() +local t = require('test.testutil') +local n = require('test.functional.testnvim')() -local clear = t.clear -local command = t.command -local eval = t.eval -local expect = t.expect +local clear = n.clear +local command = n.command +local eval = n.eval +local expect = n.expect local eq = t.eq -local feed = t.feed -local feed_command = t.feed_command -local insert = t.insert -local fn = t.fn -local exec = t.exec -local exec_lua = t.exec_lua +local feed = n.feed +local feed_command = n.feed_command +local insert = n.insert +local fn = n.fn +local exec = n.exec +local exec_lua = n.exec_lua local function lastmessage() local messages = fn.split(fn.execute('messages'), '\n') @@ -44,7 +45,7 @@ describe('u CTRL-R g- g+', function() local function undo_and_redo(hist_pos, undo, redo, expect_str) command('enew!') create_history(hist_pos) - local cur_contents = t.curbuf_contents() + local cur_contents = n.curbuf_contents() feed(undo) expect(expect_str) feed(redo) |