Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 1 | " *-register (quotestar) tests |
| 2 | |
| 3 | if !has('clipboard') |
| 4 | finish |
| 5 | endif |
| 6 | |
| 7 | source shared.vim |
| 8 | |
| 9 | let s:where = 0 |
| 10 | func Abort(id) |
| 11 | call assert_report('Test timed out at ' . s:where) |
| 12 | call FinishTesting() |
| 13 | endfunc |
| 14 | |
| 15 | func Do_test_quotestar_for_macunix() |
| 16 | if empty(exepath('pbcopy')) || empty(exepath('pbpaste')) |
| 17 | return 'Test requires pbcopy(1) and pbpaste(1)' |
| 18 | endif |
| 19 | |
| 20 | let @* = '' |
| 21 | |
| 22 | " Test #1: Pasteboard to Vim |
| 23 | let test_msg = "text from pasteboard to vim via quotestar" |
| 24 | " Write a piece of text to the pasteboard. |
| 25 | call system('/bin/echo -n "' . test_msg . '" | pbcopy') |
| 26 | " See if the *-register is changed as expected. |
| 27 | call assert_equal(test_msg, @*) |
| 28 | |
| 29 | " Test #2: Vim to Pasteboard |
| 30 | let test_msg = "text from vim to pasteboard via quotestar" |
| 31 | " Write a piece of text to the *-register. |
| 32 | let @* = test_msg |
| 33 | " See if the pasteboard is changed as expected. |
| 34 | call assert_equal(test_msg, system('pbpaste')) |
| 35 | |
| 36 | return '' |
| 37 | endfunc |
| 38 | |
| 39 | func Do_test_quotestar_for_x11() |
| 40 | if !has('clientserver') || !has('job') |
| 41 | return 'Test requires the client-server and job features' |
| 42 | endif |
| 43 | |
| 44 | let cmd = GetVimCommand() |
| 45 | if cmd == '' |
| 46 | return 'GetVimCommand() failed' |
| 47 | endif |
| 48 | |
| 49 | " Some of these commands may hang when failing. |
| 50 | call timer_start(10000, 'Abort') |
| 51 | |
| 52 | let s:where = 1 |
| 53 | let name = 'XVIMCLIPBOARD' |
| 54 | let cmd .= ' --servername ' . name |
| 55 | let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) |
| 56 | call WaitFor('job_status(g:job) == "run"') |
| 57 | if job_status(g:job) != 'run' |
| 58 | call assert_report('Cannot run the Vim server') |
| 59 | return '' |
| 60 | endif |
| 61 | let s:where = 2 |
| 62 | |
| 63 | " Takes a short while for the server to be active. |
| 64 | call WaitFor('serverlist() =~ "' . name . '"') |
| 65 | call assert_match(name, serverlist()) |
| 66 | let s:where = 3 |
| 67 | |
| 68 | " Clear the *-register of this vim instance. |
| 69 | let @* = '' |
| 70 | |
| 71 | " Try to change the *-register of the server. |
| 72 | call remote_foreground(name) |
| 73 | let s:where = 4 |
| 74 | call remote_send(name, ":let @* = 'yes'\<CR>") |
| 75 | let s:where = 5 |
| 76 | call WaitFor('remote_expr("' . name . '", "@*") == "yes"') |
| 77 | let s:where = 6 |
| 78 | call assert_equal('yes', remote_expr(name, "@*")) |
| 79 | let s:where = 7 |
| 80 | |
| 81 | " Check that the *-register of this vim instance is changed as expected. |
| 82 | call assert_equal('yes', @*) |
| 83 | |
| 84 | if has('unix') && has('gui') && !has('gui_running') |
| 85 | let @* = '' |
| 86 | |
| 87 | " Running in a terminal and the GUI is avaiable: Tell the server to open |
| 88 | " the GUI and check that the remote command still works. |
| 89 | " Need to wait for the GUI to start up, otherwise the send hangs in trying |
| 90 | " to send to the terminal window. |
| 91 | if has('gui_athena') || has('gui_motif') |
| 92 | " For those GUIs, ignore the 'failed to create input context' error. |
| 93 | call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") |
| 94 | else |
| 95 | call remote_send(name, ":gui -f\<CR>") |
| 96 | endif |
| 97 | let s:where = 8 |
| 98 | sleep 500m |
| 99 | call remote_send(name, ":let @* = 'maybe'\<CR>") |
| 100 | let s:where = 9 |
| 101 | call WaitFor('remote_expr("' . name . '", "@*") == "maybe"') |
| 102 | let s:where = 10 |
| 103 | call assert_equal('maybe', remote_expr(name, "@*")) |
| 104 | let s:where = 11 |
| 105 | |
| 106 | call assert_equal('maybe', @*) |
| 107 | endif |
| 108 | |
| 109 | call remote_send(name, ":qa!\<CR>") |
| 110 | let s:where = 12 |
| 111 | call WaitFor('job_status(g:job) == "dead"') |
| 112 | let s:where = 13 |
| 113 | if job_status(g:job) != 'dead' |
| 114 | call assert_report('Server did not exit') |
| 115 | call job_stop(g:job, 'kill') |
| 116 | endif |
| 117 | |
| 118 | return '' |
| 119 | endfunc |
| 120 | |
| 121 | func Test_quotestar() |
| 122 | let skipped = '' |
| 123 | |
| 124 | let quotestar_saved = @* |
| 125 | |
| 126 | if has('macunix') |
| 127 | let skipped = Do_test_quotestar_for_macunix() |
| 128 | elseif !empty("$DISPLAY") |
| 129 | let skipped = Do_test_quotestar_for_x11() |
| 130 | else |
| 131 | let skipped = "Test is not implemented yet for this platform." |
| 132 | endif |
| 133 | |
| 134 | let @* = quotestar_saved |
| 135 | |
| 136 | if !empty(skipped) |
| 137 | throw skipped |
| 138 | endif |
| 139 | endfunc |