comparison src/testdir/screendump.vim @ 17164:7927cf327396 v8.1.1581

patch 8.1.1581: shared functions for testing are disorganised commit https://github.com/vim/vim/commit/7a39dd7f00239059ce34660611589b26126a550c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 23 00:50:15 2019 +0200 patch 8.1.1581: shared functions for testing are disorganised Problem: Shared functions for testing are disorganised. Solution: Group finctions in script files. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/4573)
author Bram Moolenaar <Bram@vim.org>
date Sun, 23 Jun 2019 01:00:05 +0200
parents 18ec0b92f431
children 9606c0adc148
comparison
equal deleted inserted replaced
17163:f5a43b78de92 17164:7927cf327396
1 " Functions shared by tests making screen dumps. 1 " Functions shared by tests making screen dumps.
2 2
3 " Only load this script once. 3 " Only load this script once.
4 if exists('*CanRunVimInTerminal') 4 if exists('*VerifyScreenDump')
5 finish 5 finish
6 endif 6 endif
7 7
8 " For most tests we need to be able to run terminal Vim with 256 colors. On 8 source shared.vim
9 " MS-Windows the console only has 16 colors and the GUI can't run in a 9 source term_util.vim
10 " terminal.
11 func CanRunVimInTerminal()
12 return has('terminal') && !has('win32')
13 endfunc
14 10
15 " Skip the rest if there is no terminal feature at all. 11 " Skip the rest if there is no terminal feature at all.
16 if !has('terminal') 12 if !has('terminal')
17 finish 13 finish
18 endif 14 endif
19
20 source shared.vim
21
22 " Run Vim with "arguments" in a new terminal window.
23 " By default uses a size of 20 lines and 75 columns.
24 " Returns the buffer number of the terminal.
25 "
26 " Options is a dictionary, these items are recognized:
27 " "rows" - height of the terminal window (max. 20)
28 " "cols" - width of the terminal window (max. 78)
29 " "statusoff" - number of lines the status is offset from default
30 func RunVimInTerminal(arguments, options)
31 " If Vim doesn't exit a swap file remains, causing other tests to fail.
32 " Remove it here.
33 call delete(".swp")
34
35 if exists('$COLORFGBG')
36 " Clear $COLORFGBG to avoid 'background' being set to "dark", which will
37 " only be corrected if the response to t_RB is received, which may be too
38 " late.
39 let $COLORFGBG = ''
40 endif
41
42 " Make a horizontal and vertical split, so that we can get exactly the right
43 " size terminal window. Works only when the current window is full width.
44 call assert_equal(&columns, winwidth(0))
45 split
46 vsplit
47
48 " Always do this with 256 colors and a light background.
49 set t_Co=256 background=light
50 hi Normal ctermfg=NONE ctermbg=NONE
51
52 " Make the window 20 lines high and 75 columns, unless told otherwise.
53 let rows = get(a:options, 'rows', 20)
54 let cols = get(a:options, 'cols', 75)
55 let statusoff = get(a:options, 'statusoff', 1)
56
57 let cmd = GetVimCommandClean()
58
59 " Add -v to have gvim run in the terminal (if possible)
60 let cmd .= ' -v ' . a:arguments
61 let buf = term_start(cmd, {
62 \ 'curwin': 1,
63 \ 'term_rows': rows,
64 \ 'term_cols': cols,
65 \ })
66 if &termwinsize == ''
67 " in the GUI we may end up with a different size, try to set it.
68 if term_getsize(buf) != [rows, cols]
69 call term_setsize(buf, rows, cols)
70 endif
71 call assert_equal([rows, cols], term_getsize(buf))
72 else
73 let rows = term_getsize(buf)[0]
74 let cols = term_getsize(buf)[1]
75 endif
76
77 " Wait for "All" or "Top" of the ruler to be shown in the last line or in
78 " the status line of the last window. This can be quite slow (e.g. when
79 " using valgrind).
80 " If it fails then show the terminal contents for debugging.
81 try
82 call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || len(term_getline(buf, rows - statusoff)) >= cols - 1})
83 catch /timed out after/
84 let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
85 call assert_report('RunVimInTerminal() failed, screen contents: ' . join(lines, "<NL>"))
86 endtry
87
88 return buf
89 endfunc
90
91 " Stop a Vim running in terminal buffer "buf".
92 func StopVimInTerminal(buf)
93 call assert_equal("running", term_getstatus(a:buf))
94
95 " CTRL-O : works both in Normal mode and Insert mode to start a command line.
96 " In Command-line it's inserted, the CTRL-U removes it again.
97 call term_sendkeys(a:buf, "\<C-O>:\<C-U>qa!\<cr>")
98
99 call WaitForAssert({-> assert_equal("finished", term_getstatus(a:buf))})
100 only!
101 endfunc
102 15
103 " Verify that Vim running in terminal buffer "buf" matches the screen dump. 16 " Verify that Vim running in terminal buffer "buf" matches the screen dump.
104 " "options" is passed to term_dumpwrite(). 17 " "options" is passed to term_dumpwrite().
105 " The file name used is "dumps/{filename}.dump". 18 " The file name used is "dumps/{filename}.dump".
106 " Optionally an extra argument can be passed which is prepended to the error 19 " Optionally an extra argument can be passed which is prepended to the error