2017-05-10 06:04:49 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2018-02-07 02:33:05 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2016-07-14 19:11:49 -07:00
|
|
|
local child_session = require('test.functional.terminal.helpers')
|
2018-02-07 02:33:05 -07:00
|
|
|
local mkdir, write_file, rmdir = helpers.mkdir, helpers.write_file, helpers.rmdir
|
|
|
|
local eq = helpers.eq
|
|
|
|
local eval = helpers.eval
|
|
|
|
local feed = helpers.feed
|
|
|
|
local feed_command = helpers.feed_command
|
|
|
|
local iswin = helpers.iswin
|
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
2018-02-08 07:11:56 -07:00
|
|
|
local nvim_dir = helpers.nvim_dir
|
2016-08-15 16:42:12 -07:00
|
|
|
|
2016-07-14 19:11:49 -07:00
|
|
|
describe("shell command :!", function()
|
2018-02-07 02:33:05 -07:00
|
|
|
if helpers.pending_win32(pending) then return end
|
2017-05-10 06:04:49 -07:00
|
|
|
|
2016-07-14 19:11:49 -07:00
|
|
|
local screen
|
|
|
|
before_each(function()
|
2018-02-07 02:33:05 -07:00
|
|
|
clear()
|
|
|
|
screen = child_session.screen_setup(0, '["'..helpers.nvim_prog..
|
|
|
|
'", "-u", "NONE", "-i", "NONE", "--cmd", "'..helpers.nvim_set..'"]')
|
2016-07-14 19:11:49 -07:00
|
|
|
screen:expect([[
|
|
|
|
{1: } |
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2017-02-09 19:39:00 -07:00
|
|
|
{4:~ }|
|
2016-07-14 19:11:49 -07:00
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2016-07-14 19:11:49 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
2016-09-14 07:19:07 -07:00
|
|
|
child_session.feed_data("\3") -- Ctrl-C
|
2016-07-14 19:11:49 -07:00
|
|
|
screen:detach()
|
|
|
|
end)
|
|
|
|
|
2017-01-19 06:19:59 -07:00
|
|
|
it("displays output without LF/EOF. #4646 #4569 #3772", function()
|
2016-07-14 19:11:49 -07:00
|
|
|
-- NOTE: We use a child nvim (within a :term buffer)
|
|
|
|
-- to avoid triggering a UI flush.
|
|
|
|
child_session.feed_data(":!printf foo; sleep 200\n")
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2016-08-09 08:01:56 -07:00
|
|
|
{4:~ }|
|
|
|
|
{4:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{5: }|
|
2016-09-14 17:59:09 -07:00
|
|
|
:!printf foo; sleep 200 |
|
|
|
|
foo |
|
2016-08-09 08:01:56 -07:00
|
|
|
{3:-- TERMINAL --} |
|
2016-07-14 19:11:49 -07:00
|
|
|
]])
|
|
|
|
end)
|
2016-09-29 17:33:50 -07:00
|
|
|
|
2016-10-07 04:18:24 -07:00
|
|
|
it("throttles shell-command output greater than ~10KB", function()
|
2016-09-29 17:33:50 -07:00
|
|
|
child_session.feed_data(
|
2017-06-26 05:49:15 -07:00
|
|
|
":!for i in $(seq 2 30000); do echo XXXXXXXXXX $i; done\n")
|
2016-10-07 04:18:24 -07:00
|
|
|
|
|
|
|
-- If we observe any line starting with a dot, then throttling occurred.
|
2017-06-26 05:49:15 -07:00
|
|
|
-- Avoid false failure on slow systems.
|
|
|
|
screen:expect{any="\n%.", timeout=20000}
|
2016-10-07 04:18:24 -07:00
|
|
|
|
|
|
|
-- Final chunk of output should always be displayed, never skipped.
|
|
|
|
-- (Throttling is non-deterministic, this test is merely a sanity check.)
|
|
|
|
screen:expect([[
|
2017-06-26 05:49:15 -07:00
|
|
|
XXXXXXXXXX 29997 |
|
|
|
|
XXXXXXXXXX 29998 |
|
|
|
|
XXXXXXXXXX 29999 |
|
|
|
|
XXXXXXXXXX 30000 |
|
2018-01-13 02:14:41 -07:00
|
|
|
|
|
2016-10-07 04:18:24 -07:00
|
|
|
{10:Press ENTER or type command to continue}{1: } |
|
|
|
|
{3:-- TERMINAL --} |
|
|
|
|
]])
|
2016-09-29 17:33:50 -07:00
|
|
|
end)
|
2016-07-14 19:11:49 -07:00
|
|
|
end)
|
2017-05-10 06:04:49 -07:00
|
|
|
|
|
|
|
describe("shell command :!", function()
|
|
|
|
before_each(function()
|
2018-02-07 02:33:05 -07:00
|
|
|
clear()
|
2017-05-10 06:04:49 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("cat a binary file #4142", function()
|
|
|
|
feed(":exe 'silent !cat '.shellescape(v:progpath)<CR>")
|
|
|
|
eq(2, eval('1+1')) -- Still alive?
|
|
|
|
end)
|
|
|
|
|
|
|
|
it([[display \x08 char #4142]], function()
|
|
|
|
feed(":silent !echo \08<CR>")
|
|
|
|
eq(2, eval('1+1')) -- Still alive?
|
|
|
|
end)
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
it('handles control codes', function()
|
2017-05-10 06:04:49 -07:00
|
|
|
if iswin() then
|
|
|
|
pending('missing printf', function() end)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
local screen = Screen.new(50, 4)
|
|
|
|
screen:attach()
|
2018-03-31 02:12:27 -07:00
|
|
|
command("set display-=msgsep")
|
2017-05-10 06:04:49 -07:00
|
|
|
-- Print TAB chars. #2958
|
|
|
|
feed([[:!printf '1\t2\t3'<CR>]])
|
|
|
|
screen:expect([[
|
|
|
|
~ |
|
|
|
|
:!printf '1\t2\t3' |
|
|
|
|
1 2 3 |
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
feed([[<CR>]])
|
|
|
|
-- Print BELL control code. #4338
|
2018-02-07 02:23:19 -07:00
|
|
|
screen.bell = false
|
2018-06-13 20:03:37 -07:00
|
|
|
feed([[:!printf '\007\007\007\007text'<CR>]])
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2017-05-10 06:04:49 -07:00
|
|
|
~ |
|
2018-06-13 20:03:37 -07:00
|
|
|
:!printf '\007\007\007\007text' |
|
2018-02-07 02:23:19 -07:00
|
|
|
text |
|
2017-05-10 06:04:49 -07:00
|
|
|
Press ENTER or type command to continue^ |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], condition=function()
|
2018-02-07 02:23:19 -07:00
|
|
|
eq(true, screen.bell)
|
2018-08-20 09:51:25 -07:00
|
|
|
end}
|
2017-05-10 06:04:49 -07:00
|
|
|
feed([[<CR>]])
|
|
|
|
-- Print BS control code.
|
2018-06-13 20:03:37 -07:00
|
|
|
feed([[:echo system('printf ''\010\n''')<CR>]])
|
2017-05-10 06:04:49 -07:00
|
|
|
screen:expect([[
|
|
|
|
~ |
|
|
|
|
^H |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
feed([[<CR>]])
|
|
|
|
-- Print LF control code.
|
|
|
|
feed([[:!printf '\n'<CR>]])
|
|
|
|
screen:expect([[
|
|
|
|
:!printf '\n' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
feed([[<CR>]])
|
|
|
|
end)
|
2018-02-07 02:33:05 -07:00
|
|
|
|
|
|
|
describe('', function()
|
|
|
|
local screen
|
|
|
|
before_each(function()
|
|
|
|
rmdir('bang_filter_spec')
|
|
|
|
mkdir('bang_filter_spec')
|
|
|
|
write_file('bang_filter_spec/f1', 'f1')
|
|
|
|
write_file('bang_filter_spec/f2', 'f2')
|
|
|
|
write_file('bang_filter_spec/f3', 'f3')
|
|
|
|
screen = Screen.new(53,10)
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
[1] = {bold = true, foreground = Screen.colors.Blue1},
|
|
|
|
[2] = {foreground = Screen.colors.Blue1},
|
|
|
|
[3] = {bold = true, foreground = Screen.colors.SeaGreen4},
|
2018-03-31 02:12:27 -07:00
|
|
|
[4] = {bold = true, reverse = true},
|
2018-02-07 02:33:05 -07:00
|
|
|
})
|
|
|
|
screen:attach()
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
rmdir('bang_filter_spec')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("doesn't truncate Last line of shell output #3269", function()
|
2017-10-03 14:39:17 -07:00
|
|
|
command(helpers.iswin()
|
|
|
|
and [[nnoremap <silent>\l :!dir /b bang_filter_spec<cr>]]
|
|
|
|
or [[nnoremap <silent>\l :!ls bang_filter_spec<cr>]])
|
|
|
|
local result = (helpers.iswin()
|
|
|
|
and [[:!dir /b bang_filter_spec]]
|
|
|
|
or [[:!ls bang_filter_spec ]])
|
2018-02-07 02:33:05 -07:00
|
|
|
feed([[\l]])
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2018-02-07 02:33:05 -07:00
|
|
|
{1:~ }|
|
|
|
|
{1:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{4: }|
|
2017-10-03 14:39:17 -07:00
|
|
|
]]..result..[[ |
|
2018-02-07 02:33:05 -07:00
|
|
|
f1 |
|
|
|
|
f2 |
|
|
|
|
f3 |
|
|
|
|
|
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('handles binary and multibyte data', function()
|
|
|
|
feed_command('!cat test/functional/fixtures/shell_data.txt')
|
|
|
|
screen.bell = false
|
2018-08-20 09:51:25 -07:00
|
|
|
screen:expect{grid=[[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
2018-02-07 02:33:05 -07:00
|
|
|
{1:~ }|
|
2018-03-31 02:12:27 -07:00
|
|
|
{4: }|
|
2018-02-07 02:33:05 -07:00
|
|
|
:!cat test/functional/fixtures/shell_data.txt |
|
|
|
|
{2:^@^A^B^C^D^E^F^H} |
|
|
|
|
{2:^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_} |
|
|
|
|
ö 한글 {2:<a5><c3>} |
|
|
|
|
t {2:<ff>} |
|
|
|
|
|
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
2018-08-20 09:51:25 -07:00
|
|
|
]], condition=function()
|
2018-02-07 02:33:05 -07:00
|
|
|
eq(true, screen.bell)
|
2018-08-20 09:51:25 -07:00
|
|
|
end}
|
2018-02-07 02:33:05 -07:00
|
|
|
end)
|
2018-02-08 07:11:56 -07:00
|
|
|
|
|
|
|
it('handles multibyte sequences split over buffer boundaries', function()
|
|
|
|
command('cd '..nvim_dir)
|
|
|
|
local cmd
|
|
|
|
if iswin() then
|
|
|
|
cmd = '!shell-test UTF-8 '
|
|
|
|
else
|
|
|
|
cmd = '!./shell-test UTF-8'
|
|
|
|
end
|
|
|
|
feed_command(cmd)
|
|
|
|
-- Note: only the first example of split composed char works
|
|
|
|
screen:expect([[
|
2018-03-31 02:12:27 -07:00
|
|
|
|
|
|
|
|
{4: }|
|
2018-02-08 07:11:56 -07:00
|
|
|
:]]..cmd..[[ |
|
|
|
|
å |
|
|
|
|
ref: å̲ |
|
|
|
|
1: å̲ |
|
|
|
|
2: å ̲ |
|
|
|
|
3: å ̲ |
|
|
|
|
|
|
|
|
|
{3:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
|
|
|
end)
|
2018-02-07 02:33:05 -07:00
|
|
|
end)
|
2017-05-10 06:04:49 -07:00
|
|
|
end)
|