script_spec.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local eq = t.eq
  4. local neq = t.neq
  5. local command = n.command
  6. local exec_capture = n.exec_capture
  7. local write_file = t.write_file
  8. local api = n.api
  9. local clear = n.clear
  10. local dedent = t.dedent
  11. local exc_exec = n.exc_exec
  12. local missing_provider = n.missing_provider
  13. local tmpfile = 'X_ex_cmds_script'
  14. before_each(clear)
  15. local function source(code)
  16. write_file(tmpfile, code)
  17. command('source ' .. tmpfile)
  18. end
  19. describe('script_get-based command', function()
  20. local garbage = ')}{+*({}]*[;(+}{&[]}{*])('
  21. after_each(function()
  22. os.remove(tmpfile)
  23. end)
  24. local function test_garbage_exec(cmd, check_neq)
  25. describe(cmd, function()
  26. it('works correctly when skipping oneline variant', function()
  27. eq(
  28. true,
  29. pcall(
  30. source,
  31. (dedent([[
  32. if 0
  33. %s %s
  34. endif
  35. ]])):format(cmd, garbage)
  36. )
  37. )
  38. eq('', exec_capture('messages'))
  39. if check_neq then
  40. neq(
  41. 0,
  42. exc_exec(dedent([[
  43. %s %s
  44. ]])):format(cmd, garbage)
  45. )
  46. end
  47. end)
  48. it('works correctly when skipping HEREdoc variant', function()
  49. eq(
  50. true,
  51. pcall(
  52. source,
  53. (dedent([[
  54. if 0
  55. %s << EOF
  56. %s
  57. EOF
  58. endif
  59. ]])):format(cmd, garbage)
  60. )
  61. )
  62. eq('', exec_capture('messages'))
  63. if check_neq then
  64. eq(
  65. true,
  66. pcall(
  67. source,
  68. (dedent([[
  69. let g:exc = 0
  70. try
  71. %s << EOF
  72. %s
  73. EOF
  74. catch
  75. let g:exc = v:exception
  76. endtry
  77. ]])):format(cmd, garbage)
  78. )
  79. )
  80. neq(0, api.nvim_get_var('exc'))
  81. end
  82. end)
  83. end)
  84. end
  85. clear()
  86. -- Built-in scripts
  87. test_garbage_exec('lua', true)
  88. -- Provider-based scripts
  89. test_garbage_exec('ruby', not missing_provider('ruby'))
  90. test_garbage_exec('python3', not missing_provider('python'))
  91. -- Missing scripts
  92. test_garbage_exec('python', false)
  93. test_garbage_exec('tcl', false)
  94. test_garbage_exec('mzscheme', false)
  95. test_garbage_exec('perl', false)
  96. -- Not really a script
  97. test_garbage_exec('xxxinvalidlanguagexxx', true)
  98. end)