annotate src/testdir/term_util.vim @ 34682:a36144b38683 v9.1.0222

patch 9.1.0222: missing 'below' virt text if truncation precedes after/right text Commit: https://github.com/vim/vim/commit/fe0a76b2bca12b13982ad66bafadc0d6c1681d00 Author: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Date: Thu Mar 28 11:47:32 2024 +0100 patch 9.1.0222: missing 'below' virt text if truncation precedes after/right text Problem: When a line is truncated just before 'after'/'right' virtual text and the line also has 'below' virtual text, then the 'below' virtual text would not be displayed, depending on the order these text properties were added. Solution: In the loop to make text properties active, skip instead of break for 'after'/'right' virtual text properties that are ignored due to truncation, so following 'below' text properties can still be made active. Similarly, a loop is needed to determine if a text property follows at the end of the screen. (Dylan Thacker-Smith) related: #14307 Signed-off-by: Dylan Thacker-Smith <dylan.ah.smith@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Mar 2024 12:00:04 +0100
parents 79b2eb83f2df
children 1ee567e88a22
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))})
27098
8bb07c88ac27 patch 8.2.4078: terminal test for current directory not used on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 24335
diff changeset
27 call TermWait(a:buf)
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 endfunc
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
30 " 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
31 " 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
32 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
33 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
34 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
35 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
36 let wait_time *= 4
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
37 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
38 let wait_time *= 10
7d0fe945278c patch 8.2.1002: test may fail when run directly
Bram Moolenaar <Bram@vim.org>
parents: 20881
diff changeset
39 endif
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
40 endif
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
41 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
42
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
43 " 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
44 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
45 endfunc
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
46
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 " 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
48 " 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
49 " 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
50 "
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 " 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
52 " "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
53 " 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
54 " "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
55 " "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
56 " "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
57 " "wait_for_ruler" - if zero then don't wait for ruler to show
32122
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
58 " "no_clean" - if non-zero then remove "--clean" from the command
33083
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
59 " "cmd" - run any other command, e.g. "xxd" (used in xxd test)
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 func RunVimInTerminal(arguments, options)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 " 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
62 " Remove it here.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 call delete(".swp")
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 if exists('$COLORFGBG')
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 " 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
67 " 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
68 " late.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 let $COLORFGBG = ''
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 " 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
73 " 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
74 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
75 split
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 vsplit
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 " 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
79 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
80 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
81
22079
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
82 " 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
83 " 'termwinsize' is set.
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 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
85 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
86 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
87
20768
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
88 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
89 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
90 else
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 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
92 endif
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
93
33083
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
94 if empty(get(a:options, 'cmd', ''))
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
95 let cmd = GetVimCommandCleanTerm() .. reset_u7 .. a:arguments
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
96 else
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
97 let cmd = get(a:options, 'cmd')
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
98 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99
32122
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
100 if get(a:options, 'no_clean', 0)
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
101 let cmd = substitute(cmd, '--clean', '', '')
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
102 endif
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
103
22079
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
104 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
105 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
106 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
107 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
108 endif
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
109
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
110 " 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
111 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
112
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
113 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
114
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 if &termwinsize == ''
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 " 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
117 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
118 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
119 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 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
121 else
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 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
123 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
124 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
126 call TermWait(buf)
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
127
33083
79b2eb83f2df patch 9.0.1827: xxd: no color support
Christian Brabandt <cb@256bit.org>
parents: 32122
diff changeset
128 if get(a:options, 'wait_for_ruler', 1) && empty(get(a:options, 'cmd', ''))
20881
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
129 " 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
130 " 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
131 " 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
132 " 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
133 try
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
134 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
135 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
136 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
137 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
138 endtry
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
139 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
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
141 " 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
142 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
143
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 return buf
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 endfunc
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 " 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
148 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
149 " 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
150 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
151
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 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
153
31571
c51111774ea8 patch 9.0.1118: sporadic test failures when using a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 31247
diff changeset
154 " Wait for all the pending updates to terminal to complete
c51111774ea8 patch 9.0.1118: sporadic test failures when using a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 31247
diff changeset
155 call TermWait(a:buf)
c51111774ea8 patch 9.0.1118: sporadic test failures when using a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 31247
diff changeset
156
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 " 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
158 " 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
159 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
160
20365
6bcd12791bf1 patch 8.2.0738: mouse handling in a terminal window not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
161 " 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
162 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
163
22778
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
164 " 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
165 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
166
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
167 " 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
168 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
169 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
170 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 endfunc
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
172
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
173 " 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
174 " number.
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
175 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
176 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
177 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
178 else
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
179 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
180 endif
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
181 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
182
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
183 let termlist = term_list()
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
184 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
185 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
186
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
187 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
188 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
189
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
190 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
191 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
192
27098
8bb07c88ac27 patch 8.2.4078: terminal test for current directory not used on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 24335
diff changeset
193 " On slower systems it may take a bit of time before the shell is ready to
8bb07c88ac27 patch 8.2.4078: terminal test for current directory not used on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 24335
diff changeset
194 " accept keys. This mainly matters when using term_sendkeys() next.
8bb07c88ac27 patch 8.2.4078: terminal test for current directory not used on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 24335
diff changeset
195 call TermWait(buf)
8bb07c88ac27 patch 8.2.4078: terminal test for current directory not used on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 24335
diff changeset
196
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
197 return buf
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
198 endfunc
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
199
23940
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 22780
diff changeset
200 " 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
201 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
202 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
203 endfunc
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
204
31245
fbc4d3b0302d patch 9.0.0956: terminal tests fail when using key with modifier
Bram Moolenaar <Bram@vim.org>
parents: 27098
diff changeset
205
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
206 " vim: shiftwidth=2 sts=2 expandtab