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')
|
2021-09-01 09:42:53 -07:00
|
|
|
local assert_alive = helpers.assert_alive
|
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 feed = helpers.feed
|
|
|
|
local feed_command = helpers.feed_command
|
|
|
|
local iswin = helpers.iswin
|
|
|
|
local clear = helpers.clear
|
|
|
|
local command = helpers.command
|
2022-06-22 05:51:52 -07:00
|
|
|
local testprg = helpers.testprg
|
2018-02-08 07:11:56 -07:00
|
|
|
local nvim_dir = helpers.nvim_dir
|
2019-12-31 12:21:57 -07:00
|
|
|
local has_powershell = helpers.has_powershell
|
2019-10-10 01:16:02 -07:00
|
|
|
local set_shell_powershell = helpers.set_shell_powershell
|
2022-11-13 06:52:19 -07:00
|
|
|
local skip = helpers.skip
|
2016-08-15 16:42:12 -07:00
|
|
|
|
2016-07-14 19:11:49 -07:00
|
|
|
describe("shell command :!", function()
|
|
|
|
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
|
|
|
end)
|
|
|
|
|
2017-01-19 06:19:59 -07:00
|
|
|
it("displays output without LF/EOF. #4646 #4569 #3772", function()
|
2022-11-13 06:52:19 -07:00
|
|
|
skip(iswin())
|
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()
|
2022-11-13 06:52:19 -07:00
|
|
|
skip('openbsd' == helpers.uname(), 'FIXME #10804')
|
2022-06-22 05:51:52 -07:00
|
|
|
child_session.feed_data((":!%s REP 30001 foo\n"):format(testprg('shell-test')))
|
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([[
|
2019-08-08 07:02:28 -07:00
|
|
|
29997: foo |
|
|
|
|
29998: foo |
|
|
|
|
29999: foo |
|
|
|
|
30000: foo |
|
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 --} |
|
2018-11-20 02:52:49 -07:00
|
|
|
]], {
|
|
|
|
-- test/functional/helpers.lua defaults to background=light.
|
|
|
|
[1] = {reverse = true},
|
|
|
|
[3] = {bold = true},
|
|
|
|
[10] = {foreground = 2},
|
|
|
|
})
|
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>")
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2017-05-10 06:04:49 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it([[display \x08 char #4142]], function()
|
|
|
|
feed(":silent !echo \08<CR>")
|
2021-09-01 09:42:53 -07:00
|
|
|
assert_alive()
|
2017-05-10 06:04:49 -07:00
|
|
|
end)
|
|
|
|
|
2018-08-20 09:51:25 -07:00
|
|
|
it('handles control codes', function()
|
2022-11-13 06:52:19 -07:00
|
|
|
skip(iswin(), 'missing printf')
|
2017-05-10 06:04:49 -07:00
|
|
|
local screen = Screen.new(50, 4)
|
2022-08-17 07:19:35 -07:00
|
|
|
screen:set_default_attr_ids {
|
|
|
|
[1] = {bold = true, reverse = true};
|
|
|
|
[2] = {bold = true, foreground = Screen.colors.SeaGreen};
|
|
|
|
[3] = {foreground = Screen.colors.Blue};
|
|
|
|
}
|
2017-05-10 06:04:49 -07:00
|
|
|
screen:attach()
|
|
|
|
-- Print TAB chars. #2958
|
|
|
|
feed([[:!printf '1\t2\t3'<CR>]])
|
2022-08-17 07:19:35 -07:00
|
|
|
screen:expect{grid=[[
|
|
|
|
{1: }|
|
2017-05-10 06:04:49 -07:00
|
|
|
:!printf '1\t2\t3' |
|
|
|
|
1 2 3 |
|
2022-08-17 07:19:35 -07:00
|
|
|
{2:Press ENTER or type command to continue}^ |
|
|
|
|
]]}
|
2017-05-10 06:04:49 -07:00
|
|
|
feed([[<CR>]])
|
2022-08-17 07:19:35 -07:00
|
|
|
|
2017-05-10 06:04:49 -07:00
|
|
|
-- 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=[[
|
2022-08-17 07:19:35 -07:00
|
|
|
{1: }|
|
2018-06-13 20:03:37 -07:00
|
|
|
:!printf '\007\007\007\007text' |
|
2018-02-07 02:23:19 -07:00
|
|
|
text |
|
2022-08-17 07:19:35 -07:00
|
|
|
{2: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>]])
|
2022-08-17 07:19:35 -07:00
|
|
|
|
2017-05-10 06:04:49 -07:00
|
|
|
-- 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([[
|
2022-08-17 07:19:35 -07:00
|
|
|
{1: }|
|
|
|
|
{3:^H} |
|
2017-05-10 06:04:49 -07:00
|
|
|
|
|
2022-08-17 07:19:35 -07:00
|
|
|
{2:Press ENTER or type command to continue}^ |
|
2017-05-10 06:04:49 -07:00
|
|
|
]])
|
|
|
|
feed([[<CR>]])
|
2022-08-17 07:19:35 -07:00
|
|
|
|
2017-05-10 06:04:49 -07:00
|
|
|
-- Print LF control code.
|
|
|
|
feed([[:!printf '\n'<CR>]])
|
|
|
|
screen:expect([[
|
|
|
|
:!printf '\n' |
|
|
|
|
|
|
|
|
|
|
|
2022-08-17 07:19:35 -07:00
|
|
|
{2:Press ENTER or type command to continue}^ |
|
2017-05-10 06:04:49 -07:00
|
|
|
]])
|
|
|
|
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)
|
2022-06-22 05:51:52 -07:00
|
|
|
local cmd = iswin() and '!shell-test UTF-8 ' or '!./shell-test UTF-8'
|
2018-02-08 07:11:56 -07:00
|
|
|
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)
|
2019-12-31 12:21:57 -07:00
|
|
|
if has_powershell() then
|
2019-10-10 01:16:02 -07:00
|
|
|
it('powershell supports literal strings', function()
|
|
|
|
set_shell_powershell()
|
2020-11-19 21:12:01 -07:00
|
|
|
local screen = Screen.new(45, 4)
|
2019-10-10 01:16:02 -07:00
|
|
|
screen:attach()
|
2019-10-10 21:30:20 -07:00
|
|
|
feed_command([[!'Write-Output $a']])
|
2020-11-19 21:12:01 -07:00
|
|
|
screen:expect([[
|
|
|
|
:!'Write-Output $a' |
|
|
|
|
Write-Output $a |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
2019-10-10 21:30:20 -07:00
|
|
|
feed_command([[!$a = 1; Write-Output '$a']])
|
2020-11-19 21:12:01 -07:00
|
|
|
screen:expect([[
|
|
|
|
:!$a = 1; Write-Output '$a' |
|
|
|
|
$a |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
2019-10-10 21:30:20 -07:00
|
|
|
feed_command([[!"Write-Output $a"]])
|
2020-11-19 21:12:01 -07:00
|
|
|
screen:expect([[
|
|
|
|
:!"Write-Output $a" |
|
|
|
|
Write-Output |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
2019-10-10 21:30:20 -07:00
|
|
|
feed_command([[!$a = 1; Write-Output "$a"]])
|
2020-11-19 21:12:01 -07:00
|
|
|
screen:expect([[
|
|
|
|
:!$a = 1; Write-Output "$a" |
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
if iswin() then
|
|
|
|
feed_command([[!& 'cmd.exe' /c 'echo $a']])
|
|
|
|
screen:expect([[
|
|
|
|
:!& 'cmd.exe' /c 'echo $a' |
|
|
|
|
$a |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
else
|
|
|
|
feed_command([[!& '/bin/sh' -c 'echo ''$a''']])
|
|
|
|
screen:expect([[
|
|
|
|
:!& '/bin/sh' -c 'echo ''$a''' |
|
|
|
|
$a |
|
|
|
|
|
|
|
|
|
Press ENTER or type command to continue^ |
|
|
|
|
]])
|
|
|
|
end
|
2019-10-10 01:16:02 -07:00
|
|
|
end)
|
|
|
|
end
|
2017-05-10 06:04:49 -07:00
|
|
|
end)
|