Mercurial > vim
comparison src/testdir/test_terminal2.vim @ 30865:c8ebe35b2475 v9.0.0767
patch 9.0.0767: too many delete() calls in tests
Commit: https://github.com/vim/vim/commit/c4860bdd2832feb7ab054c6dc14f68abe24c2373
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 15 20:52:26 2022 +0100
patch 9.0.0767: too many delete() calls in tests
Problem: Too many delete() calls in tests.
Solution: Use deferred delete where possible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Oct 2022 22:00:04 +0200 |
parents | 13b02c1ea0f7 |
children | 8f15c56ff2fb |
comparison
equal
deleted
inserted
replaced
30864:51906709cb7a | 30865:c8ebe35b2475 |
---|---|
17 set termwinsize=6x40 | 17 set termwinsize=6x40 |
18 let text = [] | 18 let text = [] |
19 for n in range(10) | 19 for n in range(10) |
20 call add(text, repeat(n, 50)) | 20 call add(text, repeat(n, 50)) |
21 endfor | 21 endfor |
22 call writefile(text, 'Xwinsize') | 22 call writefile(text, 'Xwinsize', 'D') |
23 let buf = RunVimInTerminal('Xwinsize', {}) | 23 let buf = RunVimInTerminal('Xwinsize', {}) |
24 let win = bufwinid(buf) | 24 let win = bufwinid(buf) |
25 call assert_equal([6, 40], term_getsize(buf)) | 25 call assert_equal([6, 40], term_getsize(buf)) |
26 call assert_equal(6, winheight(win)) | 26 call assert_equal(6, winheight(win)) |
27 call assert_equal(40, winwidth(win)) | 27 call assert_equal(40, winwidth(win)) |
32 call assert_equal([6, 40], term_getsize(buf)) | 32 call assert_equal([6, 40], term_getsize(buf)) |
33 call assert_equal(10, winheight(win)) | 33 call assert_equal(10, winheight(win)) |
34 call assert_equal(60, winwidth(win)) | 34 call assert_equal(60, winwidth(win)) |
35 | 35 |
36 call StopVimInTerminal(buf) | 36 call StopVimInTerminal(buf) |
37 call delete('Xwinsize') | |
38 | 37 |
39 call assert_fails('set termwinsize=40', 'E474:') | 38 call assert_fails('set termwinsize=40', 'E474:') |
40 call assert_fails('set termwinsize=10+40', 'E474:') | 39 call assert_fails('set termwinsize=10+40', 'E474:') |
41 call assert_fails('set termwinsize=abc', 'E474:') | 40 call assert_fails('set termwinsize=abc', 'E474:') |
42 | 41 |
190 | 189 |
191 call writefile([ | 190 call writefile([ |
192 \ '#!/bin/sh', | 191 \ '#!/bin/sh', |
193 \ 'echo "this is standard error" >&2', | 192 \ 'echo "this is standard error" >&2', |
194 \ 'echo "this is standard out" >&1', | 193 \ 'echo "this is standard out" >&1', |
195 \ ], 'Xechoerrout.sh') | 194 \ ], 'Xechoerrout.sh', 'D') |
196 call setfperm('Xechoerrout.sh', 'rwxrwx---') | 195 call setfperm('Xechoerrout.sh', 'rwxrwx---') |
197 | 196 |
198 let outfile = 'Xtermstdout' | 197 let outfile = 'Xtermstdout' |
199 let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile}) | 198 let buf = term_start(['./Xechoerrout.sh'], {'out_io': 'file', 'out_name': outfile}) |
200 | 199 |
202 call assert_equal(['this is standard out'], readfile(outfile)) | 201 call assert_equal(['this is standard out'], readfile(outfile)) |
203 call assert_equal('this is standard error', term_getline(buf, 1)) | 202 call assert_equal('this is standard error', term_getline(buf, 1)) |
204 | 203 |
205 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) | 204 call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(buf)))}) |
206 exe buf . 'bwipe' | 205 exe buf . 'bwipe' |
207 call delete('Xechoerrout.sh') | |
208 call delete(outfile) | 206 call delete(outfile) |
209 endfunc | 207 endfunc |
210 | 208 |
211 func Test_termwinscroll() | 209 func Test_termwinscroll() |
212 CheckUnix | 210 CheckUnix |
288 call assert_equal("", bufname(buf)) | 286 call assert_equal("", bufname(buf)) |
289 | 287 |
290 unlet g:job | 288 unlet g:job |
291 endfunc | 289 endfunc |
292 | 290 |
293 " TODO: re-enable when this no longer hangs on Travis | 291 func Test_zz2_terminal_guioptions_bang() |
294 "func Test_zz2_terminal_guioptions_bang() | 292 CheckGui |
295 " CheckGui | 293 set guioptions+=! |
296 " set guioptions+=! | 294 |
297 " | 295 let filename = 'Xtestscript' |
298 " let filename = 'Xtestscript' | 296 if has('win32') |
299 " if has('win32') | 297 let filename .= '.bat' |
300 " let filename .= '.bat' | 298 let prefix = '' |
301 " let prefix = '' | 299 let contents = ['@echo off', 'exit %1'] |
302 " let contents = ['@echo off', 'exit %1'] | 300 else |
303 " else | 301 let filename .= '.sh' |
304 " let filename .= '.sh' | 302 let prefix = './' |
305 " let prefix = './' | 303 let contents = ['#!/bin/sh', 'exit $1'] |
306 " let contents = ['#!/bin/sh', 'exit $1'] | 304 endif |
307 " endif | 305 call writefile(contents, filename, 'D') |
308 " call writefile(contents, filename) | 306 call setfperm(filename, 'rwxrwx---') |
309 " call setfperm(filename, 'rwxrwx---') | 307 |
310 " | 308 " Check if v:shell_error is equal to the exit status. |
311 " " Check if v:shell_error is equal to the exit status. | 309 let exitval = 0 |
312 " let exitval = 0 | 310 execute printf(':!%s%s %d', prefix, filename, exitval) |
313 " execute printf(':!%s%s %d', prefix, filename, exitval) | 311 call assert_equal(exitval, v:shell_error) |
314 " call assert_equal(exitval, v:shell_error) | 312 |
315 " | 313 let exitval = 9 |
316 " let exitval = 9 | 314 execute printf(':!%s%s %d', prefix, filename, exitval) |
317 " execute printf(':!%s%s %d', prefix, filename, exitval) | 315 call assert_equal(exitval, v:shell_error) |
318 " call assert_equal(exitval, v:shell_error) | 316 |
319 " | 317 set guioptions& |
320 " set guioptions& | 318 endfunc |
321 " call delete(filename) | |
322 "endfunc | |
323 | 319 |
324 func Test_terminal_hidden() | 320 func Test_terminal_hidden() |
325 CheckUnix | 321 CheckUnix |
326 | 322 |
327 term ++hidden cat | 323 term ++hidden cat |
370 " Run Vim in a terminal and open a terminal window to run Vim in. | 366 " Run Vim in a terminal and open a terminal window to run Vim in. |
371 let lines =<< trim END | 367 let lines =<< trim END |
372 call setline(1, range(11111, 11122)) | 368 call setline(1, range(11111, 11122)) |
373 3 | 369 3 |
374 END | 370 END |
375 call writefile(lines, 'XtermNormal') | 371 call writefile(lines, 'XtermNormal', 'D') |
376 let buf = RunVimInTerminal('-S XtermNormal', {'rows': 8}) | 372 let buf = RunVimInTerminal('-S XtermNormal', {'rows': 8}) |
377 call TermWait(buf) | 373 call TermWait(buf) |
378 | 374 |
379 call term_sendkeys(buf, "\<C-W>N") | 375 call term_sendkeys(buf, "\<C-W>N") |
380 call term_sendkeys(buf, ":set number cursorline culopt=both\r") | 376 call term_sendkeys(buf, ":set number cursorline culopt=both\r") |
387 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {}) | 383 call VerifyScreenDump(buf, 'Test_terminal_normal_3', {}) |
388 | 384 |
389 call assert_fails('call term_sendkeys(buf, [])', 'E730:') | 385 call assert_fails('call term_sendkeys(buf, [])', 'E730:') |
390 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>") | 386 call term_sendkeys(buf, "a:q!\<CR>:q\<CR>:q\<CR>") |
391 call StopVimInTerminal(buf) | 387 call StopVimInTerminal(buf) |
392 call delete('XtermNormal') | |
393 endfunc | 388 endfunc |
394 | 389 |
395 func Test_terminal_hidden_and_close() | 390 func Test_terminal_hidden_and_close() |
396 CheckUnix | 391 CheckUnix |
397 | 392 |
413 \ [ 'Two', '', '' ], | 408 \ [ 'Two', '', '' ], |
414 \ [ 'Three' ] + repeat([''], 30) | 409 \ [ 'Three' ] + repeat([''], 30) |
415 \ ] | 410 \ ] |
416 | 411 |
417 for c in contents | 412 for c in contents |
418 call writefile(c, 'Xdntfile') | 413 call writefile(c, 'Xdntfile', 'D') |
419 if has('win32') | 414 if has('win32') |
420 term cmd /c type Xdntfile | 415 term cmd /c type Xdntfile |
421 else | 416 else |
422 term cat Xdntfile | 417 term cat Xdntfile |
423 endif | 418 endif |
426 call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) | 421 call WaitForAssert({-> assert_equal('finished', term_getstatus(bnr))}) |
427 sleep 100m | 422 sleep 100m |
428 call assert_equal(c, getline(1, line('$'))) | 423 call assert_equal(c, getline(1, line('$'))) |
429 quit | 424 quit |
430 endfor | 425 endfor |
431 | |
432 call delete('Xdntfile') | |
433 endfunc | 426 endfunc |
434 | 427 |
435 func GetDummyCmd() | 428 func GetDummyCmd() |
436 if has('win32') | 429 if has('win32') |
437 return 'cmd /c ""' | 430 return 'cmd /c ""' |