From 0c59771e314d6faaad69676985cd2a11c157ee37 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 22 Mar 2024 11:02:52 +0100 Subject: refactor(tests): all screen tests should use highlights This is the first installment of a multi-PR series significantly refactoring how highlights are being specified. The end goal is to have a base set of 20 ish most common highlights, and then specific files only need to add more groups to that as needed. As a complicating factor, we also want to migrate to the new default color scheme eventually. But by sharing a base set, that future PR will hopefully be a lot smaller since a lot of tests will be migrated just simply by updating the base set in place. As a first step, fix the anti-pattern than Screen defaults to ignoring highlights. Highlights are integral part of the screen state, not something "extra" which we only test "sometimes". For now, we still allow opt-out via the intentionally ugly screen._default_attr_ids = nil The end goal is to get rid of all of these eventually (which will be easier as part of the color scheme migration) --- test/functional/vimscript/system_spec.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'test/functional/vimscript/system_spec.lua') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index d44f68e152..db27c5206f 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -214,7 +214,7 @@ describe('system()', function() feed(':call system("echo")') screen:expect([[ ^ | - ~ |*12 + {1:~ }|*12 :call system("echo") | ]]) end) @@ -262,14 +262,14 @@ describe('system()', function() ) screen:expect([[ | - ~ |*12 + {1:~ }|*12 ]] .. (is_os('win') and [[ :call system("for /L %I in (1,0,2) do @echo y") |]] or [[ :call system("yes") |]])) feed('foo') screen:expect([[ ^ | - ~ |*12 + {1:~ }|*12 Type :qa and press to exit Nvim | ]]) end) @@ -283,15 +283,15 @@ describe('system()', function() ) screen:expect([[ | - ~ |*12 + {1:~ }|*12 ]] .. (is_os('win') and [[ :call system("for /L %I in (1,0,2) do @echo y") |]] or [[ :call system("yes") |]])) feed('foo') screen:expect([[ ^ | - ~ |*12 - -- INSERT -- | + {1:~ }|*12 + {5:-- INSERT --} | ]]) end) end) @@ -447,7 +447,7 @@ describe('systemlist()', function() feed(':call systemlist("echo")') screen:expect([[ ^ | - ~ |*12 + {1:~ }|*12 :call systemlist("echo") | ]]) end) @@ -456,13 +456,13 @@ describe('systemlist()', function() feed(':call systemlist("yes | xargs")') screen:expect([[ | - ~ |*12 + {1:~ }|*12 :call systemlist("yes | xargs") | ]]) feed('') screen:expect([[ ^ | - ~ |*12 + {1:~ }|*12 Type :qa and press to exit Nvim | ]]) end) -- cgit From 7035125b2b26aa68fcfb7cda39377ac79926a0f9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 8 Apr 2024 11:03:20 +0200 Subject: test: improve test conventions Work on https://github.com/neovim/neovim/issues/27004. --- test/functional/vimscript/system_spec.lua | 54 ++++++++++++++----------------- 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'test/functional/vimscript/system_spec.lua') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index db27c5206f..1cbe9422e2 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -1,24 +1,18 @@ -- Tests for system() and :! shell. -local helpers = require('test.functional.helpers')(after_each) +local t = require('test.functional.testutil')(after_each) -local assert_alive = helpers.assert_alive -local testprg = helpers.testprg +local assert_alive = t.assert_alive +local testprg = t.testprg local eq, call, clear, eval, feed_command, feed, api = - helpers.eq, - helpers.call, - helpers.clear, - helpers.eval, - helpers.feed_command, - helpers.feed, - helpers.api -local command = helpers.command -local insert = helpers.insert -local expect = helpers.expect -local exc_exec = helpers.exc_exec -local os_kill = helpers.os_kill -local pcall_err = helpers.pcall_err -local is_os = helpers.is_os + t.eq, t.call, t.clear, t.eval, t.feed_command, t.feed, t.api +local command = t.command +local insert = t.insert +local expect = t.expect +local exc_exec = t.exc_exec +local os_kill = t.os_kill +local pcall_err = t.pcall_err +local is_os = t.is_os local Screen = require('test.functional.ui.screen') @@ -189,7 +183,7 @@ describe('system()', function() end) it('with powershell', function() - helpers.set_shell_powershell() + t.set_shell_powershell() eq('a\nb\n', eval([[system('Write-Output a b')]])) eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]])) eq('a b\n', eval([[system('Write-Output "a b"')]])) @@ -197,11 +191,11 @@ describe('system()', function() end it('powershell w/ UTF-8 text #13713', function() - if not helpers.has_powershell() then + if not t.has_powershell() then pending('powershell not found', function() end) return end - helpers.set_shell_powershell() + t.set_shell_powershell() eq('ああ\n', eval([[system('Write-Output "ああ"')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc @@ -234,7 +228,7 @@ describe('system()', function() end) it('self and total time recorded separately', function() - local tempfile = helpers.tmpname() + local tempfile = t.tmpname() feed(':function! AlmostNoSelfTime()') feed('echo system("echo hi")') @@ -247,11 +241,11 @@ describe('system()', function() feed(':edit ' .. tempfile .. '') - local command_total_time = tonumber(helpers.fn.split(helpers.fn.getline(7))[2]) - local command_self_time = tonumber(helpers.fn.split(helpers.fn.getline(7))[3]) + local command_total_time = tonumber(t.fn.split(t.fn.getline(7))[2]) + local command_self_time = tonumber(t.fn.split(t.fn.getline(7))[3]) - helpers.neq(nil, command_total_time) - helpers.neq(nil, command_self_time) + t.neq(nil, command_total_time) + t.neq(nil, command_self_time) end) it('`yes` interrupted with CTRL-C', function() @@ -554,11 +548,11 @@ describe('systemlist()', function() end) it('powershell w/ UTF-8 text #13713', function() - if not helpers.has_powershell() then + if not t.has_powershell() then pending('powershell not found', function() end) return end - helpers.set_shell_powershell() + t.set_shell_powershell() eq({ is_os('win') and 'あ\r' or 'あ' }, eval([[systemlist('Write-Output あ')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc @@ -574,7 +568,7 @@ describe('shell :!', function() it(':{range}! with powershell filter/redirect #16271 #19250', function() local screen = Screen.new(500, 8) screen:attach() - local found = helpers.set_shell_powershell(true) + local found = t.set_shell_powershell(true) insert([[ 3 1 @@ -621,12 +615,12 @@ describe('shell :!', function() } end feed('') - helpers.set_shell_powershell(true) + t.set_shell_powershell(true) feed(':4verbose %w !sort') screen:expect { any = [[Executing command: .?& { Get%-Content .* | & sort }]], } feed('') - helpers.expect_exit(command, 'qall!') + t.expect_exit(command, 'qall!') end) end) -- cgit From 81fc27124b9e1b375e0ce9605ae69c3c2a2d9222 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 9 Apr 2024 12:26:16 +0100 Subject: refactor(test): inject after_each differently --- test/functional/vimscript/system_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/vimscript/system_spec.lua') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index 1cbe9422e2..77ba4e8f97 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -1,6 +1,6 @@ -- Tests for system() and :! shell. -local t = require('test.functional.testutil')(after_each) +local t = require('test.functional.testutil')() local assert_alive = t.assert_alive local testprg = t.testprg -- cgit From 052498ed42780a76daea589d063cd8947a894673 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 20 Apr 2024 17:44:13 +0200 Subject: 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. --- test/functional/vimscript/system_spec.lua | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'test/functional/vimscript/system_spec.lua') diff --git a/test/functional/vimscript/system_spec.lua b/test/functional/vimscript/system_spec.lua index 77ba4e8f97..792e4c46c3 100644 --- a/test/functional/vimscript/system_spec.lua +++ b/test/functional/vimscript/system_spec.lua @@ -1,21 +1,21 @@ -- Tests for system() and :! shell. -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 testprg = t.testprg +local assert_alive = n.assert_alive +local testprg = n.testprg local eq, call, clear, eval, feed_command, feed, api = - t.eq, t.call, t.clear, t.eval, t.feed_command, t.feed, t.api -local command = t.command -local insert = t.insert -local expect = t.expect -local exc_exec = t.exc_exec -local os_kill = t.os_kill + t.eq, n.call, n.clear, n.eval, n.feed_command, n.feed, n.api +local command = n.command +local insert = n.insert +local expect = n.expect +local exc_exec = n.exc_exec +local os_kill = n.os_kill local pcall_err = t.pcall_err local is_os = t.is_os -local Screen = require('test.functional.ui.screen') - local function create_file_with_nuls(name) return function() feed('ipart1000part2000part3:w ' .. name .. '') @@ -183,7 +183,7 @@ describe('system()', function() end) it('with powershell', function() - t.set_shell_powershell() + n.set_shell_powershell() eq('a\nb\n', eval([[system('Write-Output a b')]])) eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]])) eq('a b\n', eval([[system('Write-Output "a b"')]])) @@ -191,11 +191,11 @@ describe('system()', function() end it('powershell w/ UTF-8 text #13713', function() - if not t.has_powershell() then + if not n.has_powershell() then pending('powershell not found', function() end) return end - t.set_shell_powershell() + n.set_shell_powershell() eq('ああ\n', eval([[system('Write-Output "ああ"')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc @@ -241,8 +241,8 @@ describe('system()', function() feed(':edit ' .. tempfile .. '') - local command_total_time = tonumber(t.fn.split(t.fn.getline(7))[2]) - local command_self_time = tonumber(t.fn.split(t.fn.getline(7))[3]) + local command_total_time = tonumber(n.fn.split(n.fn.getline(7))[2]) + local command_self_time = tonumber(n.fn.split(n.fn.getline(7))[3]) t.neq(nil, command_total_time) t.neq(nil, command_self_time) @@ -548,11 +548,11 @@ describe('systemlist()', function() end) it('powershell w/ UTF-8 text #13713', function() - if not t.has_powershell() then + if not n.has_powershell() then pending('powershell not found', function() end) return end - t.set_shell_powershell() + n.set_shell_powershell() eq({ is_os('win') and 'あ\r' or 'あ' }, eval([[systemlist('Write-Output あ')]])) -- Sanity test w/ default encoding -- * on Windows, expected to default to Western European enc @@ -568,7 +568,7 @@ describe('shell :!', function() it(':{range}! with powershell filter/redirect #16271 #19250', function() local screen = Screen.new(500, 8) screen:attach() - local found = t.set_shell_powershell(true) + local found = n.set_shell_powershell(true) insert([[ 3 1 @@ -615,12 +615,12 @@ describe('shell :!', function() } end feed('') - t.set_shell_powershell(true) + n.set_shell_powershell(true) feed(':4verbose %w !sort') screen:expect { any = [[Executing command: .?& { Get%-Content .* | & sort }]], } feed('') - t.expect_exit(command, 'qall!') + n.expect_exit(command, 'qall!') end) end) -- cgit