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 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 9 | func 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 '' |
| 31 | endfunc |
| 32 | |
| 33 | func 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 |
Bram Moolenaar | a2845b8 | 2017-03-25 15:20:06 +0100 | [diff] [blame] | 42 | try |
| 43 | call remote_send('xxx', '') |
| 44 | catch |
| 45 | if v:exception =~ 'E240:' |
| 46 | " No connection to the X server, give up. |
| 47 | return |
| 48 | endif |
| 49 | " ignore other errors |
| 50 | endtry |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 51 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 52 | let name = 'XVIMCLIPBOARD' |
| 53 | let cmd .= ' --servername ' . name |
| 54 | let g:job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'}) |
| 55 | call WaitFor('job_status(g:job) == "run"') |
| 56 | if job_status(g:job) != 'run' |
| 57 | call assert_report('Cannot run the Vim server') |
| 58 | return '' |
| 59 | endif |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 60 | |
| 61 | " Takes a short while for the server to be active. |
| 62 | call WaitFor('serverlist() =~ "' . name . '"') |
| 63 | call assert_match(name, serverlist()) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 64 | |
Bram Moolenaar | 4889ad7 | 2017-03-21 18:02:41 +0100 | [diff] [blame] | 65 | " Wait for the server to be up and answering requests. One second is not |
| 66 | " always sufficient. |
| 67 | call WaitFor('remote_expr("' . name . '", "v:version", "", 2) != ""') |
| 68 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 69 | " Clear the *-register of this vim instance. |
| 70 | let @* = '' |
| 71 | |
| 72 | " Try to change the *-register of the server. |
| 73 | call remote_foreground(name) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 74 | call remote_send(name, ":let @* = 'yes'\<CR>") |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 75 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"') |
| 76 | call assert_equal('yes', remote_expr(name, "@*", "", 2)) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 77 | |
| 78 | " Check that the *-register of this vim instance is changed as expected. |
| 79 | call assert_equal('yes', @*) |
| 80 | |
| 81 | if has('unix') && has('gui') && !has('gui_running') |
| 82 | let @* = '' |
| 83 | |
| 84 | " Running in a terminal and the GUI is avaiable: Tell the server to open |
| 85 | " the GUI and check that the remote command still works. |
| 86 | " Need to wait for the GUI to start up, otherwise the send hangs in trying |
| 87 | " to send to the terminal window. |
| 88 | if has('gui_athena') || has('gui_motif') |
| 89 | " For those GUIs, ignore the 'failed to create input context' error. |
| 90 | call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>") |
| 91 | else |
| 92 | call remote_send(name, ":gui -f\<CR>") |
| 93 | endif |
Bram Moolenaar | 4889ad7 | 2017-03-21 18:02:41 +0100 | [diff] [blame] | 94 | " Wait for the server in the GUI to be up and answering requests. |
| 95 | call WaitFor('remote_expr("' . name . '", "has(\"gui_running\")", "", 1) =~ "1"') |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 96 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 97 | call remote_send(name, ":let @* = 'maybe'\<CR>") |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 98 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"') |
| 99 | call assert_equal('maybe', remote_expr(name, "@*", "", 2)) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 100 | |
| 101 | call assert_equal('maybe', @*) |
| 102 | endif |
| 103 | |
| 104 | call remote_send(name, ":qa!\<CR>") |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 105 | call WaitFor('job_status(g:job) == "dead"') |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 106 | if job_status(g:job) != 'dead' |
| 107 | call assert_report('Server did not exit') |
| 108 | call job_stop(g:job, 'kill') |
| 109 | endif |
| 110 | |
| 111 | return '' |
| 112 | endfunc |
| 113 | |
| 114 | func Test_quotestar() |
| 115 | let skipped = '' |
| 116 | |
| 117 | let quotestar_saved = @* |
| 118 | |
| 119 | if has('macunix') |
| 120 | let skipped = Do_test_quotestar_for_macunix() |
Bram Moolenaar | a683ec4 | 2017-03-25 20:14:34 +0100 | [diff] [blame] | 121 | elseif has('x11') |
| 122 | if empty($DISPLAY) |
| 123 | let skipped = "Test can only run when $DISPLAY is set." |
| 124 | else |
| 125 | let skipped = Do_test_quotestar_for_x11() |
| 126 | endif |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 127 | else |
| 128 | let skipped = "Test is not implemented yet for this platform." |
| 129 | endif |
| 130 | |
| 131 | let @* = quotestar_saved |
| 132 | |
| 133 | if !empty(skipped) |
Bram Moolenaar | bfd830d | 2017-03-19 21:01:14 +0100 | [diff] [blame] | 134 | throw 'Skipped: ' . skipped |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 135 | endif |
| 136 | endfunc |