blob: 7ccee43a53374d335eeea522392fd3622874a357 [file] [log] [blame]
Bram Moolenaar7dd48502017-03-19 20:04:22 +01001" *-register (quotestar) tests
2
Bram Moolenaar52992fe2019-08-12 14:20:33 +02003CheckFeature clipboard_working
Bram Moolenaar7dd48502017-03-19 20:04:22 +01004
Bram Moolenaar7dd48502017-03-19 20:04:22 +01005func Do_test_quotestar_for_macunix()
6 if empty(exepath('pbcopy')) || empty(exepath('pbpaste'))
7 return 'Test requires pbcopy(1) and pbpaste(1)'
8 endif
9
10 let @* = ''
11
12 " Test #1: Pasteboard to Vim
13 let test_msg = "text from pasteboard to vim via quotestar"
14 " Write a piece of text to the pasteboard.
15 call system('/bin/echo -n "' . test_msg . '" | pbcopy')
16 " See if the *-register is changed as expected.
17 call assert_equal(test_msg, @*)
18
19 " Test #2: Vim to Pasteboard
20 let test_msg = "text from vim to pasteboard via quotestar"
21 " Write a piece of text to the *-register.
22 let @* = test_msg
23 " See if the pasteboard is changed as expected.
24 call assert_equal(test_msg, system('pbpaste'))
25
26 return ''
27endfunc
28
29func Do_test_quotestar_for_x11()
30 if !has('clientserver') || !has('job')
31 return 'Test requires the client-server and job features'
32 endif
33
34 let cmd = GetVimCommand()
35 if cmd == ''
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020036 throw 'GetVimCommand() failed'
Bram Moolenaar7dd48502017-03-19 20:04:22 +010037 endif
Bram Moolenaara2845b82017-03-25 15:20:06 +010038 try
39 call remote_send('xxx', '')
40 catch
41 if v:exception =~ 'E240:'
42 " No connection to the X server, give up.
43 return
44 endif
45 " ignore other errors
46 endtry
Bram Moolenaar7dd48502017-03-19 20:04:22 +010047
Bram Moolenaar7dd48502017-03-19 20:04:22 +010048 let name = 'XVIMCLIPBOARD'
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020049
50 " Make sure a previous server has exited
51 try
52 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020053 catch /E241:/
54 endtry
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020055 call WaitForAssert({-> assert_notmatch(name, serverlist())})
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020056
Bram Moolenaar7dd48502017-03-19 20:04:22 +010057 let cmd .= ' --servername ' . name
Bram Moolenaarab8b1c12017-11-04 19:24:31 +010058 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020059 call WaitForAssert({-> assert_equal("run", job_status(job))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010060
61 " Takes a short while for the server to be active.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020062 call WaitForAssert({-> assert_match(name, serverlist())})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010063
Bram Moolenaar4889ad72017-03-21 18:02:41 +010064 " Wait for the server to be up and answering requests. One second is not
65 " always sufficient.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020066 call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))})
Bram Moolenaar4889ad72017-03-21 18:02:41 +010067
Bram Moolenaar791010e2018-02-24 17:42:28 +010068 " Clear the *-register of this vim instance and wait for it to be picked up
69 " by the server.
70 let @* = 'no'
Bram Moolenaar7dd48502017-03-19 20:04:22 +010071 call remote_foreground(name)
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020072 call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))})
Bram Moolenaar791010e2018-02-24 17:42:28 +010073
74 " Set the * register on the server.
Bram Moolenaar7dd48502017-03-19 20:04:22 +010075 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020076 call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010077
78 " Check that the *-register of this vim instance is changed as expected.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020079 call WaitForAssert({-> assert_equal("yes", @*)})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010080
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020081 " Handle the large selection over 262040 byte.
82 let length = 262044
83 let sample = 'a' . repeat('b', length - 2) . 'c'
84 let @* = sample
Bram Moolenaar769e9d22018-04-11 20:53:49 +020085 call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)')
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020086 let res = remote_expr(name, "@*", "", 2)
87 call assert_equal(length, len(res))
88 " Check length to prevent a large amount of output at assertion failure.
89 if length == len(res)
90 call assert_equal(sample, res)
91 endif
92
Bram Moolenaar7dd48502017-03-19 20:04:22 +010093 if has('unix') && has('gui') && !has('gui_running')
94 let @* = ''
95
Bram Moolenaar037c54f2019-04-20 23:47:46 +020096 " Running in a terminal and the GUI is available: Tell the server to open
Bram Moolenaar7dd48502017-03-19 20:04:22 +010097 " the GUI and check that the remote command still works.
Bram Moolenaar0b962e52022-04-03 18:02:37 +010098 if has('gui_motif')
Bram Moolenaar7dd48502017-03-19 20:04:22 +010099 " For those GUIs, ignore the 'failed to create input context' error.
100 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
101 else
102 call remote_send(name, ":gui -f\<CR>")
103 endif
Bram Moolenaar4889ad72017-03-21 18:02:41 +0100104 " Wait for the server in the GUI to be up and answering requests.
Bram Moolenaar18dc3552020-11-22 14:24:00 +0100105 " First need to wait for the GUI to start up, otherwise the send hangs in
106 " trying to send to the terminal window.
Bram Moolenaar26bde6e2020-03-26 21:11:58 +0100107 " On some systems and with valgrind this can be very slow.
Bram Moolenaar18dc3552020-11-22 14:24:00 +0100108 sleep 1
Bram Moolenaar26bde6e2020-03-26 21:11:58 +0100109 call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}, 10000)
Bram Moolenaarf5610da2017-03-20 21:47:16 +0100110
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100111 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200112 call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100113
114 call assert_equal('maybe', @*)
115 endif
116
117 call remote_send(name, ":qa!\<CR>")
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100118 try
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200119 call WaitForAssert({-> assert_equal("dead", job_status(job))})
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100120 finally
121 if job_status(job) != 'dead'
122 call assert_report('Server did not exit')
123 call job_stop(job, 'kill')
124 endif
125 endtry
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100126
127 return ''
128endfunc
129
130func Test_quotestar()
Bram Moolenaarf08b0eb2021-10-16 13:00:14 +0100131 let g:test_is_flaky = 1
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100132 let skipped = ''
133
134 let quotestar_saved = @*
135
136 if has('macunix')
137 let skipped = Do_test_quotestar_for_macunix()
Bram Moolenaara683ec42017-03-25 20:14:34 +0100138 elseif has('x11')
lilydjwg6e0a18f2024-01-29 20:54:28 +0100139 if empty($DISPLAY) || !empty($WAYLAND_DISPLAY)
140 let skipped = "Test can only run when $DISPLAY is set and $WAYLAND_DISPLAY is not set."
Bram Moolenaara683ec42017-03-25 20:14:34 +0100141 else
142 let skipped = Do_test_quotestar_for_x11()
143 endif
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100144 else
145 let skipped = "Test is not implemented yet for this platform."
146 endif
147
148 let @* = quotestar_saved
149
150 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100151 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100152 endif
153endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200154
155" vim: shiftwidth=2 sts=2 expandtab