2017-10-31 07:28:16 -05:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
|
|
|
local eq = helpers.eq
|
|
|
|
local funcs = helpers.funcs
|
|
|
|
local nvim_prog = helpers.nvim_prog
|
|
|
|
local nvim_set = helpers.nvim_set
|
|
|
|
local read_file = helpers.read_file
|
|
|
|
local retry = helpers.retry
|
2017-12-02 20:38:58 -06:00
|
|
|
local sleep = helpers.sleep
|
2017-11-02 05:10:25 -05:00
|
|
|
local iswin = helpers.iswin
|
2017-10-31 07:28:16 -05:00
|
|
|
|
|
|
|
describe('startup', function()
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2017-12-02 20:38:58 -06:00
|
|
|
os.remove('Xtest_startup_ttyout')
|
2017-10-31 07:28:16 -05:00
|
|
|
end)
|
|
|
|
after_each(function()
|
|
|
|
os.remove('Xtest_startup_ttyout')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('pipe at both ends: has("ttyin")==0 has("ttyout")==0', function()
|
|
|
|
-- system() puts a pipe at both ends.
|
|
|
|
local out = funcs.system({ nvim_prog, '-u', 'NONE', '-i', 'NONE', '--headless',
|
|
|
|
'--cmd', nvim_set,
|
|
|
|
'-c', [[echo has('ttyin') has('ttyout')]],
|
|
|
|
'+q' })
|
|
|
|
eq('0 0', out)
|
|
|
|
end)
|
|
|
|
it('with --embed: has("ttyin")==0 has("ttyout")==0', function()
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
-- Remote UI connected by --embed.
|
|
|
|
screen:attach()
|
|
|
|
command([[echo has('ttyin') has('ttyout')]])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
~ |
|
|
|
|
0 0 |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('in a TTY: has("ttyin")==1 has("ttyout")==1', function()
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
screen:attach()
|
2017-11-02 05:10:25 -05:00
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2017-10-31 07:28:16 -05:00
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]]
|
2017-12-02 20:38:58 -06:00
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"echo has('ttyin') has('ttyout')\""]]
|
2017-10-31 07:28:16 -05:00
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
1 1 |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('output to pipe: has("ttyin")==1 has("ttyout")==0', function()
|
2017-11-02 05:10:25 -05:00
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
2017-10-31 07:28:16 -05:00
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal %s -u NONE -i NONE --cmd \"]]
|
2017-12-02 20:38:58 -06:00
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]]
|
|
|
|
..[[ -c q | cat -v"]] -- Output to a pipe.
|
2017-10-31 07:28:16 -05:00
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
retry(nil, 3000, function()
|
2017-12-02 20:38:58 -06:00
|
|
|
sleep(1)
|
2017-10-31 07:28:16 -05:00
|
|
|
eq('1\n0\n', -- stdin is a TTY, stdout is a pipe
|
|
|
|
read_file('Xtest_startup_ttyout'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
it('input from pipe: has("ttyin")==0 has("ttyout")==1', function()
|
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal echo foo | ]] -- Input from a pipe.
|
|
|
|
..[[%s -u NONE -i NONE --cmd \"]]
|
2017-12-02 20:38:58 -06:00
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"call writefile([has('ttyin'), has('ttyout')], 'Xtest_startup_ttyout')\"]]
|
|
|
|
..[[ -c q -- -"]]
|
2017-10-31 07:28:16 -05:00
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
retry(nil, 3000, function()
|
2017-12-02 20:38:58 -06:00
|
|
|
sleep(1)
|
2017-10-31 07:28:16 -05:00
|
|
|
eq('0\n1\n', -- stdin is a pipe, stdout is a TTY
|
|
|
|
read_file('Xtest_startup_ttyout'))
|
|
|
|
end)
|
|
|
|
end)
|
2017-12-02 20:38:58 -06:00
|
|
|
it('input from pipe (implicit) #7679', function()
|
|
|
|
local screen = Screen.new(25, 3)
|
|
|
|
screen:attach()
|
|
|
|
if iswin() then
|
|
|
|
command([[set shellcmdflag=/s\ /c shellxquote=\"]])
|
|
|
|
end
|
|
|
|
-- Running in :terminal
|
|
|
|
command([[exe printf("terminal echo foo | ]] -- Input from a pipe.
|
|
|
|
..[[%s -u NONE -i NONE --cmd \"]]
|
|
|
|
..nvim_set..[[\"]]
|
|
|
|
..[[ -c \"echo has('ttyin') has('ttyout')\""]]
|
|
|
|
..[[, shellescape(v:progpath))]])
|
|
|
|
screen:expect([[
|
|
|
|
^foo |
|
|
|
|
0 1 |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2018-05-29 00:22:15 -05:00
|
|
|
it('input from pipe + file args #7679', function()
|
2018-05-28 00:09:55 -05:00
|
|
|
eq('ohyeah\r\n0 0 bufs=3',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '--headless',
|
|
|
|
'+.print',
|
|
|
|
"+echo has('ttyin') has('ttyout') 'bufs='.bufnr('$')",
|
|
|
|
'+qall!',
|
|
|
|
'-',
|
|
|
|
'test/functional/fixtures/tty-test.c',
|
|
|
|
'test/functional/fixtures/shell-test.c',
|
|
|
|
},
|
|
|
|
{ 'ohyeah', '' }))
|
2017-12-02 20:38:58 -06:00
|
|
|
end)
|
2018-05-26 20:41:02 -05:00
|
|
|
|
2018-05-29 00:22:15 -05:00
|
|
|
it('stdin with -es/-Es #7679', function()
|
2018-05-26 20:41:02 -05:00
|
|
|
local input = { 'append', 'line1', 'line2', '.', '%print', '' }
|
|
|
|
local inputstr = table.concat(input, '\n')
|
|
|
|
|
|
|
|
--
|
|
|
|
-- -Es: read stdin as text
|
|
|
|
--
|
|
|
|
eq('partylikeits1999\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-Es', '+.print', 'test/functional/fixtures/tty-test.c' },
|
2018-05-28 00:09:55 -05:00
|
|
|
{ 'partylikeits1999', '' }))
|
2018-05-26 20:41:02 -05:00
|
|
|
eq(inputstr,
|
|
|
|
funcs.system({nvim_prog, '-i', 'NONE', '-Es', '+%print', '-' },
|
|
|
|
input))
|
|
|
|
|
|
|
|
--
|
|
|
|
-- -es: read stdin as ex-commands
|
|
|
|
--
|
|
|
|
eq(' encoding=utf-8\n',
|
|
|
|
funcs.system({nvim_prog, '-n', '-u', 'NONE', '-i', 'NONE', '-es', 'test/functional/fixtures/tty-test.c' },
|
|
|
|
{ 'set encoding', '' }))
|
|
|
|
eq('line1\nline2\n',
|
|
|
|
funcs.system({nvim_prog, '-i', 'NONE', '-es', '-' },
|
|
|
|
input))
|
|
|
|
end)
|
2017-10-31 07:28:16 -05:00
|
|
|
end)
|
|
|
|
|