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 |
| 42 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 43 | 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 Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 51 | |
| 52 | " Takes a short while for the server to be active. |
| 53 | call WaitFor('serverlist() =~ "' . name . '"') |
| 54 | call assert_match(name, serverlist()) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 55 | |
| 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 Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 61 | call remote_send(name, ":let @* = 'yes'\<CR>") |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 62 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "yes"') |
| 63 | call assert_equal('yes', remote_expr(name, "@*", "", 2)) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 64 | |
| 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 Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 81 | " Wait for the server to be up and answering requests. |
| 82 | call WaitFor('remote_expr("' . name . '", "v:version", "", 1) != ""') |
| 83 | |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 84 | call remote_send(name, ":let @* = 'maybe'\<CR>") |
Bram Moolenaar | f5610da | 2017-03-20 21:47:16 +0100 | [diff] [blame] | 85 | call WaitFor('remote_expr("' . name . '", "@*", "", 1) == "maybe"') |
| 86 | call assert_equal('maybe', remote_expr(name, "@*", "", 2)) |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 87 | |
| 88 | call assert_equal('maybe', @*) |
| 89 | endif |
| 90 | |
| 91 | call remote_send(name, ":qa!\<CR>") |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 92 | call WaitFor('job_status(g:job) == "dead"') |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 93 | 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 '' |
| 99 | endfunc |
| 100 | |
| 101 | func 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 Moolenaar | bfd830d | 2017-03-19 21:01:14 +0100 | [diff] [blame] | 117 | throw 'Skipped: ' . skipped |
Bram Moolenaar | 7dd4850 | 2017-03-19 20:04:22 +0100 | [diff] [blame] | 118 | endif |
| 119 | endfunc |