blob: d0dd04f91d8d5fc6827ef15d88b9eb5a00b1970d [file] [log] [blame]
Bram Moolenaar7dd48502017-03-19 20:04:22 +01001" *-register (quotestar) tests
2
3if !has('clipboard')
4 finish
5endif
6
7source shared.vim
8
Bram Moolenaar7dd48502017-03-19 20:04:22 +01009func Do_test_quotestar_for_macunix()
10 if empty(exepath('pbcopy')) || empty(exepath('pbpaste'))
11 return 'Test requires pbcopy(1) and pbpaste(1)'
12 endif
13
14 let @* = ''
15
16 " Test #1: Pasteboard to Vim
17 let test_msg = "text from pasteboard to vim via quotestar"
18 " Write a piece of text to the pasteboard.
19 call system('/bin/echo -n "' . test_msg . '" | pbcopy')
20 " See if the *-register is changed as expected.
21 call assert_equal(test_msg, @*)
22
23 " Test #2: Vim to Pasteboard
24 let test_msg = "text from vim to pasteboard via quotestar"
25 " Write a piece of text to the *-register.
26 let @* = test_msg
27 " See if the pasteboard is changed as expected.
28 call assert_equal(test_msg, system('pbpaste'))
29
30 return ''
31endfunc
32
33func Do_test_quotestar_for_x11()
34 if !has('clientserver') || !has('job')
35 return 'Test requires the client-server and job features'
36 endif
37
38 let cmd = GetVimCommand()
39 if cmd == ''
40 return 'GetVimCommand() failed'
41 endif
42
Bram Moolenaar7dd48502017-03-19 20:04:22 +010043 let name = 'XVIMCLIPBOARD'
44 let cmd .= ' --servername ' . name
45 let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
46 call WaitFor('job_status(g:job) == "run"')
47 if job_status(g:job) != 'run'
48 call assert_report('Cannot run the Vim server')
49 return ''
50 endif
Bram Moolenaar7dd48502017-03-19 20:04:22 +010051
52 " Takes a short while for the server to be active.
53 call WaitFor('serverlist() =~ "' . name . '"')
54 call assert_match(name, serverlist())
Bram Moolenaar7dd48502017-03-19 20:04:22 +010055
Bram Moolenaar4889ad72017-03-21 18:02:41 +010056 " Wait for the server to be up and answering requests. One second is not
57 " always sufficient.
58 call WaitFor('remote_expr("' . name . '", "v:version", "", 2) != ""')
59
Bram Moolenaar7dd48502017-03-19 20:04:22 +010060 " Clear the *-register of this vim instance.
61 let @* = ''
62
63 " Try to change the *-register of the server.
64 call remote_foreground(name)
Bram Moolenaar7dd48502017-03-19 20:04:22 +010065 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaarf5610da2017-03-20 21:47:16 +010066 call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"')
67 call assert_equal('yes', remote_expr(name, "@*", "", 2))
Bram Moolenaar7dd48502017-03-19 20:04:22 +010068
69 " Check that the *-register of this vim instance is changed as expected.
70 call assert_equal('yes', @*)
71
72 if has('unix') && has('gui') && !has('gui_running')
73 let @* = ''
74
75 " Running in a terminal and the GUI is avaiable: Tell the server to open
76 " the GUI and check that the remote command still works.
77 " Need to wait for the GUI to start up, otherwise the send hangs in trying
78 " to send to the terminal window.
79 if has('gui_athena') || has('gui_motif')
80 " For those GUIs, ignore the 'failed to create input context' error.
81 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
82 else
83 call remote_send(name, ":gui -f\<CR>")
84 endif
Bram Moolenaar4889ad72017-03-21 18:02:41 +010085 " Wait for the server in the GUI to be up and answering requests.
86 call WaitFor('remote_expr("' . name . '", "has(\"gui_running\")", "", 1) =~ "1"')
Bram Moolenaarf5610da2017-03-20 21:47:16 +010087
Bram Moolenaar7dd48502017-03-19 20:04:22 +010088 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaarf5610da2017-03-20 21:47:16 +010089 call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"')
90 call assert_equal('maybe', remote_expr(name, "@*", "", 2))
Bram Moolenaar7dd48502017-03-19 20:04:22 +010091
92 call assert_equal('maybe', @*)
93 endif
94
95 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar7dd48502017-03-19 20:04:22 +010096 call WaitFor('job_status(g:job) == "dead"')
Bram Moolenaar7dd48502017-03-19 20:04:22 +010097 if job_status(g:job) != 'dead'
98 call assert_report('Server did not exit')
99 call job_stop(g:job, 'kill')
100 endif
101
102 return ''
103endfunc
104
105func Test_quotestar()
106 let skipped = ''
107
108 let quotestar_saved = @*
109
110 if has('macunix')
111 let skipped = Do_test_quotestar_for_macunix()
112 elseif !empty("$DISPLAY")
113 let skipped = Do_test_quotestar_for_x11()
114 else
115 let skipped = "Test is not implemented yet for this platform."
116 endif
117
118 let @* = quotestar_saved
119
120 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100121 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100122 endif
123endfunc