aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/system_spec.lua
blob: ed822add725358c4eb524248a99229bc2c49deaa (plain) (blame)
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
local helpers = require('test.functional.helpers')(after_each)

local assert_alive = helpers.assert_alive
local testprg = helpers.testprg
local eq, call, clear, eval, feed_command, feed, nvim =
  helpers.eq, helpers.call, helpers.clear, helpers.eval, helpers.feed_command,
  helpers.feed, helpers.nvim
local command = helpers.command
local insert = helpers.insert
local expect = helpers.expect
local exc_exec = helpers.exc_exec
local iswin = helpers.iswin
local os_kill = helpers.os_kill
local pcall_err = helpers.pcall_err

local Screen = require('test.functional.ui.screen')

local function create_file_with_nuls(name)
  return function()
    feed('ipart1<C-V>000part2<C-V>000part3<ESC>:w '..name..'<CR>')
    eval('1')  -- wait for the file to be created
  end
end

local function delete_file(name)
  return function()
    eval("delete('"..name.."')")
  end
end

describe('system()', function()
  before_each(clear)

  describe('command passed as a List', function()
    it('throws error if cmd[0] is not executable', function()
      eq("Vim:E475: Invalid value for argument cmd: 'this-should-not-exist' is not executable",
        pcall_err(call, 'system', { 'this-should-not-exist' }))
      eq(-1, eval('v:shell_error'))
    end)

    it('parameter validation does NOT modify v:shell_error', function()
      -- 1. Call system() with invalid parameters.
      -- 2. Assert that v:shell_error was NOT set.
      feed_command('call system({})')
      eq('E475: Invalid argument: expected String or List', eval('v:errmsg'))
      eq(0, eval('v:shell_error'))
      feed_command('call system([])')
      eq('E474: Invalid argument', eval('v:errmsg'))
      eq(0, eval('v:shell_error'))

      -- Provoke a non-zero v:shell_error.
      eq("Vim:E475: Invalid value for argument cmd: 'this-should-not-exist' is not executable",
        pcall_err(call, 'system', { 'this-should-not-exist' }))
      local old_val = eval('v:shell_error')
      eq(-1, old_val)

      -- 1. Call system() with invalid parameters.
      -- 2. Assert that v:shell_error was NOT modified.
      feed_command('call system({})')
      eq(old_val, eval('v:shell_error'))
      feed_command('call system([])')
      eq(old_val, eval('v:shell_error'))
    end)

    it('quotes arguments correctly #5280', function()
      local out = call('system',
        { testprg('printargs-test'), [[1]], [[2 "3]], [[4 ' 5]], [[6 ' 7']] })

      eq(0, eval('v:shell_error'))
      eq([[arg1=1;arg2=2 "3;arg3=4 ' 5;arg4=6 ' 7';]], out)

      out = call('system', { testprg('printargs-test'), [['1]], [[2 "3]] })
      eq(0, eval('v:shell_error'))
      eq([[arg1='1;arg2=2 "3;]], out)

      out = call('system', { testprg('printargs-test'), "A\nB" })
      eq(0, eval('v:shell_error'))
      eq("arg1=A\nB;", out)
    end)

    it('calls executable in $PATH', function()
      if 0 == eval("executable('python3')") then pending("missing `python3`") end
      eq("foo\n", eval([[system(['python3', '-c', 'print("foo")'])]]))
      eq(0, eval('v:shell_error'))
    end)

    it('does NOT run in shell', function()
      if iswin() then
        eq("%PATH%\n", eval("system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'Write-Output', '%PATH%'])"))
      else
        eq("* $PATH %PATH%\n", eval("system(['echo', '*', '$PATH', '%PATH%'])"))
      end
    end)
  end)

  it('sets v:shell_error', function()
    if iswin() then
      eval([[system("cmd.exe /c exit")]])
      eq(0, eval('v:shell_error'))
      eval([[system("cmd.exe /c exit 1")]])
      eq(1, eval('v:shell_error'))
      eval([[system("cmd.exe /c exit 5")]])
      eq(5, eval('v:shell_error'))
      eval([[system('this-should-not-exist')]])
      eq(1, eval('v:shell_error'))
    else
      eval([[system("sh -c 'exit'")]])
      eq(0, eval('v:shell_error'))
      eval([[system("sh -c 'exit 1'")]])
      eq(1, eval('v:shell_error'))
      eval([[system("sh -c 'exit 5'")]])
      eq(5, eval('v:shell_error'))
      eval([[system('this-should-not-exist')]])
      eq(127, eval('v:shell_error'))
    end
  end)

  describe('executes shell function', function()
    local screen

    before_each(function()
      screen = Screen.new()
      screen:attach()
    end)

    if iswin() then
      local function test_more()
        eq('root = true', eval([[get(split(system('"more" ".editorconfig"'), "\n"), 0, '')]]))
      end
      local function test_shell_unquoting()
        eval([[system('"ping" "-n" "1" "127.0.0.1"')]])
        eq(0, eval('v:shell_error'))
        eq('"a b"\n', eval([[system('cmd /s/c "cmd /s/c "cmd /s/c "echo "a b""""')]]))
        eq('"a b"\n', eval([[system('powershell -NoProfile -NoLogo -ExecutionPolicy RemoteSigned -Command Write-Output ''\^"a b\^"''')]]))
      end

      it('with shell=cmd.exe', function()
        command('set shell=cmd.exe')
        eq('""\n', eval([[system('echo ""')]]))
        eq('"a b"\n', eval([[system('echo "a b"')]]))
        eq('a \nb\n', eval([[system('echo a & echo b')]]))
        eq('a \n', eval([[system('echo a 2>&1')]]))
        test_more()
        eval([[system('cd "C:\Program Files"')]])
        eq(0, eval('v:shell_error'))
        test_shell_unquoting()
      end)

      it('with shell=cmd', function()
        command('set shell=cmd')
        eq('"a b"\n', eval([[system('echo "a b"')]]))
        test_more()
        test_shell_unquoting()
      end)

      it('with shell=$COMSPEC', function()
        local comspecshell = eval("fnamemodify($COMSPEC, ':t')")
        if comspecshell == 'cmd.exe' then
          command('set shell=$COMSPEC')
          eq('"a b"\n', eval([[system('echo "a b"')]]))
          test_more()
          test_shell_unquoting()
        else
          pending('$COMSPEC is not cmd.exe: ' .. comspecshell)
        end
      end)

      it('with powershell', function()
        helpers.set_shell_powershell()
        eq('a\nb\n', eval([[system('Write-Output a b')]]))
        eq('C:\\\n', eval([[system('cd c:\; (Get-Location).Path')]]))
        eq('a b\n', eval([[system('Write-Output "a b"')]]))
      end)
    end

    it('powershell w/ UTF-8 text #13713', function()
      if not helpers.has_powershell() then
        pending("powershell not found", function() end)
        return
      end
      helpers.set_shell_powershell()
      eq('ああ\n', eval([[system('Write-Output "ああ"')]]))
      -- Sanity test w/ default encoding
      -- * on Windows, expected to default to Western European enc
      -- * on Linux, expected to default to UTF8
      command([[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']])
      eq(iswin() and '??\n' or 'ああ\n', eval([[system('Write-Output "ああ"')]]))
    end)

    it('`echo` and waits for its return', function()
      feed(':call system("echo")<cr>')
      screen:expect([[
        ^                                                     |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        :call system("echo")                                 |
      ]])
    end)

    it('prints verbose information', function()
      nvim('set_option', 'shell', 'fake_shell')
      nvim('set_option', 'shellcmdflag', 'cmdflag')

      screen:try_resize(72, 14)
      feed(':4verbose echo system("echo hi")<cr>')
      if iswin() then
        screen:expect{any=[[Executing command: "'fake_shell' 'cmdflag' '"echo hi"'"]]}
      else
        screen:expect{any=[[Executing command: "'fake_shell' 'cmdflag' 'echo hi'"]]}
      end
      feed('<cr>')
    end)

    it('self and total time recorded separately', function()
      local tempfile = helpers.tmpname()

      feed(':function! AlmostNoSelfTime()<cr>')
      feed('echo system("echo hi")<cr>')
      feed('endfunction<cr>')

      feed(':profile start ' .. tempfile .. '<cr>')
      feed(':profile func AlmostNoSelfTime<cr>')
      feed(':call AlmostNoSelfTime()<cr>')
      feed(':profile dump<cr>')

      feed(':edit ' .. tempfile .. '<cr>')

      local command_total_time = tonumber(helpers.funcs.split(helpers.funcs.getline(7))[2])
      local command_self_time = tonumber(helpers.funcs.split(helpers.funcs.getline(7))[3])

      helpers.neq(nil, command_total_time)
      helpers.neq(nil, command_self_time)
    end)

    it('`yes` interrupted with CTRL-C', function()
      feed(':call system("' .. (iswin()
        and 'for /L %I in (1,0,2) do @echo y'
        or  'yes') .. '")<cr>')
      screen:expect([[
                                                             |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
]] .. (iswin()
        and [[
        :call system("for /L %I in (1,0,2) do @echo y")      |]]
        or  [[
        :call system("yes")                                  |]]))
      feed('foo<c-c>')
      screen:expect([[
        ^                                                     |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        Type  :qa  and press <Enter> to exit Nvim            |
      ]])
    end)

    it('`yes` interrupted with mapped CTRL-C', function()
      command('nnoremap <C-C> i')
      feed(':call system("' .. (iswin()
        and 'for /L %I in (1,0,2) do @echo y'
        or  'yes') .. '")<cr>')
      screen:expect([[
                                                             |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
]] .. (iswin()
        and [[
        :call system("for /L %I in (1,0,2) do @echo y")      |]]
        or  [[
        :call system("yes")                                  |]]))
      feed('foo<c-c>')
      screen:expect([[
        ^                                                     |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        -- INSERT --                                         |
      ]])
    end)
  end)

  describe('passing no input', function()
    it('returns the program output', function()
      if iswin() then
        eq("echoed\n", eval('system("echo echoed")'))
      else
        eq("echoed", eval('system("echo -n echoed")'))
      end
    end)
    it('to backgrounded command does not crash', function()
      -- This is indeterminate, just exercise the codepath. May get E5677.
      feed_command('call system(has("win32") ? "start /b /wait cmd /c echo echoed" : "echo -n echoed &")')
      local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
      if v_errnum then
        eq("E5677:", v_errnum)
      end
      assert_alive()
    end)
  end)

  describe('passing input', function()
    it('returns the program output', function()
      eq("input", eval('system("cat -", "input")'))
    end)
    it('to backgrounded command does not crash', function()
      -- This is indeterminate, just exercise the codepath. May get E5677.
      feed_command('call system(has("win32") ? "start /b /wait more" : "cat - &", "input")')
      local v_errnum = string.match(eval("v:errmsg"), "^E%d*:")
      if v_errnum then
        eq("E5677:", v_errnum)
      end
      assert_alive()
    end)
    it('works with an empty string', function()
      eq("test\n", eval('system("echo test", "")'))
      assert_alive()
    end)
  end)

  describe('passing a lot of input', function()
    it('returns the program output', function()
      local input = {}
      -- write more than 1mb of data, which should be enough to overcome
      -- the os buffer limit and force multiple event loop iterations to write
      -- everything
      for _ = 1, 0xffff do
        input[#input + 1] = '01234567890ABCDEFabcdef'
      end
      input = table.concat(input, '\n')
      nvim('set_var', 'input', input)
      eq(input, eval('system("cat -", g:input)'))
    end)
  end)

  describe('Number input', function()
    it('is treated as a buffer id', function()
      command("put ='text in buffer 1'")
      eq('\ntext in buffer 1\n', eval('system("cat", 1)'))
      eq('Vim(echo):E86: Buffer 42 does not exist',
         exc_exec('echo system("cat", 42)'))
    end)
  end)

  describe('with output containing NULs', function()
    local fname = 'Xtest'

    before_each(create_file_with_nuls(fname))
    after_each(delete_file(fname))

    it('replaces NULs by SOH characters', function()
      eq('part1\001part2\001part3\n', eval([[system('"cat" "]]..fname..[["')]]))
    end)
  end)

  describe('input passed as List', function()
    it('joins List items with linefeed characters', function()
      eq('line1\nline2\nline3',
        eval("system('cat -', ['line1', 'line2', 'line3'])"))
    end)

    -- Notice that NULs are converted to SOH when the data is read back. This
    -- is inconsistent and is a good reason for the existence of the
    -- `systemlist()` function, where input and output map to the same
    -- characters(see the following tests with `systemlist()` below)
    describe('with linefeed characters inside List items', function()
      it('converts linefeed characters to NULs', function()
        eq('l1\001p2\nline2\001a\001b\nl3',
          eval([[system('cat -', ["l1\np2", "line2\na\nb", 'l3'])]]))
      end)
    end)

    describe('with leading/trailing whitespace characters on items', function()
      it('preserves whitespace, replacing linefeeds by NULs', function()
        eq('line \nline2\001\n\001line3',
          eval([[system('cat -', ['line ', "line2\n", "\nline3"])]]))
      end)
    end)
  end)

  it("with a program that doesn't close stdout will exit properly after passing input", function()
    local out = eval(string.format("system('%s', 'clip-data')", testprg('streams-test')))
    assert(out:sub(0, 5) == 'pid: ', out)
    os_kill(out:match("%d+"))
  end)
end)

describe('systemlist()', function()
  -- Similar to `system()`, but returns List instead of String.
  before_each(clear)

  it('sets v:shell_error', function()
    if iswin() then
      eval([[systemlist("cmd.exe /c exit")]])
      eq(0, eval('v:shell_error'))
      eval([[systemlist("cmd.exe /c exit 1")]])
      eq(1, eval('v:shell_error'))
      eval([[systemlist("cmd.exe /c exit 5")]])
      eq(5, eval('v:shell_error'))
      eval([[systemlist('this-should-not-exist')]])
      eq(1, eval('v:shell_error'))
    else
      eval([[systemlist("sh -c 'exit'")]])
      eq(0, eval('v:shell_error'))
      eval([[systemlist("sh -c 'exit 1'")]])
      eq(1, eval('v:shell_error'))
      eval([[systemlist("sh -c 'exit 5'")]])
      eq(5, eval('v:shell_error'))
      eval([[systemlist('this-should-not-exist')]])
      eq(127, eval('v:shell_error'))
    end
  end)

  describe('executes shell function', function()
    local screen

    before_each(function()
      screen = Screen.new()
      screen:attach()
    end)

    after_each(function()
      screen:detach()
    end)

    it('`echo` and waits for its return', function()
      feed(':call systemlist("echo")<cr>')
      screen:expect([[
        ^                                                     |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        :call systemlist("echo")                             |
      ]])
    end)

    it('`yes` interrupted with CTRL-C', function()
      feed(':call systemlist("yes | xargs")<cr>')
      screen:expect([[
                                                             |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        :call systemlist("yes | xargs")                      |
      ]])
      feed('<c-c>')
      screen:expect([[
        ^                                                     |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        ~                                                    |
        Type  :qa  and press <Enter> to exit Nvim            |
      ]])
    end)
  end)

  describe('passing string with linefeed characters as input', function()
    it('splits the output on linefeed characters', function()
      eq({'abc', 'def', 'ghi'}, eval([[systemlist("cat -", "abc\ndef\nghi")]]))
    end)
  end)

  describe('passing a lot of input', function()
    it('returns the program output', function()
      local input = {}
      for _ = 1, 0xffff do
        input[#input + 1] = '01234567890ABCDEFabcdef'
      end
      nvim('set_var', 'input', input)
      eq(input, eval('systemlist("cat -", g:input)'))
    end)
  end)

  describe('with output containing NULs', function()
    local fname = 'Xtest'

    before_each(function()
      command('set ff=unix')
      create_file_with_nuls(fname)()
    end)
    after_each(delete_file(fname))

    it('replaces NULs by newline characters', function()
      eq({'part1\npart2\npart3'}, eval([[systemlist('"cat" "]]..fname..[["')]]))
    end)
  end)

  describe('input passed as List', function()
    it('joins list items with linefeed characters', function()
      eq({'line1', 'line2', 'line3'},
        eval("systemlist('cat -', ['line1', 'line2', 'line3'])"))
    end)

    -- Unlike `system()` which uses SOH to represent NULs, with `systemlist()`
    -- input and output are the same.
    describe('with linefeed characters inside list items', function()
      it('converts linefeed characters to NULs', function()
        eq({'l1\np2', 'line2\na\nb', 'l3'},
          eval([[systemlist('cat -', ["l1\np2", "line2\na\nb", 'l3'])]]))
      end)
    end)

    describe('with leading/trailing whitespace characters on items', function()
      it('preserves whitespace, replacing linefeeds by NULs', function()
        eq({'line ', 'line2\n', '\nline3'},
          eval([[systemlist('cat -', ['line ', "line2\n", "\nline3"])]]))
      end)
    end)
  end)

  describe('handles empty lines', function()
    it('in the middle', function()
      eq({'line one','','line two'}, eval("systemlist('cat',['line one','','line two'])"))
    end)

    it('in the beginning', function()
      eq({'','line one','line two'}, eval("systemlist('cat',['','line one','line two'])"))
    end)
  end)

  describe('when keepempty option is', function()
    it('0, ignores trailing newline', function()
      eq({'aa','bb'}, eval("systemlist('cat',['aa','bb'],0)"))
      eq({'aa','bb'}, eval("systemlist('cat',['aa','bb',''],0)"))
    end)

    it('1, preserves trailing newline', function()
      eq({'aa','bb'}, eval("systemlist('cat',['aa','bb'],1)"))
      eq({'aa','bb',''}, eval("systemlist('cat',['aa','bb',''],2)"))
    end)
  end)

  it("with a program that doesn't close stdout will exit properly after passing input", function()
    local out = eval(string.format("systemlist('%s', 'clip-data')", testprg('streams-test')))
    assert(out[1]:sub(0, 5) == 'pid: ', out)
    os_kill(out[1]:match("%d+"))
  end)

  it('powershell w/ UTF-8 text #13713', function()
    if not helpers.has_powershell() then
      pending("powershell not found", function() end)
      return
    end
    helpers.set_shell_powershell()
    eq({iswin() and 'あ\r' or 'あ'}, eval([[systemlist('Write-Output あ')]]))
    -- Sanity test w/ default encoding
    -- * on Windows, expected to default to Western European enc
    -- * on Linux, expected to default to UTF8
    command([[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']])
    eq({iswin() and '?\r' or 'あ'}, eval([[systemlist('Write-Output あ')]]))
  end)

end)

describe('shell :!', function()
  before_each(clear)

  it(':{range}! with powershell filter/redirect #16271 #19250', function()
    local screen = Screen.new(500, 8)
    screen:attach()
    local found = helpers.set_shell_powershell(true)
    insert([[
      3
      1
      4
      2]])
    if iswin() then
      feed(':4verbose %!sort /R<cr>')
      screen:expect{
        any=[[Executing command: .?& { Get%-Content .* | & sort /R } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]]
      }
    else
      feed(':4verbose %!sort -r<cr>')
      screen:expect{
        any=[[Executing command: .?& { Get%-Content .* | & sort %-r } 2>&1 | Out%-File %-Encoding UTF8 .*; exit $LastExitCode"]]
      }
    end
    feed('<CR>')
    if found then
      -- Not using fake powershell, so we can test the result.
      expect([[
        4
        3
        2
        1]])
    end
  end)
end)