]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0818: tests: client-server test fails without X11 server v9.2.0818
authorMuraoka Taro <koron.kaoriya@gmail.com>
Mon, 20 Jul 2026 17:31:59 +0000 (17:31 +0000)
committerChristian Brabandt <cb@256bit.org>
Mon, 20 Jul 2026 17:31:59 +0000 (17:31 +0000)
Problem:  When unable to connect to X11, serverlist({'list':1}) returns
          a string instead of a list. This causes Test_remote_serverlist() in
          test_vim9_builtin.vim to fail.
Solution: Raise E240 (No connection to the X server)

Additionally, This fix `Test_clientserver_env_method()` keeping
`VIM_CLIENTSERVER` environment variable instead of deleting it. This
allows certain `+clientserver` tests to pass, even in environments where
the X11 server is unavailable, provided that `VIM_CLIENTSERVER=socket`
is set.

closes: #20716

Co-Authored-By: James McCoy <jamessan@jamessan.com>
Signed-off-by: Muraoka Taro <koron.kaoriya@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/clientserver.c
src/testdir/test_clientserver.vim
src/testdir/test_vim9_builtin.vim
src/version.c

index 13f3fafcb2a155331e3e4a55dc23b430b20b85d7..30aab970fe29b1c72acdd3f17237b6f712ca68e0 100644 (file)
@@ -1284,9 +1284,13 @@ f_serverlist(typval_T *argvars UNUSED, typval_T *rettv)
 #  ifdef FEAT_X11
     if (clientserver_method == CLIENTSERVER_METHOD_X11)
     {
-       make_connection();
-       if (X_DISPLAY != NULL)
-           list = serverGetVimNames(X_DISPLAY);
+       // This function fails if there is no X11 connection.
+       if (check_connection() == FAIL)
+           return;
+       // If the check_connection() function returns OK, it has already been
+       // confirmed within that function that make_connection() was called and
+       // that X_DISPLAY is not NULL.
+       list = serverGetVimNames(X_DISPLAY);
     }
 #  endif
 # endif
index 18877a9d8bf1c7c767fc15e775b8c4e77ed7bcba..4a7763ffab96f3190e793e2c5452232982712777 100644 (file)
@@ -512,6 +512,7 @@ func Test_clientserver_env_method()
   " Don't use channel:2000, because previous tests use that and it may take a
   " while for the channel to fully close.
   let actual = cmd .. ' --servername channel:4000'
+  let save_vim_clientserver = $VIM_CLIENTSERVER
   let $VIM_CLIENTSERVER = 'socket'
 
   let job = job_start(actual, {'stoponexit': 'kill', 'out_io': 'null'})
@@ -528,7 +529,11 @@ func Test_clientserver_env_method()
   else
     call system(actual .. " --remote-expr 'execute(\"qa!\")'")
   endif
-  unlet $VIM_CLIENTSERVER
+  if save_vim_clientserver == ''
+    unlet $VIM_CLIENTSERVER
+  else
+    let $VIM_CLIENTSERVER = save_vim_clientserver
+  endif
 
   try
     call WaitForAssert({-> assert_equal("dead", job_status(job))})
@@ -577,6 +582,50 @@ func Test_clientserver_serverlist_list()
   endtry
 endfunc
 
+func Test_clientserver_serverlist_without_x11()
+  CheckNotGui
+  CheckFeature x11
+
+  let cmd = GetVimCommand()
+  if cmd == ''
+    throw 'GetVimCommand() failed'
+  endif
+
+  " This test verifies that serverlist() fails with error E240 when a
+  " connection to X11 cannot be established. It must be executed with the
+  " CLIENTSERVER backend set to x11 and in a state where the X11 server is
+  " unreachable.
+  "
+  " To achieve this, the `VIM_CLIENTSERVER` and `DISPLAY` environment
+  " variables must be unset before running Vim as a child process. Within the
+  " child process, `assert_fails()` and `v:errors` are used to confirm that
+  " E240 occurred; if E240 is raised as expected, `v:errors` remains empty,
+  " whereas if the call succeeds or a different error occurs, `v:errors` will
+  " contain one or more errors.
+
+  call writefile([
+        \ "call assert_fails('let x = serverlist()', 'E240:')",
+        \ "execute 'cq! ' .. len(v:errors)"
+        \ ], 'Xtest', 'D')
+
+  let save_vim_clientserver = $VIM_CLIENTSERVER
+  unlet $VIM_CLIENTSERVER
+  let save_display = $DISPLAY
+  unlet $DISPLAY
+
+  try
+    call system(cmd .. ' -S Xtest')
+    call assert_equal(0, v:shell_error)
+  finally
+    if save_display != ''
+      let $DISPLAY = save_display
+    endif
+    if save_vim_clientserver != ''
+      let $VIM_CLIENTSERVER = save_vim_clientserver
+    endif
+  endtry
+endfunc
+
 " Uncomment this line to get a debugging log
 " call ch_logfile('channellog', 'w')
 
index 9b5abba5ce7b6bd783b4eac598d7dc2d7729125d..7df789657a4d6419f4c8cbaaa263a4ac750dd3fa 100644 (file)
@@ -3605,10 +3605,14 @@ def Test_remote_serverlist()
 
   v9.CheckSourceDefAndScriptFailure(['serverlist("")'], ['E1013: Argument 1: type mismatch, expected dict<any> but got string', 'E1206: Dictionary required for argument 1'])
   v9.CheckSourceScriptFailure(['vim9script', 'serverlist({list: ""})'], 'E1135: Using a String as a Bool: ""')
-  var l: any = serverlist()
-  assert_equal(v:t_string, type(l))
-  l = serverlist({'list': true})
-  assert_equal(v:t_list, type(l))
+  try
+    var l: any = serverlist()
+    assert_equal(v:t_string, type(l))
+    l = serverlist({'list': true})
+    assert_equal(v:t_list, type(l))
+  catch /E240:/
+    # ignore no connection to the X server
+  endtry
 enddef
 
 def Test_remove_literal_list()
index 91cfa5b70d0c81d05b63d8860dba21e2a9b198d5..a1318f49ad38410171f4fa5b98cb6afdd8966887 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    818,
 /**/
     817,
 /**/