+" Test that $VIM_CLIENTSERVER env var works properly
+func Test_clientserver_env_method()
+ CheckFeature socketserver
+
+ let g:test_is_flaky = 1
+ let cmd = GetVimCommand()
+
+ if cmd == ''
+ throw 'GetVimCommand() failed'
+ endif
+
+ " 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 $VIM_CLIENTSERVER = 'socket'
+
+ let job = job_start(actual, {'stoponexit': 'kill', 'out_io': 'null'})
+
+ call WaitForAssert({-> assert_equal("run", job_status(job))})
+
+ if !has('win32') || !has('gui_running')
+ call assert_match('channel:4000',
+ \ system(actual .. ' --remote-expr "v:servername"'))
+ endif
+
+ if has('win32')
+ call job_stop(job, 'kill')
+ else
+ call system(actual .. " --remote-expr 'execute(\"qa!\")'")
+ endif
+ unlet $VIM_CLIENTSERVER
+
+ try
+ call WaitForAssert({-> assert_equal("dead", job_status(job))})
+ finally
+ if job_status(job) != 'dead'
+ call assert_report('Server did not exit')
+ call job_stop(job, 'kill')
+ endif
+ endtry
+endfunc
+