blob: 5212b9bc62c71fefdf2ecf815f926c1c4511a3ce [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
56 " Clear the *-register of this vim instance.
57 let @* = ''
58
59 " Try to change the *-register of the server.
60 call remote_foreground(name)
Bram Moolenaar7dd48502017-03-19 20:04:22 +010061 call remote_send(name, ":let @* = 'yes'\<CR>")
Bram Moolenaarf5610da2017-03-20 21:47:16 +010062 call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"')
63 call assert_equal('yes', remote_expr(name, "@*", "", 2))
Bram Moolenaar7dd48502017-03-19 20:04:22 +010064
65 " Check that the *-register of this vim instance is changed as expected.
66 call assert_equal('yes', @*)
67
68 if has('unix') && has('gui') && !has('gui_running')
69 let @* = ''
70
71 " Running in a terminal and the GUI is avaiable: Tell the server to open
72 " the GUI and check that the remote command still works.
73 " Need to wait for the GUI to start up, otherwise the send hangs in trying
74 " to send to the terminal window.
75 if has('gui_athena') || has('gui_motif')
76 " For those GUIs, ignore the 'failed to create input context' error.
77 call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
78 else
79 call remote_send(name, ":gui -f\<CR>")
80 endif
Bram Moolenaarf5610da2017-03-20 21:47:16 +010081 " Wait for the server to be up and answering requests.
82 call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""')
83
Bram Moolenaar7dd48502017-03-19 20:04:22 +010084 call remote_send(name, ":let @* = 'maybe'\<CR>")
Bram Moolenaarf5610da2017-03-20 21:47:16 +010085 call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"')
86 call assert_equal('maybe', remote_expr(name, "@*", "", 2))
Bram Moolenaar7dd48502017-03-19 20:04:22 +010087
88 call assert_equal('maybe', @*)
89 endif
90
91 call remote_send(name, ":qa!\<CR>")
Bram Moolenaar7dd48502017-03-19 20:04:22 +010092 call WaitFor('job_status(g:job) == "dead"')
Bram Moolenaar7dd48502017-03-19 20:04:22 +010093 if job_status(g:job) != 'dead'
94 call assert_report('Server did not exit')
95 call job_stop(g:job, 'kill')
96 endif
97
98 return ''
99endfunc
100
101func Test_quotestar()
102 let skipped = ''
103
104 let quotestar_saved = @*
105
106 if has('macunix')
107 let skipped = Do_test_quotestar_for_macunix()
108 elseif !empty("$DISPLAY")
109 let skipped = Do_test_quotestar_for_x11()
110 else
111 let skipped = "Test is not implemented yet for this platform."
112 endif
113
114 let @* = quotestar_saved
115
116 if !empty(skipped)
Bram Moolenaarbfd830d2017-03-19 21:01:14 +0100117 throw 'Skipped: ' . skipped
Bram Moolenaar7dd48502017-03-19 20:04:22 +0100118 endif
119endfunc