main_spec.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. local lfs = require('lfs')
  2. local helpers = require('test.functional.helpers')(after_each)
  3. local Screen = require('test.functional.ui.screen')
  4. local eq = helpers.eq
  5. local feed = helpers.feed
  6. local eval = helpers.eval
  7. local clear = helpers.clear
  8. local funcs = helpers.funcs
  9. local nvim_prog_abs = helpers.nvim_prog_abs
  10. local write_file = helpers.write_file
  11. describe('Command-line option', function()
  12. describe('-s', function()
  13. local fname = 'Xtest-functional-core-main-s'
  14. local fname_2 = fname .. '.2'
  15. local nonexistent_fname = fname .. '.nonexistent'
  16. local dollar_fname = '$' .. fname
  17. before_each(function()
  18. clear()
  19. os.remove(fname)
  20. os.remove(dollar_fname)
  21. end)
  22. after_each(function()
  23. os.remove(fname)
  24. os.remove(dollar_fname)
  25. end)
  26. it('treats - as stdin', function()
  27. eq(nil, lfs.attributes(fname))
  28. funcs.system(
  29. {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless',
  30. '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
  31. '-s', '-', fname},
  32. {':call setline(1, "42")', ':wqall!', ''})
  33. eq(0, eval('v:shell_error'))
  34. local attrs = lfs.attributes(fname)
  35. eq(#('42\n'), attrs.size)
  36. end)
  37. it('does not expand $VAR', function()
  38. eq(nil, lfs.attributes(fname))
  39. eq(true, not not dollar_fname:find('%$%w+'))
  40. write_file(dollar_fname, ':call setline(1, "100500")\n:wqall!\n')
  41. funcs.system(
  42. {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless',
  43. '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
  44. '-s', dollar_fname, fname})
  45. eq(0, eval('v:shell_error'))
  46. local attrs = lfs.attributes(fname)
  47. eq(#('100500\n'), attrs.size)
  48. end)
  49. it('does not crash after reading from stdin in non-headless mode', function()
  50. if helpers.pending_win32(pending) then return end
  51. local screen = Screen.new(40, 8)
  52. screen:attach()
  53. funcs.termopen({
  54. nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE',
  55. '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
  56. '-s', '-'
  57. })
  58. screen:expect([[
  59. ^ |
  60. {1:~ }|
  61. {1:~ }|
  62. {1:~ }|
  63. {1:~ }|
  64. {2:[No Name] 0,0-1 All}|
  65. |
  66. |
  67. ]], {
  68. [1] = {foreground = tonumber('0x4040ff'), fg_indexed=true},
  69. [2] = {bold = true, reverse = true}
  70. })
  71. feed('i:cq<CR>')
  72. screen:expect([[
  73. |
  74. [Process exited 1] |
  75. |
  76. |
  77. |
  78. |
  79. |
  80. -- TERMINAL -- |
  81. ]])
  82. --[=[ Example of incorrect output:
  83. screen:expect([[
  84. ^nvim: /var/tmp/portage/dev-libs/libuv-1.|
  85. 10.2/work/libuv-1.10.2/src/unix/core.c:5|
  86. 19: uv__close: Assertion `fd > STDERR_FI|
  87. LENO' failed. |
  88. |
  89. [Process exited 6] |
  90. |
  91. |
  92. ]])
  93. ]=]
  94. end)
  95. it('errors out when trying to use nonexistent file with -s', function()
  96. eq(
  97. 'Cannot open for reading: "'..nonexistent_fname..'": no such file or directory\n',
  98. funcs.system(
  99. {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless',
  100. '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
  101. '--cmd', 'language C',
  102. '-s', nonexistent_fname}))
  103. eq(2, eval('v:shell_error'))
  104. end)
  105. it('errors out when trying to use -s twice', function()
  106. write_file(fname, ':call setline(1, "1")\n:wqall!\n')
  107. write_file(dollar_fname, ':call setline(1, "2")\n:wqall!\n')
  108. eq(
  109. 'Attempt to open script file again: "-s '..dollar_fname..'"\n',
  110. funcs.system(
  111. {nvim_prog_abs(), '-u', 'NONE', '-i', 'NONE', '--headless',
  112. '--cmd', 'set noswapfile shortmess+=IFW fileformats=unix',
  113. '--cmd', 'language C',
  114. '-s', fname, '-s', dollar_fname, fname_2}))
  115. eq(2, eval('v:shell_error'))
  116. eq(nil, lfs.attributes(fname_2))
  117. end)
  118. end)
  119. end)