Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 1 | " Functions shared by tests making screen dumps. |
| 2 | |
| 3 | " Only load this script once. |
| 4 | if exists('*RunVimInTerminal') |
| 5 | finish |
| 6 | endif |
| 7 | |
| 8 | source 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). |
| 15 | func 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 | |
Bram Moolenaar | 6acadda | 2018-02-24 16:51:32 +0100 | [diff] [blame] | 22 | " Always do this with 256 colors and a light background. |
| 23 | set t_Co=256 background=light |
| 24 | hi Normal ctermfg=NONE ctermbg=NONE |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 25 | |
| 26 | let cmd = GetVimCommandClean() |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 27 | " Add -v to have gvim run in the terminal (if possible) |
| 28 | let cmd .= ' -v ' . a:arguments |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 29 | 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 |
| 33 | endfunc |
| 34 | |
| 35 | " Stop a Vim running in terminal buffer "buf". |
| 36 | func 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! |
| 41 | endfunc |
| 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. |
| 46 | func 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 |
| 66 | endfunc |