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. |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 4 | if exists('*CanRunVimInTerminal') |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 5 | finish |
| 6 | endif |
| 7 | |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 8 | " 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. |
| 10 | if !has('terminal') || has('win32') |
| 11 | func CanRunVimInTerminal() |
| 12 | return 0 |
| 13 | endfunc |
| 14 | finish |
| 15 | endif |
| 16 | |
| 17 | func CanRunVimInTerminal() |
| 18 | return 1 |
| 19 | endfunc |
| 20 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 21 | source 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). |
| 28 | func 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 Moolenaar | 6acadda | 2018-02-24 16:51:32 +0100 | [diff] [blame] | 35 | " 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 Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 38 | |
| 39 | let cmd = GetVimCommandClean() |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 40 | " Add -v to have gvim run in the terminal (if possible) |
| 41 | let cmd .= ' -v ' . a:arguments |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 42 | 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 |
| 46 | endfunc |
| 47 | |
| 48 | " Stop a Vim running in terminal buffer "buf". |
| 49 | func StopVimInTerminal(buf) |
| 50 | call assert_equal("running", term_getstatus(a:buf)) |
Bram Moolenaar | 2b10bcb | 2018-02-24 21:25:44 +0100 | [diff] [blame] | 51 | call term_sendkeys(a:buf, "\<Esc>\<Esc>:qa!\<cr>") |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 52 | call WaitFor('term_getstatus(' . a:buf . ') == "finished"') |
| 53 | only! |
| 54 | endfunc |
| 55 | |
| 56 | " Verify that Vim running in terminal buffer "buf" matches the screen dump. |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 57 | " "options" is passed to term_dumpwrite(). |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 58 | " The file name used is "dumps/{filename}.dump". |
| 59 | " Will wait for up to a second for the screen dump to match. |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 60 | func VerifyScreenDump(buf, filename, options) |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 61 | 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 Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 67 | call term_dumpwrite(a:buf, testfile, a:options) |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 68 | 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 |
| 80 | endfunc |