robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 9a29622b3b00ddb601

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