From: Muraoka Taro Date: Mon, 20 Jul 2026 17:31:59 +0000 (+0000) Subject: patch 9.2.0818: tests: client-server test fails without X11 server X-Git-Tag: v9.2.0818^0 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3cfdb634b1db2ed51d1147b720e0d9d67b7f5252;p=thirdparty%2Fvim.git patch 9.2.0818: tests: client-server test fails without X11 server 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 Signed-off-by: Muraoka Taro Signed-off-by: Christian Brabandt --- diff --git a/src/clientserver.c b/src/clientserver.c index 13f3fafcb2..30aab970fe 100644 --- a/src/clientserver.c +++ b/src/clientserver.c @@ -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 diff --git a/src/testdir/test_clientserver.vim b/src/testdir/test_clientserver.vim index 18877a9d8b..4a7763ffab 100644 --- a/src/testdir/test_clientserver.vim +++ b/src/testdir/test_clientserver.vim @@ -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') diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim index 9b5abba5ce..7df789657a 100644 --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -3605,10 +3605,14 @@ def Test_remote_serverlist() v9.CheckSourceDefAndScriptFailure(['serverlist("")'], ['E1013: Argument 1: type mismatch, expected dict 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() diff --git a/src/version.c b/src/version.c index 91cfa5b70d..a1318f49ad 100644 --- a/src/version.c +++ b/src/version.c @@ -759,6 +759,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 818, /**/ 817, /**/