blob: 1016646c5bde5a67d4a4c9d029283183a0b8fe14 [file] [log] [blame]
Bram Moolenaarda650582018-02-20 15:51:40 +01001" Functions shared by tests making screen dumps.
2
3" Only load this script once.
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01004if exists('*CanRunVimInTerminal')
Bram Moolenaarda650582018-02-20 15:51:40 +01005 finish
6endif
7
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +01008" Need to be able to run terminal Vim with 256 colors. On MS-Windows the
9" console only has 16 colors and the GUI can't run in a terminal.
10if !has('terminal') || has('win32')
11 func CanRunVimInTerminal()
12 return 0
13 endfunc
14 finish
15endif
16
17func CanRunVimInTerminal()
18 return 1
19endfunc
20
Bram Moolenaarda650582018-02-20 15:51:40 +010021source shared.vim
22
23" Run Vim with "arguments" in a new terminal window.
24" By default uses a size of 20 lines and 75 columns.
25" Returns the buffer number of the terminal.
26"
27" Options is a dictionary (not used yet).
28func RunVimInTerminal(arguments, options)
29 " Make a horizontal and vertical split, so that we can get exactly the right
30 " size terminal window. Works only when we currently have one window.
31 call assert_equal(1, winnr('$'))
32 split
33 vsplit
34
Bram Moolenaar6acadda2018-02-24 16:51:32 +010035 " Always do this with 256 colors and a light background.
36 set t_Co=256 background=light
37 hi Normal ctermfg=NONE ctermbg=NONE
Bram Moolenaarda650582018-02-20 15:51:40 +010038
39 let cmd = GetVimCommandClean()
Bram Moolenaarb7ea7cb2018-02-24 14:38:51 +010040 " Add -v to have gvim run in the terminal (if possible)
41 let cmd .= ' -v ' . a:arguments
Bram Moolenaarda650582018-02-20 15:51:40 +010042 let buf = term_start(cmd, {'curwin': 1, 'term_rows': 20, 'term_cols': 75})
43 call assert_equal([20, 75], term_getsize(buf))
44
45 return buf
46endfunc
47
48" Stop a Vim running in terminal buffer "buf".
49func StopVimInTerminal(buf)
50 call assert_equal("running", term_getstatus(a:buf))
Bram Moolenaar2b10bcb2018-02-24 21:25:44 +010051 call term_sendkeys(a:buf, "\<Esc>\<Esc>:qa!\<cr>")
Bram Moolenaarda650582018-02-20 15:51:40 +010052 call WaitFor('term_getstatus(' . a:buf . ') == "finished"')
53 only!
54endfunc
55
56" Verify that Vim running in terminal buffer "buf" matches the screen dump.
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +010057" "options" is passed to term_dumpwrite().
Bram Moolenaarda650582018-02-20 15:51:40 +010058" The file name used is "dumps/{filename}.dump".
59" Will wait for up to a second for the screen dump to match.
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +010060func VerifyScreenDump(buf, filename, options)
Bram Moolenaarda650582018-02-20 15:51:40 +010061 let reference = 'dumps/' . a:filename . '.dump'
62 let testfile = a:filename . '.dump.failed'
63
64 let i = 0
65 while 1
66 call delete(testfile)
Bram Moolenaar6bb2cdf2018-02-24 19:53:53 +010067 call term_dumpwrite(a:buf, testfile, a:options)
Bram Moolenaarda650582018-02-20 15:51:40 +010068 if readfile(reference) == readfile(testfile)
69 call delete(testfile)
70 break
71 endif
72 if i == 100
73 " Leave the test file around for inspection.
74 call assert_report('See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")')
75 break
76 endif
77 sleep 10m
78 let i += 1
79 endwhile
80endfunc