test: :restart works on Windows

This commit is contained in:
zeertzjq
2025-06-10 17:52:42 +08:00
parent 2dba5abcb2
commit c2aa5fd915
2 changed files with 37 additions and 16 deletions

View File

@@ -81,7 +81,6 @@ Restart Nvim
Note: If the current UI hasn't implemented the "restart" UI Note: If the current UI hasn't implemented the "restart" UI
event, this command is equivalent to `:qall`. event, this command is equivalent to `:qall`.
Note: Only works if the UI and server are on the same system. Note: Only works if the UI and server are on the same system.
Note: Not supported on Windows yet.
:restart! :restart!
Force restarts the Nvim server, abandoning unsaved buffers. Force restarts the Nvim server, abandoning unsaved buffers.

View File

@@ -179,10 +179,6 @@ describe('TUI :detach', function()
end) end)
end) end)
if t.skip(is_os('win')) then
return
end
describe('TUI :restart', function() describe('TUI :restart', function()
it('resets buffer to blank', function() it('resets buffer to blank', function()
clear() clear()
@@ -206,6 +202,19 @@ describe('TUI :restart', function()
'echo getpid()', 'echo getpid()',
}) })
--- FIXME: On Windows spaces at the end of a screen line may have wrong attrs.
--- Remove this function when that's fixed.
---
--- @param s string
local function screen_expect(s)
if is_os('win') then
s = s:gsub(' +%}%|\n', '{MATCH: *}}{MATCH: *}|\n')
s = s:gsub(' *%} +%|\n', '{MATCH: *}}{MATCH: *}|\n')
s = s:gsub('%}%^ +%|\n', '{MATCH:[ ^]*}}{MATCH:[ ^]*}|\n')
end
screen:expect(s)
end
local s0 = [[ local s0 = [[
^ | ^ |
{4:~ }|*3 {4:~ }|*3
@@ -213,11 +222,20 @@ describe('TUI :restart', function()
{MATCH:%d+ +}| {MATCH:%d+ +}|
{3:-- TERMINAL --} | {3:-- TERMINAL --} |
]] ]]
screen:expect(s0) screen_expect(s0)
local server_session = n.connect(server_pipe)
local _, server_pid = server_session:request('nvim_call_function', 'getpid', {}) local server_session --[[@type test.Session]]
local server_pid --[[@type any]]
-- FIXME: On Windows connect() hangs.
if not is_os('win') then
server_session = n.connect(server_pipe)
_, server_pid = server_session:request('nvim_call_function', 'getpid', {})
end
local function restart_pid_check() local function restart_pid_check()
if is_os('win') then
return
end
server_session:close() server_session:close()
server_session = n.connect(server_pipe) server_session = n.connect(server_pipe)
local _, new_pid = server_session:request('nvim_call_function', 'getpid', {}) local _, new_pid = server_session:request('nvim_call_function', 'getpid', {})
@@ -233,11 +251,11 @@ describe('TUI :restart', function()
-- Check ":restart" on an unmodified buffer. -- Check ":restart" on an unmodified buffer.
tt.feed_data(':restart\013') tt.feed_data(':restart\013')
screen:expect(s0) screen_expect(s0)
restart_pid_check() restart_pid_check()
tt.feed_data('ithis will be removed\027') tt.feed_data('ithis will be removed\027')
screen:expect([[ screen_expect([[
this will be remove^d | this will be remove^d |
{4:~ }|*3 {4:~ }|*3
{5:[No Name] [+] }| {5:[No Name] [+] }|
@@ -247,7 +265,7 @@ describe('TUI :restart', function()
-- Check ":restart" on a modified buffer. -- Check ":restart" on a modified buffer.
tt.feed_data(':restart\013') tt.feed_data(':restart\013')
screen:expect([[ screen_expect([[
this will be removed | this will be removed |
{5: }| {5: }|
{8:E37: No write since last change} | {8:E37: No write since last change} |
@@ -259,11 +277,11 @@ describe('TUI :restart', function()
-- Check ":restart!". -- Check ":restart!".
tt.feed_data(':restart!\013') tt.feed_data(':restart!\013')
screen:expect(s0) screen_expect(s0)
restart_pid_check() restart_pid_check()
tt.feed_data(':echo\n') tt.feed_data(':echo\n')
screen:expect([[ screen_expect([[
^ | ^ |
{4:~ }|*3 {4:~ }|*3
{5:[No Name] }| {5:[No Name] }|
@@ -273,11 +291,11 @@ describe('TUI :restart', function()
-- No --listen conflict when server exit is delayed. -- No --listen conflict when server exit is delayed.
feed_data(':lua vim.schedule(function() vim.wait(100) end); vim.cmd.restart()\n') feed_data(':lua vim.schedule(function() vim.wait(100) end); vim.cmd.restart()\n')
screen:expect(s0) screen_expect(s0)
restart_pid_check() restart_pid_check()
screen:try_resize(60, 6) screen:try_resize(60, 6)
screen:expect([[ screen_expect([[
^ | ^ |
{4:~ }|*2 {4:~ }|*2
{5:[No Name] }| {5:[No Name] }|
@@ -287,7 +305,7 @@ describe('TUI :restart', function()
--- Check that ":restart" uses the updated size after terminal resize. --- Check that ":restart" uses the updated size after terminal resize.
tt.feed_data(':restart\013') tt.feed_data(':restart\013')
screen:expect([[ screen_expect([[
^ | ^ |
{4:~ }|*2 {4:~ }|*2
{5:[No Name] }| {5:[No Name] }|
@@ -298,6 +316,10 @@ describe('TUI :restart', function()
end) end)
end) end)
if t.skip(is_os('win')) then
return
end
describe('TUI', function() describe('TUI', function()
local screen --[[@type test.functional.ui.screen]] local screen --[[@type test.functional.ui.screen]]
local child_session --[[@type test.Session]] local child_session --[[@type test.Session]]