diff src/testdir/test_clientserver.vim @ 12765:c1347c968d31 v8.0.1260

patch 8.0.1260: using global variables for WaitFor() commit https://github.com/vim/vim/commit/ab8b1c14a31e36ae87cc7e13c4a75318d513fc7b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 4 19:24:31 2017 +0100 patch 8.0.1260: using global variables for WaitFor() Problem: Using global variables for WaitFor(). Solution: Use a lambda function instead. Don't check a condition if WaitFor() already checked it.
author Christian Brabandt <cb@256bit.org>
date Sat, 04 Nov 2017 19:30:06 +0100
parents 27eee6528b3d
children 87ffb7f85b28
line wrap: on
line diff
--- a/src/testdir/test_clientserver.vim
+++ b/src/testdir/test_clientserver.vim
@@ -27,12 +27,8 @@ func Test_client_server()
 
   let name = 'XVIMTEST'
   let cmd .= ' --servername ' . name
-  let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
-  call WaitFor('job_status(g:job) == "run"')
-  if job_status(g:job) != 'run'
-    call assert_report('Cannot run the Vim server')
-    return
-  endif
+  let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
+  call WaitFor({-> job_status(job) == "run"})
 
   " Takes a short while for the server to be active.
   " When using valgrind it takes much longer.
@@ -83,7 +79,7 @@ func Test_client_server()
   call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
   let peek_result = 'nothing'
   let r = remote_peek(g:myserverid, 'peek_result')
-  " unpredictable whether the result is already avaialble.
+  " unpredictable whether the result is already available.
   if r > 0
     call assert_equal('another', peek_result)
   elseif r == 0
@@ -97,11 +93,14 @@ func Test_client_server()
   call assert_equal('another', remote_read(g:myserverid, 2))
 
   call remote_send(name, ":qa!\<CR>")
-  call WaitFor('job_status(g:job) == "dead"')
-  if job_status(g:job) != 'dead'
-    call assert_report('Server did not exit')
-    call job_stop(g:job, 'kill')
-  endif
+  try
+    call WaitFor({-> job_status(job) == "dead"})
+  finally
+    if job_status(job) != 'dead'
+      call assert_report('Server did not exit')
+      call job_stop(job, 'kill')
+    endif
+  endtry
 endfunc
 
 " Uncomment this line to get a debugging log