robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Tests for system() and :! shell. 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each , after_each , pending , finally = 8t . describe , t . it , t . before_each , t . after_each , t . pending , t . finally 9local assert_alive =n . assert_alive 10local testprg =n . testprg 11local eq , call , clear , eval , feed_command , feed , api = 12t . eq , n . call , n . clear , n . eval , n . feed_command , n . feed , n . api 13local command =n . command 14local insert =n . insert 15local expect =n . expect 16local pcall_err =t . pcall_err 17local is_os =t . is_os 18 19local function create_file_with_nuls ( name ) 20return function () 21feed ( 'ipart1<C-V>000part2<C-V>000part3<ESC>:w ' .. name .. '<CR>' ) 22eval ( '1' ) -- wait for the file to be created 23end 24end 25 26local function delete_file ( name ) 27return function () 28eval ( "delete('" .. name .. "')" ) 29end 30end 31 32describe ( 'system()' , function () 33before_each ( clear ) 34 35describe ( 'command passed as a List' , function () 36it ( 'throws error if cmd[0] is not executable' , function () 37eq ( 38"Vim:E475: Invalid value for argument cmd: 'this-should-not-exist' is not executable" , 39pcall_err ( call , 'system' , { 'this-should-not-exist' } ) 40) 41eq ( - 1 , eval ( 'v:shell_error' )) 42end ) 43 44it ( 'parameter validation does NOT modify v:shell_error' , function () 45-- 1. Call system() with invalid parameters. 46-- 2. Assert that v:shell_error was NOT set. 47feed_command ( 'call system({})' ) 48eq ( 'E475: Invalid argument: expected String or List' , eval ( 'v:errmsg' )) 49eq ( 0 , eval ( 'v:shell_error' )) 50feed_command ( 'call system([])' ) 51eq ( 'E474: Invalid argument' , eval ( 'v:errmsg' )) 52eq ( 0 , eval ( 'v:shell_error' )) 53 54-- Provoke a non-zero v:shell_error. 55eq ( 56"Vim:E475: Invalid value for argument cmd: 'this-should-not-exist' is not executable" , 57pcall_err ( call , 'system' , { 'this-should-not-exist' } ) 58) 59local old_val =eval ( 'v:shell_error' ) 60eq ( - 1 , old_val ) 61 62-- 1. Call system() with invalid parameters. 63-- 2. Assert that v:shell_error was NOT modified. 64feed_command ( 'call system({})' ) 65eq ( old_val , eval ( 'v:shell_error' )) 66feed_command ( 'call system([])' ) 67eq ( old_val , eval ( 'v:shell_error' )) 68end ) 69 70it ( 'quotes arguments correctly #5280' , function () 71local out = 72call ( 'system' , { testprg ( 'printargs-test' ), [[1]] , [[2 "3]] , [[4 ' 5]] , [[6 ' 7']] } ) 73 74eq ( 0 , eval ( 'v:shell_error' )) 75eq ( [[arg1=1;arg2=2 "3;arg3=4 ' 5;arg4=6 ' 7';]] , out ) 76 77out =call ( 'system' , { testprg ( 'printargs-test' ), [['1]] , [[2 "3]] } ) 78eq ( 0 , eval ( 'v:shell_error' )) 79eq ( [[arg1='1;arg2=2 "3;]] , out ) 80 81out =call ( 'system' , { testprg ( 'printargs-test' ), 'A\nB' } ) 82eq ( 0 , eval ( 'v:shell_error' )) 83eq ( 'arg1=A\nB;' , out ) 84end ) 85 86it ( 'calls executable in $PATH' , function () 87if 0 == eval ( "executable('python3')" ) then 88pending ( 'missing `python3`' ) 89end 90eq ( 'foo\n' , eval ( [[system(['python3', '-c', 'print("foo")'])]] )) 91eq ( 0 , eval ( 'v:shell_error' )) 92end ) 93 94it ( 'does NOT run in shell' , function () 95if is_os ( 'win' ) then 96eq ( 97'%PATH%\n' , 98eval ( 99"system(['powershell', '-NoProfile', '-NoLogo', '-ExecutionPolicy', 'RemoteSigned', '-Command', 'Write-Output', '%PATH%'])" 100) 101) 102else 103eq ( '* $PATH %PATH%\n' , eval ( "system(['echo', '*', '$PATH', '%PATH%'])" )) 104end 105end ) 106end ) 107 108it ( 'sets v:shell_error' , function () 109if is_os ( 'win' ) then 110eval ( [[system("cmd.exe /c exit")]] ) 111eq ( 0 , eval ( 'v:shell_error' )) 112eval ( [[system("cmd.exe /c exit 1")]] ) 113eq ( 1 , eval ( 'v:shell_error' )) 114eval ( [[system("cmd.exe /c exit 5")]] ) 115eq ( 5 , eval ( 'v:shell_error' )) 116eval ( [[system('this-should-not-exist')]] ) 117eq ( 1 , eval ( 'v:shell_error' )) 118else 119eval ( [[system("sh -c 'exit'")]] ) 120eq ( 0 , eval ( 'v:shell_error' )) 121eval ( [[system("sh -c 'exit 1'")]] ) 122eq ( 1 , eval ( 'v:shell_error' )) 123eval ( [[system("sh -c 'exit 5'")]] ) 124eq ( 5 , eval ( 'v:shell_error' )) 125eval ( [[system('this-should-not-exist')]] ) 126eq ( 127 , eval ( 'v:shell_error' )) 127end 128end ) 129 130describe ( 'executes shell function' , function () 131local screen 132 133before_each ( function () 134screen =Screen . new () 135t . write_file ( 'Xmorefile' , ( 'line1\nline2\nline3\n' ): rep ( 10 )) 136end ) 137 138after_each ( function () 139os . remove ( 'Xmorefile' ) 140end ) 141 142if is_os ( 'win' ) then 143local function test_more () 144eq ( 'line1' , eval ( [[get(split(system('"more" "Xmorefile"'), "\n"), 0, '')]] )) 145end 146local function test_shell_unquoting () 147eval ( [[system('"ping" "-n" "1" "127.0.0.1"')]] ) 148eq ( 0 , eval ( 'v:shell_error' )) 149eq ( '"a b"\n' , eval ( [[system('cmd /s/c "cmd /s/c "cmd /s/c "echo "a b""""')]] )) 150eq ( 151'"a b"\n' , 152eval ( 153[[system('powershell -NoProfile -NoLogo -ExecutionPolicy RemoteSigned -Command Write-Output ''\^"a b\^"''')]] 154) 155) 156end 157 158it ( 'with shell=cmd.exe' , function () 159command ( 'set shell=cmd.exe' ) 160eq ( '""\n' , eval ( [[system('echo ""')]] )) 161eq ( '"a b"\n' , eval ( [[system('echo "a b"')]] )) 162eq ( 'a \nb\n' , eval ( [[system('echo a & echo b')]] )) 163eq ( 'a \n' , eval ( [[system('echo a 2>&1')]] )) 164test_more () 165eval ( [[system('cd "C:\Program Files"')]] ) 166eq ( 0 , eval ( 'v:shell_error' )) 167test_shell_unquoting () 168end ) 169 170it ( 'spawns child process with UTF-8 codepage' , function () 171command ( 'set shell=cmd.exe' ) 172eq ( 'тест\n' , eval ( [[system('echo тест')]] )) 173end ) 174 175it ( 'with shell=cmd' , function () 176command ( 'set shell=cmd' ) 177eq ( '"a b"\n' , eval ( [[system('echo "a b"')]] )) 178test_more () 179test_shell_unquoting () 180end ) 181 182it ( 'with shell=$COMSPEC' , function () 183local comspecshell =eval ( "fnamemodify($COMSPEC, ':t')" ) 184if comspecshell == 'cmd.exe' then 185command ( 'set shell=$COMSPEC' ) 186eq ( '"a b"\n' , eval ( [[system('echo "a b"')]] )) 187test_more () 188test_shell_unquoting () 189else 190pending ( '$COMSPEC is not cmd.exe: ' .. comspecshell ) 191end 192end ) 193 194it ( 'with powershell' , function () 195n . set_shell_powershell () 196eq ( 'a\nb\n' , eval ( [[system('Write-Output a b')]] )) 197eq ( 'C:\\\n' , eval ( [[system('cd c:\; (Get-Location).Path')]] )) 198eq ( 'a b\n' , eval ( [[system('Write-Output "a b"')]] )) 199end ) 200end 201 202it ( 'powershell w/ UTF-8 text #13713' , function () 203if not n . has_powershell () then 204pending ( 'powershell not found' , function () end ) 205return 206end 207n . set_shell_powershell () 208eq ( 'ああ\n' , eval ( [[system('Write-Output "ああ"')]] )) 209-- Sanity test w/ default encoding 210-- * on Windows, UTF-8 still works. 211-- * on Linux, expected to default to UTF8 212command ( [[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']] ) 213eq ( 'ああ\n' , eval ( [[system('Write-Output "ああ"')]] )) 214end ) 215 216it ( '`echo` and waits for its return' , function () 217feed ( ':call system("echo")<cr>' ) 218screen : expect ( [[ 219^ | 220{1:~ }|*12 221:call system("echo") | 222]] ) 223end ) 224 225it ( 'prints verbose information' , function () 226api . nvim_set_option_value ( 'shell' , 'fake_shell' , {} ) 227api . nvim_set_option_value ( 'shellcmdflag' , 'cmdflag' , {} ) 228 229screen : try_resize ( 72 , 14 ) 230feed ( ':4verbose echo system("echo hi")<cr>' ) 231if is_os ( 'win' ) then 232screen : expect { any =[[Executing command: "'fake_shell' 'cmdflag' '"echo hi"'"]] } 233else 234screen : expect { any =[[Executing command: "'fake_shell' 'cmdflag' 'echo hi'"]] } 235end 236feed ( '<cr>' ) 237end ) 238 239it ( 'self and total time recorded separately' , function () 240local tempfile =t . tmpname () 241 242feed ( ':function! AlmostNoSelfTime()<cr>' ) 243feed ( 'echo system("echo hi")<cr>' ) 244feed ( 'endfunction<cr>' ) 245 246feed ( ':profile start ' .. tempfile .. '<cr>' ) 247feed ( ':profile func AlmostNoSelfTime<cr>' ) 248feed ( ':call AlmostNoSelfTime()<cr>' ) 249feed ( ':profile dump<cr>' ) 250 251feed ( ':edit ' .. tempfile .. '<cr>' ) 252 253local command_total_time =tonumber ( n . fn . split ( n . fn . getline ( 7 ))[ 2 ]) 254local command_self_time =tonumber ( n . fn . split ( n . fn . getline ( 7 ))[ 3 ]) 255 256t . neq ( nil , command_total_time ) 257t . neq ( nil , command_self_time ) 258end ) 259 260it ( '`yes` interrupted with CTRL-C' , function () 261feed ( 262':call system("' 263.. ( is_os ( 'win' ) and 'for /L %I in (1,0,2) do @echo y' or 'yes' ) 264.. '")<cr>' 265) 266screen : expect ( [[ 267| 268{1:~ }|*12 269]] .. ( is_os ( 'win' ) and [[ 270:call system("for /L %I in (1,0,2) do @echo y") |]] or [[ 271:call system("yes") |]] )) 272feed ( 'foo<c-c>' ) 273screen : expect ( [[ 274^ | 275{1:~ }|*12 276Type :qa and press <Enter> to exit Nvim | 277]] ) 278end ) 279 280it ( '`yes` interrupted with mapped CTRL-C' , function () 281command ( 'nnoremap <C-C> i' ) 282feed ( 283':call system("' 284.. ( is_os ( 'win' ) and 'for /L %I in (1,0,2) do @echo y' or 'yes' ) 285.. '")<cr>' 286) 287screen : expect ( [[ 288| 289{1:~ }|*12 290]] .. ( is_os ( 'win' ) and [[ 291:call system("for /L %I in (1,0,2) do @echo y") |]] or [[ 292:call system("yes") |]] )) 293feed ( 'foo<c-c>' ) 294screen : expect ( [[ 295^ | 296{1:~ }|*12 297{5:-- INSERT --} | 298]] ) 299end ) 300end ) 301 302describe ( 'passing no input' , function () 303it ( 'returns the program output' , function () 304if is_os ( 'win' ) then 305eq ( 'echoed\n' , eval ( 'system("echo echoed")' )) 306else 307eq ( 'echoed' , eval ( 'system("printf echoed")' )) 308end 309end ) 310it ( 'to backgrounded command does not crash' , function () 311-- This is indeterminate, just exercise the codepath. May get E5677. 312feed_command ( 313'call system(has("win32") ? "start /b /wait cmd /c echo echoed" : "printf echoed &")' 314) 315local v_errnum =string . match ( eval ( 'v:errmsg' ), '^E%d*:' ) 316if v_errnum then 317eq ( 'E5677:' , v_errnum ) 318end 319assert_alive () 320end ) 321end ) 322 323describe ( 'passing input' , function () 324it ( 'returns the program output' , function () 325eq ( 'input' , eval ( 'system("cat -", "input")' )) 326end ) 327it ( 'to backgrounded command does not crash' , function () 328-- This is indeterminate, just exercise the codepath. May get E5677. 329feed_command ( 'call system(has("win32") ? "start /b /wait more" : "cat - &", "input")' ) 330local v_errnum =string . match ( eval ( 'v:errmsg' ), '^E%d*:' ) 331if v_errnum then 332eq ( 'E5677:' , v_errnum ) 333end 334assert_alive () 335end ) 336it ( 'works with an empty string' , function () 337eq ( 'test\n' , eval ( 'system("echo test", "")' )) 338assert_alive () 339end ) 340end ) 341 342describe ( 'passing a lot of input' , function () 343it ( 'returns the program output' , function () 344local input ={} 345-- write more than 1mb of data, which should be enough to overcome 346-- the os buffer limit and force multiple event loop iterations to write 347-- everything 348for _ =1 , 0xffff do 349input [ # input + 1 ] ='01234567890ABCDEFabcdef' 350end 351input =table . concat ( input , '\n' ) 352api . nvim_set_var ( 'input' , input ) 353eq ( input , eval ( 'system("cat -", g:input)' )) 354end ) 355end ) 356 357describe ( 'Number input' , function () 358it ( 'is treated as a buffer id' , function () 359command ( "put ='text in buffer 1'" ) 360eq ( '\ntext in buffer 1\n' , eval ( 'system("cat", 1)' )) 361eq ( 'Vim(echo):E86: Buffer 42 does not exist' , pcall_err ( command , 'echo system("cat", 42)' )) 362end ) 363end ) 364 365describe ( 'with output containing NULs' , function () 366local fname ='Xtest_functional_vimscript_system_nuls' 367 368before_each ( create_file_with_nuls ( fname )) 369after_each ( delete_file ( fname )) 370 371it ( 'replaces NULs by SOH characters' , function () 372eq ( 'part1\001part2\001part3\n' , eval ( [[system('"cat" "]] .. fname .. [["')]] )) 373end ) 374end ) 375 376describe ( 'input passed as List' , function () 377it ( 'joins List items with linefeed characters' , function () 378eq ( 'line1\nline2\nline3' , eval ( "system('cat -', ['line1', 'line2', 'line3'])" )) 379end ) 380 381-- Notice that NULs are converted to SOH when the data is read back. This 382-- is inconsistent and is a good reason for the existence of the 383-- `systemlist()` function, where input and output map to the same 384-- characters(see the following tests with `systemlist()` below) 385describe ( 'with linefeed characters inside List items' , function () 386it ( 'converts linefeed characters to NULs' , function () 387eq ( 388'\001l1\001p2\nline2\001a\001b\nl3' , 389eval ( [[system('cat -', ["\nl1\np2", "line2\na\nb", 'l3'])]] ) 390) 391end ) 392end ) 393 394describe ( 'with leading/trailing whitespace characters on items' , function () 395it ( 'preserves whitespace, replacing linefeeds by NULs' , function () 396eq ( 397'line \nline2\001\n\001line3' , 398eval ( [[system('cat -', ['line ', "line2\n", "\nline3"])]] ) 399) 400end ) 401end ) 402end ) 403 404it ( "with a program that doesn't close stdout will exit properly after passing input" , function () 405local out =eval ( string . format ( "system('%s', 'clip-data')" , testprg ( 'streams-test' ))) 406assert ( out : sub ( 0 , 5 ) == 'pid: ' , out ) 407eq ( 0 , vim . uv . kill ( assert ( tonumber ( out : match ( '%d+' ))), 'sigkill' )) 408end ) 409end ) 410 411describe ( 'systemlist()' , function () 412-- Similar to `system()`, but returns List instead of String. 413before_each ( clear ) 414 415it ( 'sets v:shell_error' , function () 416if is_os ( 'win' ) then 417eval ( [[systemlist("cmd.exe /c exit")]] ) 418eq ( 0 , eval ( 'v:shell_error' )) 419eval ( [[systemlist("cmd.exe /c exit 1")]] ) 420eq ( 1 , eval ( 'v:shell_error' )) 421eval ( [[systemlist("cmd.exe /c exit 5")]] ) 422eq ( 5 , eval ( 'v:shell_error' )) 423eval ( [[systemlist('this-should-not-exist')]] ) 424eq ( 1 , eval ( 'v:shell_error' )) 425else 426eval ( [[systemlist("sh -c 'exit'")]] ) 427eq ( 0 , eval ( 'v:shell_error' )) 428eval ( [[systemlist("sh -c 'exit 1'")]] ) 429eq ( 1 , eval ( 'v:shell_error' )) 430eval ( [[systemlist("sh -c 'exit 5'")]] ) 431eq ( 5 , eval ( 'v:shell_error' )) 432eval ( [[systemlist('this-should-not-exist')]] ) 433eq ( 127 , eval ( 'v:shell_error' )) 434end 435end ) 436 437describe ( 'executes shell function' , function () 438local screen 439 440before_each ( function () 441screen =Screen . new () 442end ) 443 444it ( '`echo` and waits for its return' , function () 445feed ( ':call systemlist("echo")<cr>' ) 446screen : expect ( [[ 447^ | 448{1:~ }|*12 449:call systemlist("echo") | 450]] ) 451end ) 452 453it ( '`yes` interrupted with CTRL-C' , function () 454feed ( ':call systemlist("yes | xargs")<cr>' ) 455screen : expect ( [[ 456| 457{1:~ }|*12 458:call systemlist("yes | xargs") | 459]] ) 460feed ( '<c-c>' ) 461screen : expect ( [[ 462^ | 463{1:~ }|*12 464Type :qa and press <Enter> to exit Nvim | 465]] ) 466end ) 467end ) 468 469describe ( 'passing string with linefeed characters as input' , function () 470it ( 'splits the output on linefeed characters' , function () 471eq ( { 'abc' , 'def' , 'ghi' } , eval ( [[systemlist("cat -", "abc\ndef\nghi")]] )) 472end ) 473end ) 474 475describe ( 'passing a lot of input' , function () 476it ( 'returns the program output' , function () 477local input ={} 478for _ =1 , 0xffff do 479input [ # input + 1 ] ='01234567890ABCDEFabcdef' 480end 481api . nvim_set_var ( 'input' , input ) 482eq ( input , eval ( 'systemlist("cat -", g:input)' )) 483end ) 484end ) 485 486describe ( 'with output containing NULs' , function () 487local fname ='Xtest_functional_vimscript_systemlist_nuls' 488 489before_each ( function () 490command ( 'set ff=unix' ) 491create_file_with_nuls ( fname )() 492end ) 493after_each ( delete_file ( fname )) 494 495it ( 'replaces NULs by newline characters' , function () 496eq ( { 'part1\npart2\npart3' } , eval ( [[systemlist('"cat" "]] .. fname .. [["')]] )) 497end ) 498end ) 499 500describe ( 'input passed as List' , function () 501it ( 'joins list items with linefeed characters' , function () 502eq ( { 'line1' , 'line2' , 'line3' } , eval ( "systemlist('cat -', ['line1', 'line2', 'line3'])" )) 503end ) 504 505-- Unlike `system()` which uses SOH to represent NULs, with `systemlist()` 506-- input and output are the same. 507describe ( 'with linefeed characters inside list items' , function () 508it ( 'converts linefeed characters to NULs' , function () 509eq ( 510{ '\nl1\np2' , 'line2\na\nb' , 'l3' } , 511eval ( [[systemlist('cat -', ["\nl1\np2", "line2\na\nb", 'l3'])]] ) 512) 513end ) 514end ) 515 516describe ( 'with leading/trailing whitespace characters on items' , function () 517it ( 'preserves whitespace, replacing linefeeds by NULs' , function () 518eq ( 519{ 'line ' , 'line2\n' , '\nline3' } , 520eval ( [[systemlist('cat -', ['line ', "line2\n", "\nline3"])]] ) 521) 522end ) 523end ) 524end ) 525 526describe ( 'handles empty lines' , function () 527it ( 'in the middle' , function () 528eq ( { 'line one' , '' , 'line two' } , eval ( "systemlist('cat',['line one','','line two'])" )) 529end ) 530 531it ( 'in the beginning' , function () 532eq ( { '' , 'line one' , 'line two' } , eval ( "systemlist('cat',['','line one','line two'])" )) 533end ) 534end ) 535 536describe ( 'when keepempty option is' , function () 537it ( '0, ignores trailing newline' , function () 538eq ( { 'aa' , 'bb' } , eval ( "systemlist('cat',['aa','bb'],0)" )) 539eq ( { 'aa' , 'bb' } , eval ( "systemlist('cat',['aa','bb',''],0)" )) 540end ) 541 542it ( '1, preserves trailing newline' , function () 543eq ( { 'aa' , 'bb' } , eval ( "systemlist('cat',['aa','bb'],1)" )) 544eq ( { 'aa' , 'bb' , '' } , eval ( "systemlist('cat',['aa','bb',''],2)" )) 545end ) 546end ) 547 548it ( "with a program that doesn't close stdout will exit properly after passing input" , function () 549local out =eval ( string . format ( "systemlist('%s', 'clip-data')" , testprg ( 'streams-test' ))) 550assert ( out [ 1 ]: sub ( 0 , 5 ) == 'pid: ' , out ) 551eq ( 0 , vim . uv . kill ( assert ( tonumber ( out [ 1 ]: match ( '%d+' ))), 'sigkill' )) 552end ) 553 554it ( 'powershell w/ UTF-8 text #13713' , function () 555if not n . has_powershell () then 556pending ( 'powershell not found' , function () end ) 557return 558end 559n . set_shell_powershell () 560eq ( { is_os ( 'win' ) and 'あ\r' or 'あ' } , eval ( [[systemlist('Write-Output あ')]] )) 561-- Sanity test w/ default encoding 562-- * on Windows, UTF-8 still works. 563-- * on Linux, expected to default to UTF8 564command ( [[let &shellcmdflag = '-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command ']] ) 565eq ( { is_os ( 'win' ) and 'あ\r' or 'あ' } , eval ( [[systemlist('Write-Output あ')]] )) 566end ) 567end ) 568 569describe ( 'shell :!' , function () 570before_each ( clear ) 571 572it ( 'preserves newlines (including CR) in binary-mode buffer #39424' , function () 573local fname ='Xbinaryfile' 574finally ( function () 575os . remove ( fname ) 576end ) 577 578t . write_file ( fname , '\r\n' , true ) 579command ( 'edit ++bin ' .. fname ) 580command ( '%!cat' ) 581command ( 'w' ) 582eq ( '\r\n' , t . read_file ( fname )) 583 584t . write_file ( fname , '\r' , true ) 585command ( 'edit ++bin ' .. fname ) 586command ( '%!cat' ) 587command ( 'w' ) 588eq ( '\r' , t . read_file ( fname )) 589end ) 590 591it ( ':{range}! works when the first char is NUL #34163' , function () 592api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { '\0hello' , 'hello' } ) 593command ( '%!cat' ) 594eq ( { '\0hello' , 'hello' } , api . nvim_buf_get_lines ( 0 , 0 , - 1 , true )) 595end ) 596 597it ( ':{range}! with powershell using "commands" filter/redirect #16271 #19250' , function () 598if not n . has_powershell () then 599return 600end 601local screen =Screen . new ( 500 , 8 ) 602n . set_shell_powershell () 603insert ( [[ 6043 6051 6064 6072]] ) 608if is_os ( 'win' ) then 609feed ( ':4verbose %!sort /R<cr>' ) 610screen : expect { 611any =[[Executing command: " $input | sort /R".*]] , 612} 613else 614feed ( ':4verbose %!sort -r<cr>' ) 615screen : expect { 616any =[[Executing command: " $input | sort %-r".*]] , 617} 618end 619feed ( '<CR>' ) 620expect ( [[ 6214 6223 6232 6241]] ) 625end ) 626 627it ( ':{range}! with powershell using "cmdlets" filter/redirect #16271 #19250' , function () 628if not n . has_powershell () then 629pending ( 'powershell not found' , function () end ) 630return 631end 632local screen =Screen . new ( 500 , 8 ) 633n . set_shell_powershell () 634insert ( [[ 6353 6361 6374 6382]] ) 639feed ( ':4verbose %!Sort-Object -Descending<cr>' ) 640screen : expect { 641any =[[Executing command: " $input | Sort%-Object %-Descending".*]] , 642} 643feed ( '<CR>' ) 644expect ( [[ 6454 6463 6472 6481]] ) 649end ) 650 651it ( ':{range}! without redirecting to buffer' , function () 652local screen =Screen . new ( 500 , 10 ) 653insert ( [[ 6543 6551 6564 6572]] ) 658feed ( ':4verbose %w !sort<cr>' ) 659screen : expect { 660any =[[Executing command: "sort".*]] , 661} 662feed ( '<CR>' ) 663 664if not n . has_powershell () then 665return 666end 667 668n . set_shell_powershell ( true ) 669feed ( ':4verbose %w !sort<cr>' ) 670screen : expect { 671any =[[Executing command: " $input | sort".*]] , 672} 673feed ( '<CR>' ) 674n . expect_exit ( command , 'qall!' ) 675end ) 676end )