blob: 5131b935ae8e2e484cb826dd81be75ffc08092b2 [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()
27 let cmd .= ' ' . a:arguments
28 let buf = term_start(cmd, {'curwin': 1, 'term_rows': 20, 'term_cols': 75})
29 call assert_equal([20, 75], term_getsize(buf))
30
31 return buf
32endfunc
33
34" Stop a Vim running in terminal buffer "buf".
35func StopVimInTerminal(buf)
36 call assert_equal("running", term_getstatus(a:buf))
37 call term_sendkeys(a:buf, ":qa!\<cr>")
38 call WaitFor('term_getstatus(' . a:buf . ') == "finished"')
39 only!
40endfunc
41
42" Verify that Vim running in terminal buffer "buf" matches the screen dump.
43" The file name used is "dumps/{filename}.dump".
44" Will wait for up to a second for the screen dump to match.
45func VerifyScreenDump(buf, filename)
46 let reference = 'dumps/' . a:filename . '.dump'
47 let testfile = a:filename . '.dump.failed'
48
49 let i = 0
50 while 1
51 call delete(testfile)
52 call term_dumpwrite(a:buf, testfile)
53 if readfile(reference) == readfile(testfile)
54 call delete(testfile)
55 break
56 endif
57 if i == 100
58 " Leave the test file around for inspection.
59 call assert_report('See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")')
60 break
61 endif
62 sleep 10m
63 let i += 1
64 endwhile
65endfunc