annotate src/testdir/term_util.vim @ 32383:b8e9ea3c1ed0 v9.0.1523

patch 9.0.1523: some error messages are not marked for translation Commit: https://github.com/vim/vim/commit/276410e78f0b82e3123059383994d2f4c578dfbd Author: zeertzjq <zeertzjq@outlook.com> Date: Sun May 7 21:59:33 2023 +0100 patch 9.0.1523: some error messages are not marked for translation Problem: Some error messages are not marked for translation. Solution: Surround the messages in _(). (closes https://github.com/vim/vim/issues/12356)
author Bram Moolenaar <Bram@vim.org>
date Sun, 07 May 2023 23:00:03 +0200
parents a2dd770c854a
children 79b2eb83f2df
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
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 func RunVimInTerminal(arguments, options)
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 " 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
61 " Remove it here.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 call delete(".swp")
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 if exists('$COLORFGBG')
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 " 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
66 " 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
67 " late.
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 let $COLORFGBG = ''
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 " 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
72 " 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
73 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
74 split
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 vsplit
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 " 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
78 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
79 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
80
22079
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
81 " 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
82 " 'termwinsize' is set.
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 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
84 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
85 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
86
20768
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
87 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
88 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
89 else
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
90 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
91 endif
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
92
1e2e81dbb958 patch 8.2.0936: some terminals misinterpret the code for getting cursor style
Bram Moolenaar <Bram@vim.org>
parents: 20365
diff changeset
93 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
94
32122
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
95 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
96 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
97 endif
a2dd770c854a patch 9.0.1392: using NULL pointer with nested :open command
Bram Moolenaar <Bram@vim.org>
parents: 31571
diff changeset
98
22079
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
99 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
100 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
101 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
102 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
103 endif
ba2c3f38a596 patch 8.2.1589: term_start() options for size are overruled by 'termwinsize'
Bram Moolenaar <Bram@vim.org>
parents: 21126
diff changeset
104
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
105 " 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
106 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
107
4ac8161e92e0 patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents: 17249
diff changeset
108 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
109
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 if &termwinsize == ''
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 " 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
112 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
113 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
114 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 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
116 else
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 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
118 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
119 endif
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120
19954
c087099e9163 patch 8.2.0533: tests using term_wait() can still be flaky
Bram Moolenaar <Bram@vim.org>
parents: 19906
diff changeset
121 call TermWait(buf)
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
122
20881
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
123 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
124 " 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
125 " 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
126 " 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
127 " 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
128 try
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
129 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
130 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
131 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
132 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
133 endtry
58137dbee8da patch 8.2.0992: Vim9: crash when using :import in the Vim command
Bram Moolenaar <Bram@vim.org>
parents: 20768
diff changeset
134 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135
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
136 " 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
137 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
138
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 return buf
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 endfunc
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 " 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
143 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
144 " 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
145 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
146
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 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
148
31571
c51111774ea8 patch 9.0.1118: sporadic test failures when using a terminal window
Bram Moolenaar <Bram@vim.org>
parents: 31247
diff changeset
149 " 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
150 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
151
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 " 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
153 " 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
154 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
155
20365
6bcd12791bf1 patch 8.2.0738: mouse handling in a terminal window not well tested
Bram Moolenaar <Bram@vim.org>
parents: 19954
diff changeset
156 " 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
157 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
158
22778
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
159 " 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
160 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
161
3ec5f653f64d patch 8.2.1937: Vim9: test for confirm modifier fails in some situations
Bram Moolenaar <Bram@vim.org>
parents: 22367
diff changeset
162 " 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
163 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
164 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
165 endif
17164
7927cf327396 patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 endfunc
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
167
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
168 " 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
169 " number.
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
170 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
171 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
172 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
173 else
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
174 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
175 endif
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
176 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
177
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
178 let termlist = term_list()
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
179 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
180 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
181
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
182 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
183 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
184
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
185 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
186 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
187
27098
8bb07c88ac27 patch 8.2.4078: terminal test for current directory not used on FreeBSD
Bram Moolenaar <Bram@vim.org>
parents: 24335
diff changeset
188 " 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
189 " 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
190 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
191
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
192 return buf
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
193 endfunc
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
194
23940
949238ccbd50 patch 8.2.2512: Vim9: compiling error test sometimes fails
Bram Moolenaar <Bram@vim.org>
parents: 22780
diff changeset
195 " 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
196 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
197 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
198 endfunc
21126
a35036006352 patch 8.2.1114: terminal test sometimes times out
Bram Moolenaar <Bram@vim.org>
parents: 20901
diff changeset
199
31245
fbc4d3b0302d patch 9.0.0956: terminal tests fail when using key with modifier
Bram Moolenaar <Bram@vim.org>
parents: 27098
diff changeset
200
19906
031184ace7c5 patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents: 19691
diff changeset
201 " vim: shiftwidth=2 sts=2 expandtab