2018-05-19 19:16:50 -07:00
|
|
|
" *-register (quotestar) tests
|
|
|
|
|
|
|
|
source shared.vim
|
2022-07-07 17:26:25 -07:00
|
|
|
source check.vim
|
|
|
|
|
|
|
|
CheckFeature clipboard_working
|
2018-05-19 19:16:50 -07:00
|
|
|
|
|
|
|
func Do_test_quotestar_for_macunix()
|
|
|
|
if empty(exepath('pbcopy')) || empty(exepath('pbpaste'))
|
|
|
|
return 'Test requires pbcopy(1) and pbpaste(1)'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let @* = ''
|
|
|
|
|
|
|
|
" Test #1: Pasteboard to Vim
|
|
|
|
let test_msg = "text from pasteboard to vim via quotestar"
|
|
|
|
" Write a piece of text to the pasteboard.
|
|
|
|
call system('/bin/echo -n "' . test_msg . '" | pbcopy')
|
|
|
|
" See if the *-register is changed as expected.
|
|
|
|
call assert_equal(test_msg, @*)
|
|
|
|
|
|
|
|
" Test #2: Vim to Pasteboard
|
|
|
|
let test_msg = "text from vim to pasteboard via quotestar"
|
|
|
|
" Write a piece of text to the *-register.
|
|
|
|
let @* = test_msg
|
|
|
|
" See if the pasteboard is changed as expected.
|
|
|
|
call assert_equal(test_msg, system('pbpaste'))
|
|
|
|
|
|
|
|
return ''
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Do_test_quotestar_for_x11()
|
|
|
|
if !has('clientserver') || !has('job')
|
|
|
|
return 'Test requires the client-server and job features'
|
|
|
|
endif
|
|
|
|
|
|
|
|
let cmd = GetVimCommand()
|
|
|
|
if cmd == ''
|
|
|
|
return 'GetVimCommand() failed'
|
|
|
|
endif
|
2018-05-29 17:40:40 -07:00
|
|
|
try
|
|
|
|
call remote_send('xxx', '')
|
|
|
|
catch
|
|
|
|
if v:exception =~ 'E240:'
|
|
|
|
" No connection to the X server, give up.
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
" ignore other errors
|
|
|
|
endtry
|
2018-05-19 19:16:50 -07:00
|
|
|
|
|
|
|
let name = 'XVIMCLIPBOARD'
|
2018-06-21 02:27:24 -07:00
|
|
|
|
|
|
|
" Make sure a previous server has exited
|
|
|
|
try
|
|
|
|
call remote_send(name, ":qa!\<CR>")
|
|
|
|
catch /E241:/
|
|
|
|
endtry
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_notmatch(name, serverlist())})
|
2018-06-21 02:27:24 -07:00
|
|
|
|
2018-05-19 19:16:50 -07:00
|
|
|
let cmd .= ' --servername ' . name
|
2019-09-01 08:30:33 -07:00
|
|
|
let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal("run", job_status(job))})
|
2018-05-19 19:16:50 -07:00
|
|
|
|
|
|
|
" Takes a short while for the server to be active.
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_match(name, serverlist())})
|
2018-05-19 19:16:50 -07:00
|
|
|
|
2018-05-19 19:30:43 -07:00
|
|
|
" Wait for the server to be up and answering requests. One second is not
|
|
|
|
" always sufficient.
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))})
|
2018-05-19 19:30:43 -07:00
|
|
|
|
2018-06-21 02:27:24 -07:00
|
|
|
" Clear the *-register of this vim instance and wait for it to be picked up
|
|
|
|
" by the server.
|
|
|
|
let @* = 'no'
|
2018-05-19 19:16:50 -07:00
|
|
|
call remote_foreground(name)
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))})
|
2018-06-21 02:27:24 -07:00
|
|
|
|
|
|
|
" Set the * register on the server.
|
2018-05-19 19:16:50 -07:00
|
|
|
call remote_send(name, ":let @* = 'yes'\<CR>")
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))})
|
2018-05-19 19:16:50 -07:00
|
|
|
|
|
|
|
" Check that the *-register of this vim instance is changed as expected.
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal("yes", @*)})
|
2018-05-19 19:16:50 -07:00
|
|
|
|
2018-11-19 19:52:38 -07:00
|
|
|
" Handle the large selection over 262040 byte.
|
|
|
|
let length = 262044
|
|
|
|
let sample = 'a' . repeat('b', length - 2) . 'c'
|
|
|
|
let @* = sample
|
2019-09-02 08:59:10 -07:00
|
|
|
call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)')
|
2018-11-19 19:52:38 -07:00
|
|
|
let res = remote_expr(name, "@*", "", 2)
|
|
|
|
call assert_equal(length, len(res))
|
|
|
|
" Check length to prevent a large amount of output at assertion failure.
|
|
|
|
if length == len(res)
|
|
|
|
call assert_equal(sample, res)
|
|
|
|
endif
|
|
|
|
|
2018-05-19 19:16:50 -07:00
|
|
|
if has('unix') && has('gui') && !has('gui_running')
|
|
|
|
let @* = ''
|
|
|
|
|
2021-03-30 03:43:10 -07:00
|
|
|
" Running in a terminal and the GUI is available: Tell the server to open
|
2018-05-19 19:16:50 -07:00
|
|
|
" the GUI and check that the remote command still works.
|
2022-09-21 22:20:41 -07:00
|
|
|
if has('gui_motif')
|
2018-05-19 19:16:50 -07:00
|
|
|
" For those GUIs, ignore the 'failed to create input context' error.
|
|
|
|
call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
|
|
|
|
else
|
|
|
|
call remote_send(name, ":gui -f\<CR>")
|
|
|
|
endif
|
2018-05-19 19:30:43 -07:00
|
|
|
" Wait for the server in the GUI to be up and answering requests.
|
2022-08-21 18:48:11 -07:00
|
|
|
" First need to wait for the GUI to start up, otherwise the send hangs in
|
|
|
|
" trying to send to the terminal window.
|
2020-03-26 16:29:20 -07:00
|
|
|
" On some systems and with valgrind this can be very slow.
|
2022-08-21 18:48:11 -07:00
|
|
|
sleep 1
|
2020-03-26 16:29:20 -07:00
|
|
|
call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}, 10000)
|
2018-05-19 19:27:03 -07:00
|
|
|
|
2018-05-19 19:16:50 -07:00
|
|
|
call remote_send(name, ":let @* = 'maybe'\<CR>")
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))})
|
2018-05-19 19:16:50 -07:00
|
|
|
|
|
|
|
call assert_equal('maybe', @*)
|
|
|
|
endif
|
|
|
|
|
|
|
|
call remote_send(name, ":qa!\<CR>")
|
2019-09-01 08:30:33 -07:00
|
|
|
try
|
2019-09-20 16:19:46 -07:00
|
|
|
call WaitForAssert({-> assert_equal("dead", job_status(job))})
|
2019-09-01 08:30:33 -07:00
|
|
|
finally
|
|
|
|
if job_status(job) != 'dead'
|
|
|
|
call assert_report('Server did not exit')
|
|
|
|
call job_stop(job, 'kill')
|
|
|
|
endif
|
|
|
|
endtry
|
2018-05-19 19:16:50 -07:00
|
|
|
|
|
|
|
return ''
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_quotestar()
|
2023-08-21 00:30:20 -07:00
|
|
|
let g:test_is_flaky = 1
|
2018-05-19 19:16:50 -07:00
|
|
|
let skipped = ''
|
|
|
|
|
|
|
|
let quotestar_saved = @*
|
|
|
|
|
|
|
|
if has('macunix')
|
|
|
|
let skipped = Do_test_quotestar_for_macunix()
|
2018-05-29 18:01:19 -07:00
|
|
|
elseif has('x11')
|
|
|
|
if empty($DISPLAY)
|
|
|
|
let skipped = "Test can only run when $DISPLAY is set."
|
|
|
|
else
|
|
|
|
let skipped = Do_test_quotestar_for_x11()
|
|
|
|
endif
|
2018-05-19 19:16:50 -07:00
|
|
|
else
|
|
|
|
let skipped = "Test is not implemented yet for this platform."
|
|
|
|
endif
|
|
|
|
|
|
|
|
let @* = quotestar_saved
|
|
|
|
|
|
|
|
if !empty(skipped)
|
2018-05-19 19:21:32 -07:00
|
|
|
throw 'Skipped: ' . skipped
|
2018-05-19 19:16:50 -07:00
|
|
|
endif
|
|
|
|
endfunc
|