1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
local t = require('test.testutil')
local n = require('test.functional.testnvim')()
local Screen = require('test.functional.ui.screen')
local tt = require('test.functional.testterm')
local assert_alive = n.assert_alive
local mkdir, write_file, rmdir = t.mkdir, t.write_file, n.rmdir
local eq = t.eq
local feed = n.feed
local feed_command = n.feed_command
local clear = n.clear
local command = n.command
local testprg = n.testprg
local nvim_dir = n.nvim_dir
local has_powershell = n.has_powershell
local set_shell_powershell = n.set_shell_powershell
local skip = t.skip
local is_os = t.is_os
clear() -- for has_powershell()
describe('shell command :!', function()
local screen
before_each(function()
clear()
screen = tt.setup_child_nvim({
'-u',
'NONE',
'-i',
'NONE',
'--cmd',
'colorscheme vim',
'--cmd',
n.nvim_set .. ' notermguicolors',
})
screen:expect([[
^ |
{4:~ }|*4
|
{3:-- TERMINAL --} |
]])
end)
after_each(function()
tt.feed_data('\3') -- Ctrl-C
end)
it('displays output without LF/EOF. #4646 #4569 #3772', function()
skip(is_os('win'))
-- NOTE: We use a child nvim (within a :term buffer)
-- to avoid triggering a UI flush.
tt.feed_data(':!printf foo; sleep 200\n')
screen:expect([[
|
{4:~ }|*2
{5: }|
:!printf foo; sleep 200 |
foo |
{3:-- TERMINAL --} |
]])
end)
it('throttles shell-command output greater than ~10KB', function()
skip(is_os('openbsd'), 'FIXME #10804')
skip(is_os('win'))
tt.feed_data((':!%s REP 30001 foo\n'):format(testprg('shell-test')))
-- If we observe any line starting with a dot, then throttling occurred.
-- Avoid false failure on slow systems.
screen:expect { any = '\n%.', timeout = 20000 }
-- Final chunk of output should always be displayed, never skipped.
-- (Throttling is non-deterministic, this test is merely a sanity check.)
screen:expect(
[[
29997: foo |
29998: foo |
29999: foo |
30000: foo |
|
{10:Press ENTER or type command to continue}^ |
{3:-- TERMINAL --} |
]],
{
-- test/functional/testnvim.lua defaults to background=light.
[1] = { reverse = true },
[3] = { bold = true },
[10] = { foreground = 2 },
}
)
end)
end)
describe('shell command :!', function()
before_each(function()
clear()
end)
it('cat a binary file #4142', function()
feed(":exe 'silent !cat '.shellescape(v:progpath)<CR>")
assert_alive()
end)
it([[display \x08 char #4142]], function()
feed(':silent !echo \08<CR>')
assert_alive()
end)
it('handles control codes', function()
skip(is_os('win'), 'missing printf')
local screen = Screen.new(50, 4)
-- Print TAB chars. #2958
feed([[:!printf '1\t2\t3'<CR>]])
screen:expect {
grid = [[
{3: }|
:!printf '1\t2\t3' |
1 2 3 |
{6:Press ENTER or type command to continue}^ |
]],
}
feed([[<CR>]])
-- Print BELL control code. #4338
screen.bell = false
feed([[:!printf '\007\007\007\007text'<CR>]])
screen:expect {
grid = [[
{3: }|
:!printf '\007\007\007\007text' |
text |
{6:Press ENTER or type command to continue}^ |
]],
condition = function()
eq(true, screen.bell)
end,
}
feed([[<CR>]])
-- Print BS control code.
feed([[:echo system('printf ''\010\n''')<CR>]])
screen:expect([[
{3: }|
{18:^H} |
|
{6:Press ENTER or type command to continue}^ |
]])
feed([[<CR>]])
-- Print LF control code.
feed([[:!printf '\n'<CR>]])
screen:expect([[
:!printf '\n' |
|*2
{6:Press ENTER or type command to continue}^ |
]])
feed([[<CR>]])
end)
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)
end)
after_each(function()
rmdir('bang_filter_spec')
end)
it("doesn't truncate Last line of shell output #3269", function()
command(
is_os('win') and [[nnoremap <silent>\l :!dir /b bang_filter_spec<cr>]]
or [[nnoremap <silent>\l :!ls bang_filter_spec<cr>]]
)
local result = (
is_os('win') and [[:!dir /b bang_filter_spec]] or [[:!ls bang_filter_spec ]]
)
feed([[\l]])
screen:expect([[
|
{1:~ }|*2
{3: }|
]] .. result .. [[ |
f1 |
f2 |
f3 |
|
{6: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
screen:expect {
grid = [[
|
{1:~ }|
{3: }|
:!cat test/functional/fixtures/shell_data.txt |
{18:^@^A^B^C^D^E^F^H} |
{18:^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_} |
ö 한글 {18:<a5><c3>} |
t {18:<ff>} |
|
{6:Press ENTER or type command to continue}^ |
]],
condition = function()
eq(true, screen.bell)
end,
}
end)
it('handles multibyte sequences split over buffer boundaries', function()
command('cd ' .. nvim_dir)
local cmd = is_os('win') and '!shell-test UTF-8 ' or '!./shell-test UTF-8'
feed_command(cmd)
-- Note: only the first example of split composed char works
screen:expect([[
|
{3: }|
:]] .. cmd .. [[ |
å |
ref: å̲ |
1: å̲ |
2: å ̲ |
3: å ̲ |
|
{6:Press ENTER or type command to continue}^ |
]])
end)
end)
if has_powershell() then
it('powershell supports literal strings', function()
set_shell_powershell()
local screen = Screen.new(45, 4)
feed_command([[!'Write-Output $a']])
screen:expect([[
:!'Write-Output $a' |
Write-Output $a |
|
{6:Press ENTER or type command to continue}^ |
]])
feed_command([[!$a = 1; Write-Output '$a']])
screen:expect([[
:!$a = 1; Write-Output '$a' |
$a |
|
{6:Press ENTER or type command to continue}^ |
]])
feed_command([[!"Write-Output $a"]])
screen:expect([[
:!"Write-Output $a" |
Write-Output |
|
{6:Press ENTER or type command to continue}^ |
]])
feed_command([[!$a = 1; Write-Output "$a"]])
screen:expect([[
:!$a = 1; Write-Output "$a" |
1 |
|
{6:Press ENTER or type command to continue}^ |
]])
if is_os('win') then
feed_command([[!& 'cmd.exe' /c 'echo $a']])
screen:expect([[
:!& 'cmd.exe' /c 'echo $a' |
$a |
|
{6:Press ENTER or type command to continue}^ |
]])
else
feed_command([[!& '/bin/sh' -c 'echo ''$a''']])
screen:expect([[
:!& '/bin/sh' -c 'echo ''$a''' |
$a |
|
{6:Press ENTER or type command to continue}^ |
]])
end
end)
end
end)
|