robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
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 () 24local screen 25before_each ( function () 26clear () 27screen =tt . setup_child_nvim ( { 28'-u' , 29'NONE' , 30'-i' , 31'NONE' , 32'--cmd' , 33'colorscheme vim' , 34'--cmd' , 35n . nvim_set .. ' notermguicolors' , 36} ) 37screen : expect ( [[ 38^ | 39{100:~ }|*4 40| 41{5:-- TERMINAL --} | 42]] ) 43end ) 44 45it ( 'displays output without LF/EOF. #4646 #4569 #3772' , function () 46skip ( is_os ( 'win' )) 47-- NOTE: We use a child nvim (within a :term buffer) 48-- to avoid triggering a UI flush. 49tt . feed_data ( ':!printf foo; sleep 200\n' ) 50screen : expect ( [[ 51| 52{100:~ }|*2 53{3: }| 54:!printf foo; sleep 200 | 55foo | 56{5:-- TERMINAL --} | 57]] ) 58tt . feed_data ( '\3' ) -- Ctrl-C 59screen : expect ( [[ 60^ | 61{100:~ }|*4 62| 63{5:-- TERMINAL --} | 64]] ) 65end ) 66 67it ( 'throttles shell-command output greater than ~10KB' , { retries =2 } , function () 68skip ( is_os ( 'openbsd' ), 'FIXME #10804' ) 69skip ( is_os ( 'win' )) 70tt . 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. 74screen : 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.) 78screen : expect { 79grid =[[ 80149997: foo | 81149998: foo | 82149999: foo | 83150000: foo | 84| 85{123:Press ENTER or type command to continue}^ | 86{5:-- TERMINAL --} | 87]] , 88timeout =20000 , 89} 90end ) 91end ) 92 93describe ( 'shell command :!' , function () 94before_each ( function () 95clear () 96end ) 97 98it ( 'cat a binary file #4142' , function () 99feed ( ":exe 'silent !cat '.shellescape(v:progpath)<CR>" ) 100assert_alive () 101end ) 102 103it ( [[display \x08 char #4142]] , function () 104feed ( ':silent !echo \08<CR>' ) 105assert_alive () 106end ) 107 108it ( 'handles control codes' , function () 109skip ( is_os ( 'win' ), 'N/A: missing printf' ) 110local screen =Screen . new ( 50 , 4 ) 111-- Print TAB chars. #2958 112feed ( [[:!printf '1\t2\t3'<CR>]] ) 113screen : expect ( [[ 114{3: }| 115:!printf '1\t2\t3' | 1161 2 3 | 117{6:Press ENTER or type command to continue}^ | 118]] ) 119feed ( [[<CR>]] ) 120 121-- Print BELL control code. #4338 122screen . bell =false 123feed ( [[:!printf '\007\007\007\007text'<CR>]] ) 124screen : expect { 125grid =[[ 126{3: }| 127:!printf '\007\007\007\007text' | 128text | 129{6:Press ENTER or type command to continue}^ | 130]] , 131condition =function () 132eq ( true , screen . bell ) 133end , 134} 135feed ( [[<CR>]] ) 136 137-- Print BS control code. 138feed ( [[:echo system('printf ''\010\n''')<CR>]] ) 139screen : expect ( [[ 140{3: }| 141{18:^H} | 142| 143{6:Press ENTER or type command to continue}^ | 144]] ) 145feed ( [[<CR>]] ) 146 147-- Print LF control code. 148feed ( [[:!printf '\n'<CR>]] ) 149screen : expect ( [[ 150:!printf '\n' | 151|*2 152{6:Press ENTER or type command to continue}^ | 153]] ) 154feed ( [[<CR>]] ) 155end ) 156 157describe ( '' , function () 158local screen 159before_each ( function () 160rmdir ( 'bang_filter_spec' ) 161mkdir ( 'bang_filter_spec' ) 162write_file ( 'bang_filter_spec/f1' , 'f1' ) 163write_file ( 'bang_filter_spec/f2' , 'f2' ) 164write_file ( 'bang_filter_spec/f3' , 'f3' ) 165screen =Screen . new ( 53 , 10 ) 166end ) 167 168after_each ( function () 169rmdir ( 'bang_filter_spec' ) 170end ) 171 172it ( "doesn't truncate Last line of shell output #3269" , function () 173command ( 174is_os ( 'win' ) and [[nnoremap <silent>\l :!dir /b bang_filter_spec<cr>]] 175or [[nnoremap <silent>\l :!ls bang_filter_spec<cr>]] 176) 177local result =( 178is_os ( 'win' ) and [[:!dir /b bang_filter_spec]] or [[:!ls bang_filter_spec ]] 179) 180feed ( [[\l]] ) 181screen : expect ( [[ 182| 183{1:~ }|*2 184{3: }| 185]] .. result .. [[ | 186f1 | 187f2 | 188f3 | 189| 190{6:Press ENTER or type command to continue}^ | 191]] ) 192end ) 193 194it ( 'handles binary and multibyte data' , function () 195feed_command ( '!cat test/functional/fixtures/shell_data.txt' ) 196screen . bell =false 197screen : expect { 198grid =[[ 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> | 206t <ff> | 207| 208{6:Press ENTER or type command to continue}^ | 209]] , 210condition =function () 211eq ( true , screen . bell ) 212end , 213} 214end ) 215 216it ( 'handles multibyte sequences split over buffer boundaries' , function () 217command ( 'cd ' .. nvim_dir ) 218local cmd =is_os ( 'win' ) and '!shell-test UTF-8 ' or '!./shell-test UTF-8' 219feed_command ( cmd ) 220-- Note: only the first example of split composed char works 221screen : expect ( [[ 222| 223{3: }| 224:]] .. cmd .. [[ | 225å | 226ref: å̲ | 2271: å̲ | 2282: å ̲ | 2293: å ̲ | 230| 231{6:Press ENTER or type command to continue}^ | 232]] ) 233end ) 234end ) 235if has_powershell () then 236it ( 'powershell supports literal strings' , function () 237set_shell_powershell () 238local screen =Screen . new ( 45 , 4 ) 239feed_command ( [[!'Write-Output $a']] ) 240screen : expect ( [[ 241:!'Write-Output $a' | 242Write-Output $a | 243| 244{6:Press ENTER or type command to continue}^ | 245]] ) 246feed_command ( [[!$a = 1; Write-Output '$a']] ) 247screen : expect ( [[ 248:!$a = 1; Write-Output '$a' | 249$a | 250| 251{6:Press ENTER or type command to continue}^ | 252]] ) 253feed_command ( [[!"Write-Output $a"]] ) 254screen : expect ( [[ 255:!"Write-Output $a" | 256Write-Output | 257| 258{6:Press ENTER or type command to continue}^ | 259]] ) 260feed_command ( [[!$a = 1; Write-Output "$a"]] ) 261screen : expect ( [[ 262:!$a = 1; Write-Output "$a" | 2631 | 264| 265{6:Press ENTER or type command to continue}^ | 266]] ) 267if is_os ( 'win' ) then 268feed_command ( [[!& 'cmd.exe' /c 'echo $a']] ) 269screen : expect ( [[ 270:!& 'cmd.exe' /c 'echo $a' | 271$a | 272| 273{6:Press ENTER or type command to continue}^ | 274]] ) 275else 276feed_command ( [[!& '/bin/sh' -c 'echo ''$a''']] ) 277screen : expect ( [[ 278:!& '/bin/sh' -c 'echo ''$a''' | 279$a | 280| 281{6:Press ENTER or type command to continue}^ | 282]] ) 283end 284end ) 285end 286end )