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) |
Bram Moolenaar | 948a796 | 2018-03-23 20:37:45 +0100 | [diff] [blame] | 29 | " If Vim doesn't exit a swap file remains, causing other tests to fail. |
| 30 | " Remove it here. |
| 31 | call delete(".swp") |
| 32 | |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 33 | " Make a horizontal and vertical split, so that we can get exactly the right |
| 34 | " size terminal window. Works only when we currently have one window. |
| 35 | call assert_equal(1, winnr('$')) |
| 36 | split |
| 37 | vsplit |
| 38 | |
Bram Moolenaar | 6acadda | 2018-02-24 16:51:32 +0100 | [diff] [blame] | 39 | " Always do this with 256 colors and a light background. |
| 40 | set t_Co=256 background=light |
| 41 | hi Normal ctermfg=NONE ctermbg=NONE |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 42 | |
| 43 | let cmd = GetVimCommandClean() |
Bram Moolenaar | b7ea7cb | 2018-02-24 14:38:51 +0100 | [diff] [blame] | 44 | " Add -v to have gvim run in the terminal (if possible) |
| 45 | let cmd .= ' -v ' . a:arguments |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 46 | let buf = term_start(cmd, {'curwin': 1, 'term_rows': 20, 'term_cols': 75}) |
| 47 | call assert_equal([20, 75], term_getsize(buf)) |
| 48 | |
| 49 | return buf |
| 50 | endfunc |
| 51 | |
| 52 | " Stop a Vim running in terminal buffer "buf". |
| 53 | func StopVimInTerminal(buf) |
| 54 | call assert_equal("running", term_getstatus(a:buf)) |
Bram Moolenaar | 2b10bcb | 2018-02-24 21:25:44 +0100 | [diff] [blame] | 55 | call term_sendkeys(a:buf, "\<Esc>\<Esc>:qa!\<cr>") |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 56 | call WaitFor('term_getstatus(' . a:buf . ') == "finished"') |
| 57 | only! |
| 58 | endfunc |
| 59 | |
| 60 | " Verify that Vim running in terminal buffer "buf" matches the screen dump. |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 61 | " "options" is passed to term_dumpwrite(). |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 62 | " The file name used is "dumps/{filename}.dump". |
| 63 | " 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] | 64 | func VerifyScreenDump(buf, filename, options) |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 65 | let reference = 'dumps/' . a:filename . '.dump' |
| 66 | let testfile = a:filename . '.dump.failed' |
| 67 | |
| 68 | let i = 0 |
| 69 | while 1 |
| 70 | call delete(testfile) |
Bram Moolenaar | 6bb2cdf | 2018-02-24 19:53:53 +0100 | [diff] [blame] | 71 | call term_dumpwrite(a:buf, testfile, a:options) |
Bram Moolenaar | da65058 | 2018-02-20 15:51:40 +0100 | [diff] [blame] | 72 | if readfile(reference) == readfile(testfile) |
| 73 | call delete(testfile) |
| 74 | break |
| 75 | endif |
| 76 | if i == 100 |
| 77 | " Leave the test file around for inspection. |
| 78 | call assert_report('See dump file difference: call term_dumpdiff("' . testfile . '", "' . reference . '")') |
| 79 | break |
| 80 | endif |
| 81 | sleep 10m |
| 82 | let i += 1 |
| 83 | endwhile |
| 84 | endfunc |