diff src/testdir/test_channel.vim @ 8041:c6443e78cf2d v7.4.1315

commit https://github.com/vim/vim/commit/7707344ddec9069b495b2a5ed41f2104466fc88b Author: Bram Moolenaar <Bram@vim.org> Date: Sat Feb 13 23:23:53 2016 +0100 patch 7.4.1315 Problem: Using a channel handle does not allow for freeing it when unused. Solution: Add the Channel variable type.
author Christian Brabandt <cb@256bit.org>
date Sat, 13 Feb 2016 23:30:05 +0100
parents 9dea1571b352
children 9f9b74579bdc
line wrap: on
line diff
--- a/src/testdir/test_channel.vim
+++ b/src/testdir/test_channel.vim
@@ -83,7 +83,6 @@ func s:kill_server()
   endif
 endfunc
 
-let s:responseHandle = -1
 let s:responseMsg = ''
 func s:RequestHandler(handle, msg)
   let s:responseHandle = a:handle
@@ -92,7 +91,7 @@ endfunc
 
 func s:communicate(port)
   let handle = ch_open('localhost:' . a:port, s:chopt)
-  if handle < 0
+  if ch_status(handle) == "fail"
     call assert_false(1, "Can't open channel")
     return
   endif
@@ -115,14 +114,22 @@ func s:communicate(port)
   " Send a request with a specific handler.
   call ch_sendexpr(handle, 'hello!', 's:RequestHandler')
   sleep 10m
-  call assert_equal(handle, s:responseHandle)
+  if !exists('s:responseHandle')
+    call assert_false(1, 's:responseHandle was not set')
+  else
+    call assert_equal(handle, s:responseHandle)
+  endif
   call assert_equal('got it', s:responseMsg)
 
-  let s:responseHandle = -1
+  unlet s:responseHandle
   let s:responseMsg = ''
   call ch_sendexpr(handle, 'hello!', function('s:RequestHandler'))
   sleep 10m
-  call assert_equal(handle, s:responseHandle)
+  if !exists('s:responseHandle')
+    call assert_false(1, 's:responseHandle was not set')
+  else
+    call assert_equal(handle, s:responseHandle)
+  endif
   call assert_equal('got it', s:responseMsg)
 
   " Send an eval request that works.
@@ -169,7 +176,7 @@ endfunc
 " Test that we can open two channels.
 func s:two_channels(port)
   let handle = ch_open('localhost:' . a:port, s:chopt)
-  if handle < 0
+  if ch_status(handle) == "fail"
     call assert_false(1, "Can't open channel")
     return
   endif
@@ -177,7 +184,7 @@ func s:two_channels(port)
   call assert_equal('got it', ch_sendexpr(handle, 'hello!'))
 
   let newhandle = ch_open('localhost:' . a:port, s:chopt)
-  if newhandle < 0
+  if ch_status(newhandle) == "fail"
     call assert_false(1, "Can't open second channel")
     return
   endif
@@ -197,7 +204,7 @@ endfunc
 " Test that a server crash is handled gracefully.
 func s:server_crash(port)
   let handle = ch_open('localhost:' . a:port, s:chopt)
-  if handle < 0
+  if ch_status(handle) == "fail"
     call assert_false(1, "Can't open channel")
     return
   endif
@@ -219,7 +226,7 @@ endfunc
 
 func s:channel_handler(port)
   let handle = ch_open('localhost:' . a:port, s:chopt)
-  if handle < 0
+  if ch_status(handle) == "fail"
     call assert_false(1, "Can't open channel")
     return
   endif
@@ -247,7 +254,7 @@ endfunc
 func Test_connect_waittime()
   let start = reltime()
   let handle = ch_open('localhost:9876', s:chopt)
-  if handle >= 0
+  if ch_status(handle) == "fail"
     " Oops, port does exists.
     call ch_close(handle)
   else
@@ -257,7 +264,7 @@ func Test_connect_waittime()
 
   let start = reltime()
   let handle = ch_open('localhost:9867', {'waittime': 2000})
-  if handle >= 0
+  if ch_status(handle) != "fail"
     " Oops, port does exists.
     call ch_close(handle)
   else