blob: 6b8aebfff7fcaadcbbb73aba67193c528a2bf893 [file] [log] [blame]
Bram Moolenaar7dd48502017-03-19 20:04:22 +01001" *-register (quotestar) tests
2
Bram Moolenaar564344a2019-04-28 13:00:12 +02003source shared.vim
Bram Moolenaar52992fe2019-08-12 14:20:33 +02004source check.vim
Bram Moolenaar7dd48502017-03-19 20:04:22 +01005
Bram Moolenaar52992fe2019-08-12 14:20:33 +02006CheckFeature clipboard_working
Bram Moolenaar7dd48502017-03-19 20:04:22 +01007
Bram Moolenaar7dd48502017-03-19 20:04:22 +01008func Do_test_quotestar_for_macunix()
9 if empty(exepath('pbcopy')) || empty(exepath('pbpaste'))
10 return 'Test requires pbcopy(1) and pbpaste(1)'
11 endif
12
13 let @* = ''
14
15 " Test #1: Pasteboard to Vim
16 let test_msg = "text from pasteboard to vim via quotestar"
17 " Write a piece of text to the pasteboard.
18 call system('/bin/echo -n "' . test_msg . '" | pbcopy')
19 " See if the *-register is changed as expected.
20 call assert_equal(test_msg, @*)
21
22 " Test #2: Vim to Pasteboard
23 let test_msg = "text from vim to pasteboard via quotestar"
24 " Write a piece of text to the *-register.
25 let @* = test_msg
26 " See if the pasteboard is changed as expected.
27 call assert_equal(test_msg, system('pbpaste'))
28
29 return ''
30endfunc
31
32func Do_test_quotestar_for_x11()
33 if !has('clientserver') || !has('job')
34 return 'Test requires the client-server and job features'
35 endif
36
37 let cmd = GetVimCommand()
38 if cmd == ''
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +020039 throw 'GetVimCommand() failed'
Bram Moolenaar7dd48502017-03-19 20:04:22 +010040 endif
Bram Moolenaara2845b82017-03-25 15:20:06 +010041 try
42 call remote_send('xxx', '')
43 catch
44 if v:exception =~ 'E240:'
45 " No connection to the X server, give up.
46 return
47 endif
48 " ignore other errors
49 endtry
Bram Moolenaar7dd48502017-03-19 20:04:22 +010050
Bram Moolenaar7dd48502017-03-19 20:04:22 +010051 let name = 'XVIMCLIPBOARD'
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020052
53 " Make sure a previous server has exited
54 try
55 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020056 catch /E241:/
57 endtry
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020058 call WaitForAssert({-> assert_notmatch(name, serverlist())})
Bram Moolenaar1c13c0f2017-06-10 16:30:32 +020059
Bram Moolenaar7dd48502017-03-19 20:04:22 +010060 let cmd .= ' --servername ' . name
Bram Moolenaarab8b1c12017-11-04 19:24:31 +010061 let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020062 call WaitForAssert({-> assert_equal("run", job_status(job))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010063
64 " Takes a short while for the server to be active.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020065 call WaitForAssert({-> assert_match(name, serverlist())})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010066
Bram Moolenaar4889ad72017-03-21 18:02:41 +010067 " Wait for the server to be up and answering requests. One second is not
68 " always sufficient.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020069 call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))})
Bram Moolenaar4889ad72017-03-21 18:02:41 +010070
Bram Moolenaar791010e2018-02-24 17:42:28 +010071 " Clear the *-register of this vim instance and wait for it to be picked up
72 " by the server.
73 let @* = 'no'
Bram Moolenaar7dd48502017-03-19 20:04:22 +010074 call remote_foreground(name)
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020075 call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))})
Bram Moolenaar791010e2018-02-24 17:42:28 +010076
77 " Set the * register on the server.
Bram Moolenaar7dd48502017-03-19 20:04:22 +010078 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020079 call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010080
81 " Check that the *-register of this vim instance is changed as expected.
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +020082 call WaitForAssert({-> assert_equal("yes", @*)})
Bram Moolenaar7dd48502017-03-19 20:04:22 +010083
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020084 " Handle the large selection over 262040 byte.
85 let length = 262044
86 let sample = 'a' . repeat('b', length - 2) . 'c'
87 let @* = sample
Bram Moolenaar769e9d22018-04-11 20:53:49 +020088 call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)')
Bram Moolenaarcdb7e1b2017-07-19 19:55:58 +020089 let res = remote_expr(name, "@*", "", 2)
90 call assert_equal(length, len(res))
91 " Check length to prevent a large amount of output at assertion failure.
92 if length == len(res)
93 call assert_equal(sample, res)
94 endif
95
Bram Moolenaar7dd48502017-03-19 20:04:22 +010096 if has('unix') && has('gui') && !has('gui_running')
97 let @* = ''
98
Bram Moolenaar037c54f2019-04-20 23:47:46 +020099 " Running in a terminal and the GUI is available: Tell the server to open
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100100 " the GUI and check that the remote command still works.
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100101 if has('gui_athena') || has('gui_motif')
102 " For those GUIs, ignore the 'failed to create input context' error.
103 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
104 else
105 call remote_send(name, ":gui -f\<CR>")
106 endif
Bram Moolenaar4889ad72017-03-21 18:02:41 +0100107 " Wait for the server in the GUI to be up and answering requests.
Bram Moolenaar18dc3552020-11-22 14:24:00 +0100108 " First need to wait for the GUI to start up, otherwise the send hangs in
109 " trying to send to the terminal window.
Bram Moolenaar26bde6e2020-03-26 21:11:58 +0100110 " On some systems and with valgrind this can be very slow.
Bram Moolenaar18dc3552020-11-22 14:24:00 +0100111 sleep 1
Bram Moolenaar26bde6e2020-03-26 21:11:58 +0100112 call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}, 10000)
Bram Moolenaarf5610da2017-03-20 21:47:16 +0100113
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100114 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200115 call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))})
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100116
117 call assert_equal('maybe', @*)
118 endif
119
120 call remote_send(name, ":qa!\<CR>")
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100121 try
Bram Moolenaar0e9d1ae2018-04-30 14:28:24 +0200122 call WaitForAssert({-> assert_equal("dead", job_status(job))})
Bram Moolenaarab8b1c12017-11-04 19:24:31 +0100123 finally
124 if job_status(job) != 'dead'
125 call assert_report('Server did not exit')
126 call job_stop(job, 'kill')
127 endif
128 endtry
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100129
130 return ''
131endfunc
132
133func Test_quotestar()
134 let skipped = ''
135
136 let quotestar_saved = @*
137
138 if has('macunix')
139 let skipped = Do_test_quotestar_for_macunix()
Bram Moolenaara683ec42017-03-25 20:14:34 +0100140 elseif has('x11')
141 if empty($DISPLAY)
142 let skipped = "Test can only run when $DISPLAY is set."
143 else
144 let skipped = Do_test_quotestar_for_x11()
145 endif
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100146 else
147 let skipped = "Test is not implemented yet for this platform."
148 endif
149
150 let @* = quotestar_saved
151
152 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100153 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100154 endif
155endfunc
Bram Moolenaar6d91bcb2020-08-12 18:50:36 +0200156
157" vim: shiftwidth=2 sts=2 expandtab