annotate src/testdir/term_util.vim @ 26366:d227481dbe8e v8.2.3714

patch 8.2.3714: some unused assignments and ugly code in xxd Commit: https://github.com/vim/vim/commit/7e5503c17a3f142e6b28f344d899c9ab9e75a844 Author: DungSaga <dungsaga@users.noreply.github.com> Date: Wed Dec 1 11:24:52 2021 +0000 patch 8.2.3714: some unused assignments and ugly code in xxd Problem: Some unused assignments and ugly code in xxd. Solution: Leave out assignments. Use marcro for fprintf(). (closes https://github.com/vim/vim/issues/9246)
author Bram Moolenaar <Bram@vim.org>
date Wed, 01 Dec 2021 12:30:04 +0100
parents 3f96a5dc0c53
children 8bb07c88ac27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Functions about terminal shared by several tests
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Only load this script once.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 if exists('*CanRunVimInTerminal')
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 finish
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7
22367
997bbc35c181 patch 8.2.1732: stuck when win_execute() for a popup causes an error
Bram Moolenaar <Bram@vim.org>
parents: 22079
diff changeset
8 source shared.vim
997bbc35c181 patch 8.2.1732: stuck when win_execute() for a popup causes an error
Bram Moolenaar <Bram@vim.org>
parents: 22079
diff changeset
9
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 " For most tests we need to be able to run terminal Vim with 256 colors. On
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 " MS-Windows the console only has 16 colors and the GUI can't run in a
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 " terminal.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 func CanRunVimInTerminal()
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 return has('terminal') && !has('win32')
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 endfunc
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 " Skip the rest if there is no terminal feature at all.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 if !has('terminal')
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 finish
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 " Stops the shell running in terminal "buf".
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 func StopShellInTerminal(buf)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 call term_sendkeys(a:buf, "exit\r")
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 let job = term_getjob(a:buf)
24335
3f96a5dc0c53 patch 8.2.2708: test sometimes fails waiting for shell in terminal
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
26 call WaitForAssert({-> assert_equal("dead", job_status(job))})
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 endfunc
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
29 " Wrapper around term_wait() to allow more time for re-runs of flaky tests
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
30 " The second argument is the minimum time to wait in msec, 10 if omitted.
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
31 func TermWait(buf, ...)
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
32 let wait_time = a:0 ? a:1 : 10
20901
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
33 if exists('g:run_nr')
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
34 if g:run_nr == 2
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
35 let wait_time *= 4
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
36 elseif g:run_nr > 2
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
37 let wait_time *= 10
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
38 endif
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
39 endif
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
40 call term_wait(a:buf, wait_time)
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
41
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
42 " In case it wasn't set yet.
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
43 let g:test_is_flaky = 1
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
44 endfunc
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
45
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 " Run Vim with "arguments" in a new terminal window.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 " By default uses a size of 20 lines and 75 columns.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 " Returns the buffer number of the terminal.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 "
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 " Options is a dictionary, these items are recognized:
20768
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
51 " "keep_t_u7" - when 1 do not make t_u7 empty (resetting t_u7 avoids clearing
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
52 " parts of line 2 and 3 on the display)
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 " "rows" - height of the terminal window (max. 20)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 " "cols" - width of the terminal window (max. 78)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 " "statusoff" - number of lines the status is offset from default
22367
997bbc35c181 patch 8.2.1732: stuck when win_execute() for a popup causes an error
Bram Moolenaar <Bram@vim.org>
parents: 22079
diff changeset
56 " "wait_for_ruler" - if zero then don't wait for ruler to show
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 func RunVimInTerminal(arguments, options)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 " If Vim doesn't exit a swap file remains, causing other tests to fail.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 " Remove it here.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 call delete(".swp")
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 if exists('$COLORFGBG')
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 " Clear $COLORFGBG to avoid 'background' being set to "dark", which will
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 " only be corrected if the response to t_RB is received, which may be too
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 " late.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 let $COLORFGBG = ''
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 " Make a horizontal and vertical split, so that we can get exactly the right
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 " size terminal window. Works only when the current window is full width.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 call assert_equal(&columns, winwidth(0))
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 split
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 vsplit
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 " Always do this with 256 colors and a light background.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 set t_Co=256 background=light
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 hi Normal ctermfg=NONE ctermbg=NONE
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
22079
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
79 " Make the window 20 lines high and 75 columns, unless told otherwise or
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
80 " 'termwinsize' is set.
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 let rows = get(a:options, 'rows', 20)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 let cols = get(a:options, 'cols', 75)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 let statusoff = get(a:options, 'statusoff', 1)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
20768
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
85 if get(a:options, 'keep_t_u7', 0)
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
86 let reset_u7 = ''
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
87 else
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
88 let reset_u7 = ' --cmd "set t_u7=" '
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
89 endif
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
90
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
91 let cmd = GetVimCommandCleanTerm() .. reset_u7 .. a:arguments
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92
22079
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
93 let options = #{curwin: 1}
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
94 if &termwinsize == ''
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
95 let options.term_rows = rows
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
96 let options.term_cols = cols
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
97 endif
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
98
18170
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
99 " Accept other options whose name starts with 'term_'.
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
100 call extend(options, filter(copy(a:options), 'v:key =~# "^term_"'))
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
101
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
102 let buf = term_start(cmd, options)
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
103
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 if &termwinsize == ''
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 " in the GUI we may end up with a different size, try to set it.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 if term_getsize(buf) != [rows, cols]
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 call term_setsize(buf, rows, cols)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 call assert_equal([rows, cols], term_getsize(buf))
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 else
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 let rows = term_getsize(buf)[0]
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 let cols = term_getsize(buf)[1]
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
115 call TermWait(buf)
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
116
20881
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
117 if get(a:options, 'wait_for_ruler', 1)
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
118 " Wait for "All" or "Top" of the ruler to be shown in the last line or in
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
119 " the status line of the last window. This can be quite slow (e.g. when
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
120 " using valgrind).
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
121 " If it fails then show the terminal contents for debugging.
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
122 try
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
123 call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - statusoff)) >= cols - 1})
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
124 catch /timed out after/
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
125 let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
126 call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
127 endtry
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
128 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129
19687
c3f506e24eab patch 8.2.0400: not all tests using a terminal are in the list of flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 18170
diff changeset
130 " Starting a terminal to run Vim is always considered flaky.
19691
60b5abfc4897 patch 8.2.0402: setting local instead of global flag
Bram Moolenaar <Bram@vim.org>
parents: 19687
diff changeset
131 let g:test_is_flaky = 1
19687
c3f506e24eab patch 8.2.0400: not all tests using a terminal are in the list of flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 18170
diff changeset
132
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 return buf
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 endfunc
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 " Stop a Vim running in terminal buffer "buf".
22780
2e681033d766 patch 8.2.1938: wiping out a terminal buffer makes some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 22778
diff changeset
137 func StopVimInTerminal(buf, kill = 1)
19687
c3f506e24eab patch 8.2.0400: not all tests using a terminal are in the list of flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 18170
diff changeset
138 " Using a terminal to run Vim is always considered flaky.
19691
60b5abfc4897 patch 8.2.0402: setting local instead of global flag
Bram Moolenaar <Bram@vim.org>
parents: 19687
diff changeset
139 let g:test_is_flaky = 1
19687
c3f506e24eab patch 8.2.0400: not all tests using a terminal are in the list of flaky tests
Bram Moolenaar <Bram@vim.org>
parents: 18170
diff changeset
140
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 call assert_equal("running", term_getstatus(a:buf))
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 " CTRL-O : works both in Normal mode and Insert mode to start a command line.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 " In Command-line it's inserted, the CTRL-U removes it again.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 call term_sendkeys(a:buf, "\<C-O>:\<C-U>qa!\<cr>")
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146
20365
6bcd12791bf1 patch 8.2.0738: mouse handling in a terminal window not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
147 " Wait for all the pending updates to terminal to complete
6bcd12791bf1 patch 8.2.0738: mouse handling in a terminal window not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
148 call TermWait(a:buf)
6bcd12791bf1 patch 8.2.0738: mouse handling in a terminal window not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
149
22778
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
150 " Wait for the terminal to end.
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))})
22778
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
152
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
153 " If the buffer still exists forcefully wipe it.
22780
2e681033d766 patch 8.2.1938: wiping out a terminal buffer makes some tests fail
Bram Moolenaar <Bram@vim.org>
parents: 22778
diff changeset
154 if a:kill && bufexists(a:buf)
22778
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
155 exe a:buf .. 'bwipe!'
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
156 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 endfunc
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
158
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
159 " Open a terminal with a shell, assign the job to g:job and return the buffer
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
160 " number.
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
161 func Run_shell_in_terminal(options)
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
162 if has('win32')
24335
3f96a5dc0c53 patch 8.2.2708: test sometimes fails waiting for shell in terminal
Bram Moolenaar <Bram@vim.org>
parents: 23940
diff changeset
163 let buf = term_start([&shell, '/k'], a:options)
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
164 else
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
165 let buf = term_start(&shell, a:options)
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
166 endif
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
167 let g:test_is_flaky = 1
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
168
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
169 let termlist = term_list()
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
170 call assert_equal(1, len(termlist))
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
171 call assert_equal(buf, termlist[0])
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
172
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
173 let g:job = term_getjob(buf)
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
174 call assert_equal(v:t_job, type(g:job))
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
175
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
176 let string = string({'job': buf->term_getjob()})
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
177 call assert_match("{'job': 'process \\d\\+ run'}", string)
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
178
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
179 return buf
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
180 endfunc
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
181
23940
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 22780
diff changeset
182 " Return concatenated lines in terminal.
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 22780
diff changeset
183 func Term_getlines(buf, lines)
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 22780
diff changeset
184 return join(map(a:lines, 'term_getline(a:buf, v:val)'), '')
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 22780
diff changeset
185 endfunc
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
186
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
187 " vim: shiftwidth=2 sts=2 expandtab