comparison src/testdir/test_terminal.vim @ 19245:5ed8297121fa v8.2.0181

patch 8.2.0181: problems parsing :term arguments Commit: https://github.com/vim/vim/commit/21109272f5b0d32c408dc292561c0b1f2f8ebc53 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 30 16:27:20 2020 +0100 patch 8.2.0181: problems parsing :term arguments Problem: Problems parsing :term arguments. Solution: Improve parsing, fix memory leak, add tests. (Ozaki Kiichi, closes #5536)
author Bram Moolenaar <Bram@vim.org>
date Thu, 30 Jan 2020 16:30:04 +0100
parents c7b16393c248
children ce8c47ed54e5
comparison
equal deleted inserted replaced
19244:bb09b0f937ad 19245:5ed8297121fa
687 unlet g:job 687 unlet g:job
688 bwipe 688 bwipe
689 endfunc 689 endfunc
690 690
691 func Test_terminal_write_stdin() 691 func Test_terminal_write_stdin()
692 if !executable('wc') 692 " TODO: enable once writing to stdin works on MS-Windows
693 throw 'skipped: wc command not available' 693 CheckNotMSWindows
694 endif 694 CheckExecutable wc
695 if has('win32') 695
696 " TODO: enable once writing to stdin works on MS-Windows
697 return
698 endif
699 new
700 call setline(1, ['one', 'two', 'three']) 696 call setline(1, ['one', 'two', 'three'])
701 %term wc 697 %term wc
702 call WaitForAssert({-> assert_match('3', getline("$"))}) 698 call WaitForAssert({-> assert_match('3', getline("$"))})
703 let nrs = split(getline('$')) 699 let nrs = split(getline('$'))
704 call assert_equal(['3', '3', '14'], nrs) 700 call assert_equal(['3', '3', '14'], nrs)
705 bwipe 701 %bwipe!
706 702
707 new
708 call setline(1, ['one', 'two', 'three', 'four']) 703 call setline(1, ['one', 'two', 'three', 'four'])
709 2,3term wc 704 2,3term wc
710 call WaitForAssert({-> assert_match('2', getline("$"))}) 705 call WaitForAssert({-> assert_match('2', getline("$"))})
711 let nrs = split(getline('$')) 706 let nrs = split(getline('$'))
712 call assert_equal(['2', '2', '10'], nrs) 707 call assert_equal(['2', '2', '10'], nrs)
713 bwipe 708 %bwipe!
714 709 endfunc
715 if executable('python') 710
716 new 711 func Test_terminal_eof_arg()
717 call setline(1, ['print("hello")']) 712 CheckExecutable python
718 1term ++eof=exit() python 713
719 " MS-Windows echoes the input, Unix doesn't. 714 call setline(1, ['print("hello")'])
720 call WaitFor('getline("$") =~ "exit" || getline(1) =~ "hello"') 715 1term ++eof=exit(123) python
721 if getline(1) =~ 'hello' 716 " MS-Windows echoes the input, Unix doesn't.
722 call assert_equal('hello', getline(1)) 717 if has('win32')
723 else 718 call WaitFor({-> getline('$') =~ 'exit(123)'})
724 call assert_equal('hello', getline(line('$') - 1)) 719 call assert_equal('hello', getline(line('$') - 1))
725 endif 720 else
726 bwipe 721 call WaitFor({-> getline('$') =~ 'hello'})
727 722 call assert_equal('hello', getline('$'))
728 if has('win32') 723 endif
729 new 724 call assert_equal(123, bufnr()->term_getjob()->job_info().exitval)
730 call setline(1, ['print("hello")']) 725 %bwipe!
731 1term ++eof=<C-Z> python 726 endfunc
732 call WaitForAssert({-> assert_match('Z', getline("$"))}) 727
733 call assert_equal('hello', getline(line('$') - 1)) 728 func Test_terminal_eof_arg_win32_ctrl_z()
734 bwipe 729 CheckMSWindows
735 endif 730 CheckExecutable python
736 endif 731
737 732 call setline(1, ['print("hello")'])
738 bwipe! 733 1term ++eof=<C-Z> python
734 call WaitForAssert({-> assert_match('\^Z', getline(line('$') - 1))})
735 call assert_match('\^Z', getline(line('$') - 1))
736 %bwipe!
737 endfunc
738
739 func Test_terminal_duplicate_eof_arg()
740 CheckExecutable python
741
742 " Check the last specified ++eof arg is used and should not memory leak.
743 new
744 call setline(1, ['print("hello")'])
745 1term ++eof=<C-Z> ++eof=exit(123) python
746 " MS-Windows echoes the input, Unix doesn't.
747 if has('win32')
748 call WaitFor({-> getline('$') =~ 'exit(123)'})
749 call assert_equal('hello', getline(line('$') - 1))
750 else
751 call WaitFor({-> getline('$') =~ 'hello'})
752 call assert_equal('hello', getline('$'))
753 endif
754 call assert_equal(123, bufnr()->term_getjob()->job_info().exitval)
755 %bwipe!
739 endfunc 756 endfunc
740 757
741 func Test_terminal_no_cmd() 758 func Test_terminal_no_cmd()
742 let buf = term_start('NONE', {}) 759 let buf = term_start('NONE', {})
743 call assert_notequal(0, buf) 760 call assert_notequal(0, buf)
2240 bwipe! 2257 bwipe!
2241 endif 2258 endif
2242 endfunc 2259 endfunc
2243 2260
2244 func Test_terminal_setapi_and_call() 2261 func Test_terminal_setapi_and_call()
2245 if !CanRunVimInTerminal() 2262 CheckRunVimInTerminal
2246 return
2247 endif
2248 2263
2249 call WriteApiCall('Tapi_TryThis') 2264 call WriteApiCall('Tapi_TryThis')
2250 call ch_logfile('Xlog', 'w') 2265 call ch_logfile('Xlog', 'w')
2251 2266
2252 unlet! g:called_bufnum 2267 unlet! g:called_bufnum
2253 unlet! g:called_arg 2268 unlet! g:called_arg
2254 2269
2255 let buf = RunVimInTerminal('-S Xscript', {'term_api': 0}) 2270 let buf = RunVimInTerminal('-S Xscript', {'term_api': ''})
2256 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))}) 2271 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
2257 call assert_false(exists('g:called_bufnum')) 2272 call assert_false(exists('g:called_bufnum'))
2258 call assert_false(exists('g:called_arg')) 2273 call assert_false(exists('g:called_arg'))
2259 2274
2260 call term_setapi(buf, 'Tapi_TryThis') 2275 eval buf->term_setapi('Tapi_')
2261 call term_sendkeys(buf, ":set notitle\<CR>") 2276 call term_sendkeys(buf, ":set notitle\<CR>")
2262 call term_sendkeys(buf, ":source Xscript\<CR>") 2277 call term_sendkeys(buf, ":source Xscript\<CR>")
2263 call WaitFor({-> exists('g:called_bufnum')}) 2278 call WaitFor({-> exists('g:called_bufnum')})
2264 call assert_equal(buf, g:called_bufnum) 2279 call assert_equal(buf, g:called_bufnum)
2265 call assert_equal(['hello', 123], g:called_arg) 2280 call assert_equal(['hello', 123], g:called_arg)
2281
2266 call StopVimInTerminal(buf) 2282 call StopVimInTerminal(buf)
2267 2283
2268 call delete('Xscript') 2284 call delete('Xscript')
2269 call ch_logfile('') 2285 call ch_logfile('')
2270 call delete('Xlog') 2286 call delete('Xlog')
2271 unlet! g:called_bufnum 2287 unlet! g:called_bufnum
2272 unlet! g:called_arg 2288 unlet! g:called_arg
2273 endfunc 2289 endfunc
2290
2291 func Test_terminal_api_arg()
2292 CheckRunVimInTerminal
2293
2294 call WriteApiCall('Tapi_TryThis')
2295 call ch_logfile('Xlog', 'w')
2296
2297 unlet! g:called_bufnum
2298 unlet! g:called_arg
2299
2300 execute 'term ++api= ' .. GetVimCommandCleanTerm() .. '-S Xscript'
2301 let buf = bufnr('%')
2302 call WaitForAssert({-> assert_match('Unpermitted function: Tapi_TryThis', string(readfile('Xlog')))})
2303 call assert_false(exists('g:called_bufnum'))
2304 call assert_false(exists('g:called_arg'))
2305
2306 call StopVimInTerminal(buf)
2307
2308 call ch_logfile('Xlog', 'w')
2309
2310 execute 'term ++api=Tapi_ ' .. GetVimCommandCleanTerm() .. '-S Xscript'
2311 let buf = bufnr('%')
2312 call WaitFor({-> exists('g:called_bufnum')})
2313 call assert_equal(buf, g:called_bufnum)
2314 call assert_equal(['hello', 123], g:called_arg)
2315
2316 call StopVimInTerminal(buf)
2317
2318 call delete('Xscript')
2319 call ch_logfile('')
2320 call delete('Xlog')
2321 unlet! g:called_bufnum
2322 unlet! g:called_arg
2323 endfunc