Mercurial > vim
annotate src/testdir/term_util.vim @ 19938:f33098f1aec0 v8.2.0525
patch 8.2.0525: Win32: typo in assignment and misplaced paren
Commit: https://github.com/vim/vim/commit/40655d501649e0b73e12f940b56f462dee44e06c
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Apr 6 23:49:50 2020 +0200
patch 8.2.0525: Win32: typo in assignment and misplaced paren
Problem: Win32: typo in assignment and misplaced paren.
Solution: Fix the syntax.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 07 Apr 2020 00:01:14 +0200 |
parents | 031184ace7c5 |
children | c087099e9163 |
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 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 " 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
|
9 " 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
|
10 " terminal. |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 func CanRunVimInTerminal() |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 return has('terminal') && !has('win32') |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 endfunc |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 " 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
|
16 if !has('terminal') |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 finish |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 endif |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 " 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
|
21 func StopShellInTerminal(buf) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 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
|
23 let job = term_getjob(a:buf) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 call WaitFor({-> job_status(job) == "dead"}) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 endfunc |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 " 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
|
28 " 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
|
29 " 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
|
30 " |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 " Options is a dictionary, these items are recognized: |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 " "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
|
33 " "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
|
34 " "statusoff" - number of lines the status is offset from default |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 func RunVimInTerminal(arguments, options) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 " 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
|
37 " Remove it here. |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 call delete(".swp") |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 if exists('$COLORFGBG') |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 " 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
|
42 " 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
|
43 " late. |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 let $COLORFGBG = '' |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 endif |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 " 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
|
48 " 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
|
49 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
|
50 split |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 vsplit |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 " 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
|
54 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
|
55 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
|
56 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 " Make the window 20 lines high and 75 columns, unless told otherwise. |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 |
17249
3e2e998ce0db
patch 8.1.1624: when testing in the GUI may try to run gvim in a terminal
Bram Moolenaar <Bram@vim.org>
parents:
17164
diff
changeset
|
62 let cmd = GetVimCommandCleanTerm() .. a:arguments |
17164
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 |
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
|
64 let options = { |
17164
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 \ 'curwin': 1, |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 \ 'term_rows': rows, |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 \ 'term_cols': cols, |
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
|
68 \ } |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
17249
diff
changeset
|
69 " 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
|
70 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
|
71 |
4ac8161e92e0
patch 8.1.2080: the terminal API is limited and can't be disabled
Bram Moolenaar <Bram@vim.org>
parents:
17249
diff
changeset
|
72 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
|
73 |
17164
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 if &termwinsize == '' |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 " 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
|
76 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
|
77 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
|
78 endif |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 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
|
80 else |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 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
|
82 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
|
83 endif |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 |
19906
031184ace7c5
patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents:
19691
diff
changeset
|
85 call term_wait(buf) |
031184ace7c5
patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents:
19691
diff
changeset
|
86 |
17164
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 " Wait for "All" or "Top" of the ruler to be shown in the last line or in |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 " the status line of the last window. This can be quite slow (e.g. when |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 " using valgrind). |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 " If it fails then show the terminal contents for debugging. |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 try |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - statusoff)) >= cols - 1}) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 catch /timed out after/ |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 let lines = map(range(1, rows), {key, val -> term_getline(buf, val)}) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>")) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 endtry |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 |
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
|
98 " 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
|
99 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
|
100 |
17164
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 return buf |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
102 endfunc |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
103 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
104 " Stop a Vim running in terminal buffer "buf". |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
105 func StopVimInTerminal(buf) |
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
|
106 " 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
|
107 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
|
108 |
17164
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
109 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
|
110 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
111 " 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
|
112 " 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
|
113 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
|
114 |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
115 call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))}) |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
116 only! |
7927cf327396
patch 8.1.1581: shared functions for testing are disorganised
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
117 endfunc |
19906
031184ace7c5
patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents:
19691
diff
changeset
|
118 |
031184ace7c5
patch 8.2.0509: various code is not properly tested.
Bram Moolenaar <Bram@vim.org>
parents:
19691
diff
changeset
|
119 " vim: shiftwidth=2 sts=2 expandtab |