test_quotestar.vim 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. " *-register (quotestar) tests
  2. source shared.vim
  3. source check.vim
  4. CheckFeature clipboard_working
  5. func Do_test_quotestar_for_macunix()
  6. if empty(exepath('pbcopy')) || empty(exepath('pbpaste'))
  7. return 'Test requires pbcopy(1) and pbpaste(1)'
  8. endif
  9. let @* = ''
  10. " Test #1: Pasteboard to Vim
  11. let test_msg = "text from pasteboard to vim via quotestar"
  12. " Write a piece of text to the pasteboard.
  13. call system('/bin/echo -n "' . test_msg . '" | pbcopy')
  14. " See if the *-register is changed as expected.
  15. call assert_equal(test_msg, @*)
  16. " Test #2: Vim to Pasteboard
  17. let test_msg = "text from vim to pasteboard via quotestar"
  18. " Write a piece of text to the *-register.
  19. let @* = test_msg
  20. " See if the pasteboard is changed as expected.
  21. call assert_equal(test_msg, system('pbpaste'))
  22. return ''
  23. endfunc
  24. func Do_test_quotestar_for_x11()
  25. if !has('clientserver') || !has('job')
  26. return 'Test requires the client-server and job features'
  27. endif
  28. let cmd = GetVimCommand()
  29. if cmd == ''
  30. return 'GetVimCommand() failed'
  31. endif
  32. try
  33. call remote_send('xxx', '')
  34. catch
  35. if v:exception =~ 'E240:'
  36. " No connection to the X server, give up.
  37. return
  38. endif
  39. " ignore other errors
  40. endtry
  41. let name = 'XVIMCLIPBOARD'
  42. " Make sure a previous server has exited
  43. try
  44. call remote_send(name, ":qa!\<CR>")
  45. catch /E241:/
  46. endtry
  47. call WaitForAssert({-> assert_notmatch(name, serverlist())})
  48. let cmd .= ' --servername ' . name
  49. let job = job_start(cmd, {'stoponexit': 'kill', 'out_io': 'null'})
  50. call WaitForAssert({-> assert_equal("run", job_status(job))})
  51. " Takes a short while for the server to be active.
  52. call WaitForAssert({-> assert_match(name, serverlist())})
  53. " Wait for the server to be up and answering requests. One second is not
  54. " always sufficient.
  55. call WaitForAssert({-> assert_notequal('', remote_expr(name, "v:version", "", 2))})
  56. " Clear the *-register of this vim instance and wait for it to be picked up
  57. " by the server.
  58. let @* = 'no'
  59. call remote_foreground(name)
  60. call WaitForAssert({-> assert_equal("no", remote_expr(name, "@*", "", 1))})
  61. " Set the * register on the server.
  62. call remote_send(name, ":let @* = 'yes'\<CR>")
  63. call WaitForAssert({-> assert_equal("yes", remote_expr(name, "@*", "", 1))})
  64. " Check that the *-register of this vim instance is changed as expected.
  65. call WaitForAssert({-> assert_equal("yes", @*)})
  66. " Handle the large selection over 262040 byte.
  67. let length = 262044
  68. let sample = 'a' . repeat('b', length - 2) . 'c'
  69. let @* = sample
  70. call WaitFor('remote_expr("' . name . '", "len(@*) >= ' . length . '", "", 1)')
  71. let res = remote_expr(name, "@*", "", 2)
  72. call assert_equal(length, len(res))
  73. " Check length to prevent a large amount of output at assertion failure.
  74. if length == len(res)
  75. call assert_equal(sample, res)
  76. endif
  77. if has('unix') && has('gui') && !has('gui_running')
  78. let @* = ''
  79. " Running in a terminal and the GUI is available: Tell the server to open
  80. " the GUI and check that the remote command still works.
  81. if has('gui_motif')
  82. " For those GUIs, ignore the 'failed to create input context' error.
  83. call remote_send(name, ":call test_ignore_error('E285') | gui -f\<CR>")
  84. else
  85. call remote_send(name, ":gui -f\<CR>")
  86. endif
  87. " Wait for the server in the GUI to be up and answering requests.
  88. " First need to wait for the GUI to start up, otherwise the send hangs in
  89. " trying to send to the terminal window.
  90. " On some systems and with valgrind this can be very slow.
  91. sleep 1
  92. call WaitForAssert({-> assert_match("1", remote_expr(name, "has('gui_running')", "", 1))}, 10000)
  93. call remote_send(name, ":let @* = 'maybe'\<CR>")
  94. call WaitForAssert({-> assert_equal("maybe", remote_expr(name, "@*", "", 2))})
  95. call assert_equal('maybe', @*)
  96. endif
  97. call remote_send(name, ":qa!\<CR>")
  98. try
  99. call WaitForAssert({-> assert_equal("dead", job_status(job))})
  100. finally
  101. if job_status(job) != 'dead'
  102. call assert_report('Server did not exit')
  103. call job_stop(job, 'kill')
  104. endif
  105. endtry
  106. return ''
  107. endfunc
  108. func Test_quotestar()
  109. let g:test_is_flaky = 1
  110. let skipped = ''
  111. let quotestar_saved = @*
  112. if has('macunix')
  113. let skipped = Do_test_quotestar_for_macunix()
  114. elseif has('x11')
  115. if empty($DISPLAY)
  116. let skipped = "Test can only run when $DISPLAY is set."
  117. else
  118. let skipped = Do_test_quotestar_for_x11()
  119. endif
  120. else
  121. let skipped = "Test is not implemented yet for this platform."
  122. endif
  123. let @* = quotestar_saved
  124. if !empty(skipped)
  125. throw 'Skipped: ' . skipped
  126. endif
  127. endfunc