blob: 5ebe60908ba8d478d95a940fbbd929d044be3d13 [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.
4if exists('*RunVimInTerminal')
5 finish
6endif
7
8source shared.vim
9
10" Run Vim with "arguments" in a new terminal window.
11" By default uses a size of 20 lines and 75 columns.
12" Returns the buffer number of the terminal.
13"
14" Options is a dictionary (not used yet).
15func RunVimInTerminal(arguments, options)
16 " Make a horizontal and vertical split, so that we can get exactly the right
17 " size terminal window. Works only when we currently have one window.
18 call assert_equal(1, winnr('$'))
19 split
20 vsplit
21
22 " Always doo this with 256 colors and a light background.
23 set t_Co=256
24 hi Normal ctermfg=0 ctermbg=15
25
26 let cmd = GetVimCommandClean()
Bram Moolenaarb7ea7cb2018-02-24 14:38:51 +010027 " Add -v to have gvim run in the terminal (if possible)
28 let cmd .= ' -v ' . a:arguments
Bram Moolenaarda650582018-02-20 15:51:40 +010029 let buf = term_start(cmd, {'curwin': 1, 'term_rows': 20, 'term_cols': 75})
30 call assert_equal([20, 75], term_getsize(buf))
31
32 return buf
33endfunc
34
35" Stop a Vim running in terminal buffer "buf".
36func StopVimInTerminal(buf)
37 call assert_equal("running", term_getstatus(a:buf))
38 call term_sendkeys(a:buf, ":qa!\<cr>")
39 call WaitFor('term_getstatus(' . a:buf . ') == "finished"')
40 only!
41endfunc
42
43" Verify that Vim running in terminal buffer "buf" matches the screen dump.
44" The file name used is "dumps/{filename}.dump".
45" Will wait for up to a second for the screen dump to match.
46func VerifyScreenDump(buf, filename)
47 let reference = 'dumps/' . a:filename . '.dump'
48 let testfile = a:filename . '.dump.failed'
49
50 let i = 0
51 while 1
52 call delete(testfile)
53 call term_dumpwrite(a:buf, testfile)
54 if readfile(reference) == readfile(testfile)
55 call delete(testfile)
56 break
57 endif
58 if i == 100
59 " Leave the test file around for inspection.
60 call assert_report('See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")')
61 break
62 endif
63 sleep 10m
64 let i += 1
65 endwhile
66endfunc